Solved by ptrblck in post #2 
              
              
                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.