Solved by ptrblck in post #2 
              
              
                You could reuse the internal implementation of clip_grad_norm_ found here. 
E.g. this should work: 
# setup
x = torch.randn(2, 3, 224, 224)
model = models.resnet18().eval()
out = model(x)
loss = (out**2).mean()
loss.backward()

# create reference
torch.nn.utils.clip_grad_norm_(model.parameters(), ma…