Use backward twice, and apply retain_graph=True for the first backward, but the evaluation result is always the same

Use backward twice, and apply retain_graph=True for the first backward, but the evaluation result is always the same.

Hi,

Could you give more information please about your code and what do these prints correspond to?

Of course. In one epoch, I want to have the two backward of the network, In the first backward, I can get the gradient of every layer which i want to use to update the parameters. And I have the second background with a different cost function.

Could you give a small code sample (30-40 lines) that reproduces what you see? So that I can test it on my machine?