Skip to content

Commit 3002bd3

Browse files
MartinPernuswilliamFalcon
authored andcommitted
log named parameters (#660)
1 parent 91ee071 commit 3002bd3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pytorch_lightning/core/grads.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class GradInformation(nn.Module):
1010
def grad_norm(self, norm_type):
1111
results = {}
1212
total_norm = 0
13-
for i, p in enumerate(self.parameters()):
13+
for name, p in self.named_parameters():
1414
if p.requires_grad:
1515
try:
1616
param_norm = p.grad.data.norm(norm_type)
1717
total_norm += param_norm ** norm_type
1818
norm = param_norm ** (1 / norm_type)
1919

2020
grad = round(norm.data.cpu().numpy().flatten()[0], 3)
21-
results['grad_{}_norm_{}'.format(norm_type, i)] = grad
21+
results['grad_{}_norm_{}'.format(norm_type, name)] = grad
2222
except Exception:
2323
# this param had no grad
2424
pass

0 commit comments

Comments
 (0)