From 3002bd3df5b30497649d40c7d385b9e7fa511b00 Mon Sep 17 00:00:00 2001 From: MartinPernus <36865527+MartinPernus@users.noreply.github.com> Date: Tue, 14 Jan 2020 04:54:06 +0100 Subject: [PATCH] log named parameters (#660) --- pytorch_lightning/core/grads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytorch_lightning/core/grads.py b/pytorch_lightning/core/grads.py index 7bdc8572b9..d98a6efeb8 100644 --- a/pytorch_lightning/core/grads.py +++ b/pytorch_lightning/core/grads.py @@ -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