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

Using print_nan_grads in the Trainer results in an error #566

Closed
iamsimha opened this issue Dec 2, 2019 · 2 comments · Fixed by #579
Closed

Using print_nan_grads in the Trainer results in an error #566

iamsimha opened this issue Dec 2, 2019 · 2 comments · Fixed by #579
Labels
bug Something isn't working

Comments

@iamsimha
Copy link

iamsimha commented Dec 2, 2019

Describe the bug
When using

print_nan_grads=True

in the Trainer, I am getting the error below.

trainer.fit(lstm_model)
File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 364, in fit
self.run_pretrain_routine(model)
File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 471, in run_pretrain_routine
self.train()
File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py", line 60, in train
self.run_training_epoch()
File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py", line 99, in run_training_epoch
output = self.run_training_batch(batch, batch_nb)
File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py", line 219, in run_training_batch
self.print_nan_gradients()
File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/training_tricks_mixin.py", line 16, in print_nan_gradients
if torch.isnan(param.grad.float()).any():
AttributeError: 'NoneType' object has no attribute 'float'

To Reproduce
Steps to reproduce the behavior:
If some param object, does not have .grad, then that object should not be checked for nans

@iamsimha iamsimha added the bug Something isn't working label Dec 2, 2019
@awaelchli
Copy link
Contributor

sounds like an easy fix: iterate only over params where grad is not None. Would that solve the issue?

@williamFalcon
Copy link
Contributor

exactly. Anyone want to submit the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants