In-depth explanation of Pytorch function - torch.Tensor.detach

Category: General catalog of "Pytorch functions in simple terms"
Related articles:
· Pytorch functions in simple terms——torch.Tensor


Returns a new tensor that is separate from the current graph, the result of which will never require gradients. This method also affects forward mode AD gradients, and the result will never have forward mode AD gradients. The returned Tensor shares the same storage space as the original Tensor and may trigger bugs in correctness checking. Previously, changes to the returned tensor's shape, stride, storage, etc. (eg resize_, resize_as_/, set_, transpose_etc.) would also update the original tensor. Now, these in-place changes will no longer update the original tensor, but instead will trigger an error. For sparse tensors, changes to the returned tensor (e.g. zero_, copy_, add_) will no longer update the original tensor, but instead will trigger an error.

grammar

torch.Tensor.detach()

return value

torch.Tensor

Guess you like

Origin blog.csdn.net/hy592070616/article/details/131969122