From f744285da8b1c606b6d62d91fc02ec09e3a3810f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Sat, 13 Jun 2020 23:25:46 +0200 Subject: [PATCH] simplify teardown with finally block --- pytorch_lightning/trainer/training_loop.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pytorch_lightning/trainer/training_loop.py b/pytorch_lightning/trainer/training_loop.py index 329703607f2e7..d673ab417510b 100644 --- a/pytorch_lightning/trainer/training_loop.py +++ b/pytorch_lightning/trainer/training_loop.py @@ -359,7 +359,6 @@ def train(self): self.run_training_epoch() if self.max_steps and self.max_steps == self.global_step: - self.run_training_teardown() return # update LR schedulers @@ -380,11 +379,8 @@ def train(self): # stop training stop = should_stop and met_min_epochs if stop: - self.run_training_teardown() return - self.run_training_teardown() - except KeyboardInterrupt: rank_zero_warn('Detected KeyboardInterrupt, attempting graceful shutdown...') @@ -394,8 +390,8 @@ def train(self): for proc in self.interactive_ddp_procs: subprocess.Popen.kill(proc) - - self.run_training_teardown() + finally: + self.run_training_teardown() def run_training_epoch(self):