torch.Tensor.retain_grad
-
Tensor.retain_grad() → None -
Enables this Tensor to have their
gradpopulated duringbackward(). This is a no-op for leaf tensors.
Tensor.retain_grad() → None Enables this Tensor to have their grad populated during backward(). This is a no-op for leaf tensors.
© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.Tensor.retain_grad.html