Skip to content

Commit

Permalink
log named parameters (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPernus authored and williamFalcon committed Jan 14, 2020
1 parent 91ee071 commit 3002bd3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pytorch_lightning/core/grads.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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)
total_norm += param_norm ** norm_type
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
Expand Down

0 comments on commit 3002bd3

Please sign in to comment.