Skip to content

Commit

Permalink
fix init_device_mesh for torch 2.4 (deepspeedai#6614)
Browse files Browse the repository at this point in the history
Start torch 2.4, in
[`init_device_mesh()`](https://github.com/pytorch/pytorch/blob/de4c2a3b4e89d96334dc678d1c3f2ae51a6630a0/torch/distributed/device_mesh.py#L915)
,device type with a GPU index, such as "cuda:0", is not allowed.


![image](https://github.com/user-attachments/assets/1ddb61bf-8a15-4e0a-9115-a3681d7f19ff)

---------

Co-authored-by: Olatunji Ruwase <[email protected]>
Co-authored-by: Logan Adams <[email protected]>
Co-authored-by: Masahiro Tanaka <[email protected]>
Co-authored-by: Masahiro Tanaka <[email protected]>
  • Loading branch information
5 people authored Oct 23, 2024
1 parent e06bb51 commit 6e6563d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions deepspeed/comm/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,14 @@ def init_device_mesh(self, mesh_shape, mesh_dim_names):
if not required_torch_version(min_version=2.2):
raise RuntimeError(f"Current torch version does not have device mesh"
f"api (torch.__version__: {torch.__version__})")
return torch.distributed.device_mesh.init_device_mesh(get_accelerator().current_device_name(),
mesh_shape,
mesh_dim_names=mesh_dim_names)
if not required_torch_version(max_version=2.4):
return torch.distributed.device_mesh.init_device_mesh(get_accelerator().device_name(),
mesh_shape,
mesh_dim_names=mesh_dim_names)
else:
return torch.distributed.device_mesh.init_device_mesh(get_accelerator().current_device_name(),
mesh_shape,
mesh_dim_names=mesh_dim_names)


# This will become a light-weight wrapper around torch.distributed functions
Expand Down

0 comments on commit 6e6563d

Please sign in to comment.