Skip to content
Merged
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this for TPU too ?

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleaning !

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