Solved by ptrblck in post #6 
              
              
                You have to assign the detached tensor: 
target = target.detach()

or alternatively just detach it in the criterion: 
loss = criterion(output, target.detach())