Skip to content

Commit

Permalink
move device-specific teardown logic from training loop to accelerator (
Browse files Browse the repository at this point in the history
…#5973)

* on train end

* switch order
  • Loading branch information
awaelchli authored Feb 15, 2021
1 parent ae4dca9 commit aa60c08
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
1 change: 1 addition & 0 deletions pytorch_lightning/accelerators/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def on_train_start(self):

def on_train_end(self):
# clean up memory
self.model.cpu()
with torch.cuda.device(self.root_device):
torch.cuda.empty_cache()

Expand Down
8 changes: 1 addition & 7 deletions pytorch_lightning/trainer/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,7 @@ def on_train_end(self):
self.trainer.profiler.describe()

# give accelerators a chance to finish
self.trainer.accelerator_backend.on_train_end()

# clear mem
if self.trainer._device_type == DeviceType.GPU:
model = self.trainer.get_model()
model.cpu()
torch.cuda.empty_cache()
self.trainer.accelerator.on_train_end()

def check_checkpoint_callback(self, should_update, is_last=False):
# TODO bake this logic into the ModelCheckpoint callback
Expand Down

0 comments on commit aa60c08

Please sign in to comment.