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

Allow multiple process per device #2916

Merged
merged 3 commits into from
Jul 15, 2024
Merged
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
16 changes: 4 additions & 12 deletions src/accelerate/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,18 +789,10 @@ def set_device(self):
else:
if device == "gpu":
device = "cuda"
self.device = torch.device(device, self.local_process_index)
if self.device is not None:
if device == "xpu":
torch.xpu.set_device(self.device)
elif device == "mlu":
torch.mlu.set_device(self.device)
elif device == "musa":
torch.musa.set_device(self.device)
elif device == "npu":
torch.npu.set_device(self.device)
elif device == "cuda":
torch.cuda.set_device(self.device)
device_module = getattr(torch, device)
device_index = self.local_process_index % device_module.device_count()
self.device = torch.device(device, device_index)
device_module.set_device(self.device)

def __getattr__(self, name: str):
# By this point we know that no attributes of `self` contain `name`,
Expand Down
Loading