Skip to content
Merged
Changes from 2 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: 2 additions & 14 deletions torchtitan/experiments/simple_fsdp/simple_fsdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Replicate,
Shard,
)
from torch.distributed.device_mesh import _mesh_resources, DeviceMesh
from torch.distributed.device_mesh import DeviceMesh
from torch.distributed.tensor._dtensor_spec import DTensorSpec
from torch.distributed.tensor._redistribute import redistribute_local_tensor
from torch.distributed.tensor.placement_types import _StridedShard, Placement
Expand Down Expand Up @@ -95,19 +95,7 @@ def _distribute_dtensor(
"""
inner_spec = tensor._spec
outer_mesh, inner_mesh = device_mesh, inner_spec.mesh
outer_global_mesh = _mesh_resources.get_root_mesh(outer_mesh)
inner_global_mesh = _mesh_resources.get_root_mesh(inner_mesh)
if outer_global_mesh != inner_global_mesh or (
outer_global_mesh is None or inner_global_mesh is None
):
raise AssertionError(
"Cannot distribute tensor across two meshes without the same root mesh: \n"
f"outer global mesh: {outer_global_mesh}\ninner global mesh: {inner_global_mesh}"
)
assert outer_mesh.mesh_dim_names is not None
assert inner_mesh.mesh_dim_names is not None
submesh_names = outer_mesh.mesh_dim_names + inner_mesh.mesh_dim_names
spanned_mesh = outer_global_mesh[submesh_names]
spanned_mesh = DeviceMesh._concatenate((outer_mesh, inner_mesh))
Copy link

Choose a reason for hiding this comment

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

Nice!

One nit: isn't the argument supposed to be a list, and not a tuple?

If so, how come there is no type checking or other linting to catch this?

Note that we've already observed TorchTitan being somewhat incorrect with types, e.g., it passes lists to init_device_mesh instead of tuples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I believe we have not enabled type checking for TorchTitan, which we should.


if len(dp_placements) == 1:
assert dp_placements[0].is_replicate() or dp_placements[0].is_shard()
Expand Down
Loading