I don’t see the string: “Traceback of forward call that caused the error” in the error you provided, which could mean that anomaly mode is not properly enabled.
Make sure anomaly mode is enabled when you are running the forward pass as well.
Anomaly mode works because the backtrace of the call leading to the backward node’s creation is saved to the node’s metadata during the forward pass. That way when an error is encountered while applying that node, it can simply access what was stored in its metadata do identify the forward op responsible.
You can see an example of the message here:
https://pytorch.org/docs/stable/autograd.html#anomaly-detection 51