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

I had similar problem, but it was solved as I mentioned here: