I’m not familiar with your use case and cannot comment if the used methods are right or not.
However, if you are concerned about the correctness of the gradient calculation, you could check the .grad attribute of all parameters after the backward call.
Before the first backward they should be set to None, afterwards they should contain a valid value.
If all param.grad attributes are filled, then the computation graph is not detached and the gradients are calculated.