Solved by albanD in post #2 
              
              
                Hi, 
Since gradients are needed for y itself, your can’t modify it inplace. 
What you can do is clone it before, that way the cloned version will not be a leaf Variable and can thus be changed inplace: 
import torch
from torch.autograd import Variable

x = torch.LongTensor([0,1,0,1,1,0])
y = Variabl…