Gradients do not update when I replace the loss value in this code

The problem is solved. Thanks to this post and discussion between @ljj7975 & @ptrblck for hinting me towards checking if the computation graph was broken somewhere. It was exactly that. The computation graph was broken while calling loss.backward().

2 Likes