Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make print_nan_grads print grad #208

Merged
merged 1 commit into from
Sep 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,10 +1091,10 @@ def __clip_gradients(self):
torch.nn.utils.clip_grad_norm_(model.parameters(), self.gradient_clip)

def __print_nan_grads(self):
if self.print_nan_grads:
model = self.__get_model()
for param in model.parameters():
print(param.grad.float().sum())
model = self.__get_model()
for param in model.parameters():
if torch.isnan(param.grad.float()).any():
print(param, param.grad)

def __run_tng_batch(self, data_batch, batch_nb):
if data_batch is None:
Expand Down Expand Up @@ -1137,7 +1137,8 @@ def __run_tng_batch(self, data_batch, batch_nb):
model_ref.on_after_backward()

# nan grads
self.__print_nan_grads()
if self.print_nan_grads:
self.__print_nan_grads()

# track total loss for logging (avoid mem leaks)
self.batch_loss_value += loss.item()
Expand Down