8000 Fix multiprocessing with CUDA_VISIBLE_DEVICES seems to give the wrong device by fzyzcjy · Pull Request #149248 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Fix multiprocessing with CUDA_VISIBLE_DEVICES seems to give the wrong device #149248

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8000
Diff view
Diff view
14 changes: 13 additions & 1 deletion torch/multiprocessing/reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def rebuild_cuda_tensor(
event_handle,
event_sync_required,
):
storage_device = _device_from_uuid(storage_device)
# If storage_handle is None, storage points to nullptr.
if storage_handle is None or storage_size_bytes == 0:
storage = storage_cls(0, dtype=dtype, device=storage_device, _internal=True)
Expand Down Expand Up @@ -365,7 +366,7 @@ def reduce_tensor(tensor):
tensor_offset, # tensor offset in its storage
type(storage),
tensor.dtype,
device,
_device_to_uuid(device),
handle, # identifier which CUDA allocation is the storage in.
storage_size_bytes, # size(in bytes) of the storage
storage_offset_bytes, # offset(in bytes) of the storage in the CUDA allocation
Expand Down Expand Up @@ -645,3 +646,14 @@ def init_reductions():
from torch.nn.parameter import Parameter

reduction.register(Parameter, reduce_tensor)


def _device_to_uuid(device):
return str(torch.cuda.get_device_properties(device).uuid)


def _device_from_uuid(device_uuid):
for device in range(torch.cuda.device_count()):
if str(torch.cuda.get_device_properties(device).uuid) == device_uuid:
return device
raise Exception("Invalid device_uuid=" + device_uuid)
Loading
0