Solved by vabh in post #2 
              
              
                I think this operation is breaking your computation graph. 
The order of operations should be: 
loss = loss_function(output,y)
loss.backward()
optimizer.step()