You should upgrade your pytorch version as no Variables are needed anymore.
If your labels is a single python number, you can simply wrap it in a long (or whatever type you criterion expects) tensor as torch.LongTensor([correct_class]).
Thanks a lot. I got another error RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.
Iam actually manually upgrading the weights by getting inputs from user. I read your answer to provide retain_graph=True. Still it does not work. Here is my code.