With the anomaly flag off it is giving still the same error of inplaced operations:

The error you linked is not the same actually !
Try adding a retain_graph=True to see if it is better.

Then I turned the anomaly flag on torch.autograd.set_detect_anomaly(True) and it gave a different error:

This can happen for few reasons but most likely here because you multiply something infinite with 0. Do you get infinite values in the forward for the mul that is pointed to by anomaly mode?