When I run this with detect anomaly on, I get the same error stack trace. I dont have a NaN value problem. My tensors and loss are showing as follows:

43%20PM832×430 58.5 KB

We can run the forward function independently entirely and there are no problems as is shown from the output of the debug screen capture above.