log named parameters (#660)
This commit is contained in:
parent
91ee0711f0
commit
3002bd3df5
|
@ -10,7 +10,7 @@ class GradInformation(nn.Module):
|
|||
def grad_norm(self, norm_type):
|
||||
results = {}
|
||||
total_norm = 0
|
||||
for i, p in enumerate(self.parameters()):
|
||||
for name, p in self.named_parameters():
|
||||
if p.requires_grad:
|
||||
try:
|
||||
param_norm = p.grad.data.norm(norm_type)
|
||||
|
@ -18,7 +18,7 @@ class GradInformation(nn.Module):
|
|||
norm = param_norm ** (1 / norm_type)
|
||||
|
||||
grad = round(norm.data.cpu().numpy().flatten()[0], 3)
|
||||
results['grad_{}_norm_{}'.format(norm_type, i)] = grad
|
||||
results['grad_{}_norm_{}'.format(norm_type, name)] = grad
|
||||
except Exception:
|
||||
# this param had no grad
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue