MCPcopy
hub / github.com/NVlabs/imaginaire / gradient_norm

Function gradient_norm

imaginaire/utils/misc.py:201–213  ·  view source on GitHub ↗

r"""Return the gradient norm of model. Args: model (PyTorch module): Your network.

(model)

Source from the content-addressed store, hash-verified

199
200
201def gradient_norm(model):
202 r"""Return the gradient norm of model.
203
204 Args:
205 model (PyTorch module): Your network.
206
207 """
208 total_norm = 0
209 for p in model.parameters():
210 if p.grad is not None:
211 param_norm = p.grad.norm(2)
212 total_norm += param_norm.item() ** 2
213 return total_norm ** (1. / 2)
214
215
216def random_shift(x, offset=0.05, mode='bilinear', padding_mode='reflection'):

Callers

nothing calls this directly

Calls 1

normMethod · 0.80

Tested by

no test coverage detected