Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple fix for memory leak on GPU0 #1094

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pytorch_lightning/trainer/evaluation_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,16 @@ def evaluation_forward(self, model, batch, batch_idx, dataloader_idx, test_mode:

# single GPU data transfer
if self.single_gpu:
# for single GPU put inputs on gpu manually
root_gpu = 0

if isinstance(self.data_parallel_device_ids, list):
root_gpu = self.data_parallel_device_ids[0]
root_device = (torch.device("cuda", root_gpu)
if root_gpu else torch.device("cpu"))
torch.cuda.set_device(root_device)
Copy link
Contributor

Choose a reason for hiding this comment

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

also need to add tpu device...

else:
raise RuntimeError(
'Expected `data_parallel_device_ids` as a list, cannot determine root gpu.'
)
batch = self.transfer_batch_to_gpu(batch, root_gpu)
args[0] = batch

Expand Down
3 changes: 3 additions & 0 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ def __init__(
self.gpus = gpus
self.data_parallel_device_ids = parse_gpu_ids(self.gpus)
self.root_gpu = determine_root_gpu_device(self.data_parallel_device_ids)
root_device = (torch.device("cuda", self.root_gpu)
if self.root_gpu else torch.device("cpu"))
torch.cuda.set_device(root_device)

# tpu state flags
self.use_tpu = False
Expand Down