autograd.detect_anomaly 5 is a utility to help you debug runs in the autograd engine.
If you run the code with the decorator, you should get an error message, which you could post here so that we could have a look.