From 81720d9ee586c78d315779f093ee60499ac1d579 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Fri, 19 Jun 2020 00:49:40 -0400 Subject: [PATCH] fallback to hparams str (#2259) --- pytorch_lightning/core/lightning.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index d2190a37f5..273313c782 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -1702,11 +1702,14 @@ class LightningModule(ABC, DeviceDtypeModuleMixin, GradInformation, ModelIO, Mod looks at the code of the class to figure out what the user named self.hparams this only happens when the user explicitly sets self.hparams """ - class_code = inspect.getsource(self.__class__) - lines = class_code.split('\n') - for line in lines: - line = re.sub(r"\s+", "", line, flags=re.UNICODE) - if 'self.hparams=' in line: - return line.split('=')[1] + try: + class_code = inspect.getsource(self.__class__) + lines = class_code.split('\n') + for line in lines: + line = re.sub(r"\s+", "", line, flags=re.UNICODE) + if 'self.hparams=' in line: + return line.split('=')[1] + except Exception as e: + return 'hparams' return None