Hi,
One way to pinpoint such errors is to enable anomaly detection 1 to know which operation in the forward caused the error in the backward.
You don’t seem to be using a lot of inplace operations. Maybe replace the loss += by loss = loss +`?