Getting the autograd counter of a tensor in PyTorch
I am using PyTorch for training a network. I was going through the autograd documentation and here it is mentioned that for each tensor there is a counter that the autograd implements to track the &quot;version&quot; of any tensor. How can I get this counter for any tensor in the graph?
Reason why I need it.
I have encountered the autograd error

[torch.cuda.FloatTensor [x, y, z]], which is output 0 of torch::autograd::CopySlices, is at version 7; expected version 6 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

This is not new to me and I have been successful in handling it before. This time around I am not able to see why the tensor would be at version 7 instead of being at 6. To answer this, I would want to know the version at any given point in the run.
Thanks.

It can be obtained through the command tensor_name._version.
As an example of how to use it, following MSE is provided.
import torch

a = torch.zeros(10, 5)
print(a._version)  # prints 0
a[:, 1] = 1
print(a._version)  # prints 1  

