Exactely: .item() gives you a python number that means that you don’t have Tensors anymore (and so no autograd anymore).
Also given you error message, you seem to be using .data. You should not use it and using with torch.no_grad() instead as in my example.