MCPcopy Index your code
hub / github.com/OpenGVLab/InternVL / get_grad_norm

Function get_grad_norm

classification/utils.py:316–326  ·  view source on GitHub ↗
(parameters, norm_type=2)

Source from the content-addressed store, hash-verified

314
315
316def get_grad_norm(parameters, norm_type=2):
317 if isinstance(parameters, torch.Tensor):
318 parameters = [parameters]
319 parameters = list(filter(lambda p: p.grad is not None, parameters))
320 norm_type = float(norm_type)
321 total_norm = 0
322 for p in parameters:
323 param_norm = p.grad.data.norm(norm_type)
324 total_norm += param_norm.item() ** norm_type
325 total_norm = total_norm ** (1. / norm_type)
326 return total_norm
327
328
329def auto_resume_helper(output_dir):

Callers 2

train_one_epochFunction · 0.90
__call__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected