log named parameters (#660)

This commit is contained in:
MartinPernus 2020-01-14 04:54:06 +01:00 committed by William Falcon
parent 91ee0711f0
commit 3002bd3df5
1 changed files with 2 additions and 2 deletions

View File

@ -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