thanks @god_sp33d , it’s working now 
Although I understood the problem a bit, could you please explain in detail what was happening.
Because earlier also when I was printing the loss value, it was working the same way as of now. But now I’m not getting out of memory error