Skip to content

Commit

Permalink
[bugfix] remove nan loss in manual optimization (#5121)
Browse files Browse the repository at this point in the history
* remove nan loss whe missing

* Update pytorch_lightning/core/lightning.py

Co-authored-by: Carlos Mocholí <[email protected]>

* Apply suggestions from code review

Co-authored-by: Carlos Mocholí <[email protected]>
Co-authored-by: Rohit Gupta <[email protected]>
  • Loading branch information
3 people authored and Borda committed Dec 23, 2020
1 parent d975900 commit 824fad8
Showing 1 changed file with 9 additions and 6 deletions.
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)}
avg_training_loss = None
if running_train_loss is not None:
avg_training_loss = running_train_loss.cpu().item()
elif self.trainer.train_loop.automatic_optimization:
avg_training_loss = float('NaN')

tqdm_dict = {}
if avg_training_loss is not None:
tqdm_dict["loss"] = f"{avg_training_loss:.3g}"

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

0 comments on commit 824fad8

Please sign in to comment.