Solved by ptrblck in post #2 
              
              
                Your train_loss seems to be a plain float (i.e. not a tensor) so make sure you are calling backward on the actual loss tensor not the Python float scalar.