Hi,
The detect_anomaly should be fairly reliable.
Could you add this to your code:
logits = net(img, gt=labels)

def hook_fn(grad):
    print("logits grad")
    print(grad)
logits.register_hook(hook_fn)

loss = F.cross_entropy(input=logits, target=labels)


Does the gradients for logits look good?
If so, can you add the same check to your code line 145 and change it from return self.fc(self.net(x), gt) to
resnet_output = self.net(x)

def hook_fn(grad):
    print("resnet output grad")
    print(grad)
resnet_output.register_hook(hook_fn)

return self.fc(resnet_output, gt)