Try to add .clone() operations to tensors to isolate the offending line of code.
I cannot find anything suspicious by skimming through your code.
PS: Variables are deprecated since PyTorch 0.4, so you can use tensors now