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

setting PGU device #1128

Closed
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
4 changes: 4 additions & 0 deletions pytorch_lightning/trainer/distrib_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,8 @@ def determine_root_gpu_device(gpus):
# set root gpu
root_gpu = gpus[0]

# set cuda device to root gpu
root_device = (torch.device("cuda", root_gpu) if root_gpu >= 0 else torch.device("cpu"))
torch.cuda.set_device(root_device)

return root_gpu
Copy link
Member

Choose a reason for hiding this comment

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

To me it looks like this should not go here, because the method is called "determine_root_gpu_device", and the added code also checks if the device is cpu. This code should probably go to the place where we call determine_root_gpu_device.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where do you suggest to place this?

11 changes: 10 additions & 1 deletion pytorch_lightning/trainer/evaluation_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,18 @@ 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]

# set cuda device to root gpu
root_device = (torch.device("cuda", root_gpu)
if root_gpu >= 0 else torch.device("cpu"))
torch.cuda.set_device(root_device)
else:
raise RuntimeError(
'Expected `data_parallel_device_ids` as a list, cannot determine root gpu.'
Copy link
Member

Choose a reason for hiding this comment

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

Above we have if self.single_gpu, so why should device ids be a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was already an if clause:if isinstance(self.data_parallel_device_ids, list) , I raised the runtime error as a safenet because root_gpu = 0 was used earlier by default.

)
batch = self.transfer_batch_to_gpu(batch, root_gpu)
args[0] = batch

Expand Down