Any reason to use .data on Tensor when converting?

I have seen code that has like this:


where data_predict is a List, and train_predict is a Tensor. My understanding is that .data is used to extract the Tensor from a Variable, and that if the object is already a Tensor, there is no purpose for it in this manner. Is that correct? Or is there some reason/difference in having .data as above vs omitting it.


Variables are deprecated since PyTorch 0.4 and you can use tensors now. Also, you should not access the .data attribute directly, as it might yield unwanted side effects.
So you are correct and should remove the .data usage. :wink: