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

[bugfix] remove nan loss in manual optimization #5121

Merged
merged 7 commits into from
Dec 16, 2020
15 changes: 9 additions & 6 deletions pytorch_lightning/core/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,12 +1392,15 @@ def get_progress_bar_dict(self):
"""
# call .item() only once but store elements without graphs
running_train_loss = self.trainer.train_loop.running_loss.mean()
avg_training_loss = (
running_train_loss.cpu().item()
if running_train_loss is not None
else float("NaN")
)
tqdm_dict = {"loss": "{:.3g}".format(avg_training_loss)}
if self.trainer.train_loop.automatic_optimization:
avg_training_loss = (
running_train_loss.cpu().item()
if running_train_loss is not None
else float("NaN")
)
tqdm_dict = {"loss": "{:.3g}".format(avg_training_loss)}
else:
tqdm_dict = {}
tchaton marked this conversation as resolved.
Show resolved Hide resolved

if self.trainer.truncated_bptt_steps is not None:
tqdm_dict["split_idx"] = self.trainer.split_idx
Expand Down