MCPcopy Create free account
hub / github.com/SwinTransformer/Transformer-SSL / get_grad_norm

Function get_grad_norm

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

Source from the content-addressed store, hash-verified

79
80
81def get_grad_norm(parameters, norm_type=2):
82 if isinstance(parameters, torch.Tensor):
83 parameters = [parameters]
84 parameters = list(filter(lambda p: p.grad is not None, parameters))
85 norm_type = float(norm_type)
86 total_norm = 0
87 for p in parameters:
88 param_norm = p.grad.data.norm(norm_type)
89 total_norm += param_norm.item() ** norm_type
90 total_norm = total_norm ** (1. / norm_type)
91 return total_norm
92
93
94def auto_resume_helper(output_dir):

Callers 3

train_one_epochFunction · 0.90
train_one_epochFunction · 0.90
train_one_epochFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected