set_detect_anomaly won’t change the behavior of your code, just the error reporting. If you are not using it, the invalid values would also be created, but you would just “use” them, i.e. you might update your model parameters to NaNs etc.