MCPcopy Create free account
hub / github.com/LeapLabTHU/DAT / get_grad_norm

Function get_grad_norm

utils.py:65–75  ·  view source on GitHub ↗
(parameters, norm_type=2)

Source from the content-addressed store, hash-verified

63
64
65def get_grad_norm(parameters, norm_type=2):
66 if isinstance(parameters, torch.Tensor):
67 parameters = [parameters]
68 parameters = list(filter(lambda p: p.grad is not None, parameters))
69 norm_type = float(norm_type)
70 total_norm = 0
71 for p in parameters:
72 param_norm = p.grad.data.norm(norm_type)
73 total_norm += param_norm.item() ** norm_type
74 total_norm = total_norm ** (1. / norm_type)
75 return total_norm
76
77
78def auto_resume_helper(output_dir):

Callers 2

train_one_epochFunction · 0.90
train_one_epochFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected