Kothari_Gaurav:

loss = Variable(loss,requires_grad=True)


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