Solved by jpeg729 in post #4 
              
              
                You should recalculate Q for each forward pass. Otherwise the computation graph for Q gets freed when you run loss.backward() and the second run can’t backpropagate all the way back to T. 
class Net(nn.Module):
  def __init__(self):
    super(Net, self).__init__()
    self.T = nn.Parameter(torch.Ten…