I don’t know much about it but,
retain_graph (bool ,* optional ) – If False , the graph used to compute the grads will be freed.
If you want to backward grad through the model multiple times, you should set retain_graph=True . Something like —> Loss.backward(retain_graph=True), and then you should manually free the graph.(I don’t know how)