torch.Tensor.Tensor.retain_grad
Tensor.retain_grad(): voidEnables this Tensor to have its grad populated during backward(). This is a no-op for leaf tensors.
For non-leaf tensors, gradients are normally not retained and are freed during backward. Call retain_grad() to keep them.