From d40425d2574c5698eed350e340d9ece779a68ac2 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Thu, 30 Apr 2020 08:04:18 -0400 Subject: [PATCH] added warning to crash (#1625) * added warning to crash * formatting Co-authored-by: J. Borovec --- pytorch_lightning/core/lightning.py | 6 +++--- pytorch_lightning/trainer/training_io.py | 8 ++++++-- setup.cfg | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index 26016613..fc88fb8c 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -1162,9 +1162,9 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks): # native amp + lbfgs is a no go right now if self.trainer.use_amp and self.trainer.use_native_amp: - m = 'native PyTorch amp and lbfgs are not compatible. To request, please file' \ - 'a Github issue in PyTorch and tag @mcarilli' - raise MisconfigurationException(m) + raise MisconfigurationException( + 'native PyTorch amp and lbfgs are not compatible.' + ' To request, please file a Github issue in PyTorch and tag @mcarilli') optimizer.step(second_order_closure) else: if self.trainer.use_amp and self.trainer.use_native_amp: diff --git a/pytorch_lightning/trainer/training_io.py b/pytorch_lightning/trainer/training_io.py index e4932953..78d24fad 100644 --- a/pytorch_lightning/trainer/training_io.py +++ b/pytorch_lightning/trainer/training_io.py @@ -251,9 +251,11 @@ class TrainerIOMixin(ABC): # do the actual save try: self._atomic_save(checkpoint, filepath) - except AttributeError: + except AttributeError as e: if 'hparams' in checkpoint: del checkpoint['hparams'] + rank_zero_warn('warning, `hparams` dropped from checkpoint.' + f' An attribute is not picklable {e}') self._atomic_save(checkpoint, filepath) @@ -434,9 +436,11 @@ class TrainerIOMixin(ABC): # TODO: fix for anything with multiprocess DP, DDP, DDP2 try: self._atomic_save(checkpoint, filepath) - except AttributeError: + except AttributeError as e: if 'hparams' in checkpoint: del checkpoint['hparams'] + rank_zero_warn('warning, `hparams` dropped from checkpoint.' + f' An attribute is not picklable {e}') self._atomic_save(checkpoint, filepath) diff --git a/setup.cfg b/setup.cfg index 2f1b55c1..aab7a580 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,6 +18,7 @@ exclude_lines = pragma: no-cover warnings pass + rank_zero_warn [flake8] # TODO: this should be 88 or 100 according PEP8