MCPcopy Create free account
hub / github.com/CompVis/diff2flow / get_grad_norm

Function get_grad_norm

diff2flow/trainer_module.py:726–733  ·  view source on GitHub ↗
(model)

Source from the content-addressed store, hash-verified

724
725
726def get_grad_norm(model):
727 total_norm = 0
728 parameters = [p for p in model.parameters() if p.grad is not None and p.requires_grad]
729 for p in parameters:
730 param_norm = p.grad.detach().data.norm(2)
731 total_norm += param_norm.item() ** 2
732 total_norm = total_norm ** 0.5
733 return total_norm

Callers 1

training_stepMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected