Alan_Wang:

For my problem, it seems that the error is when calculating the diff. Why is a subtraction operator giving an nan?


inf - inf would give nan IIRC.

It seems that setting set_detect_anomaly on prevents any nan detection (all the outputs are False). Is this expected?

No but maybe your code is “flaky” and depending on the run, the nan don’t appear at the same place?