Hi,
The problem comes from the fact that the backward for output_2 tries to propagate all the way to model_1. But the parameters for model_1 were modified when you did opt_1.step() hence the error that you see.
If you just don’t want this backward to go all the way to model_1, you can do output_2 = model_2(output_1.detach()) to break the graph.