This error is because you modify some things inplace that should not be modifie inplace. This has nothing to do with the anomaly mode.
You can fix this by changing data[data != data] = 0 to data = data.clone(); data[data != data] = 0 so that you don’t modify the original data inplace.
The anomaly mode tells you about the nan. If you remove this and you have the nan error again, you should have an additional stack trace that tells you about the forward function (make sure to enable the anomaly mode before the you run the forward).