Repository navigation
Use new DeviceMesh unflatten to rewrite parallel_dims - #1660
Conversation
12eca61 to
19e4a23
Compare
19e4a23 to
178bc11
Compare
left a comment
•
There was a problem hiding this comment.
We should modify FLUX train.py as it's in core now.
@ruisizhang123 let's adapt SimpleFSDP after this PR is merged.
oh it seems being fixed in #1959
20910ef to
a67e87a
Compare
aba17ea to
f3a0c0c
Compare
| # sequences would require https://github.com/pytorch/torchtitan/pull/686 | ||
| # pyrefly: ignore [bad-argument-type] | ||
| apply_tp_minus_sp(model, parallel_dims.world_mesh["tp"]) | ||
| apply_tp_minus_sp(model, parallel_dims.get_mesh("tp")) |
There was a problem hiding this comment.
After converging to full dtensor TP plan, we no longer need this minus_sp plan. cc @wwwjn
| k: v for k, v in self._meshes.items() if v.ndim == 1 and v.size() > 1 | ||
| } | ||
| else: | ||
| return {k: v for k, v in self._meshes.items() if v.size() > 1} |
There was a problem hiding this comment.
Nice catch, it's a legacy from some version. I forgot to delete it . Since it is not used anymore I delete the branch and rename the API to match the logic.
| if dp_cp_mesh_dim_names != []: | ||
| mesh[tuple(dp_cp_mesh_dim_names)]._flatten(mesh_dim_name="dp_cp") | ||
|
|
||
| def get_optional_mesh(self, dims: str | list[str]) -> DeviceMesh | None: |
There was a problem hiding this comment.
what's the consideration of separating the two? can we have an arg like check_exists?
There was a problem hiding this comment.
Mostly typing. If we don't separate the two, more than 70+ use cases need extra check to ensure typing system doesn't complain None doesn't have some fields. The benefit is that a user will be forced to understand which API should be used, optional or not, and the typing system will give the user an error if the usage is not correct. This can reduce chance of error usages.
So I want to keep this optional case unless there are other concerns.
| dist_utils.dist_mean(loss, parallel_dims.world_mesh["dp_cp"]), | ||
| dist_utils.dist_max(loss, parallel_dims.world_mesh["dp_cp"]), | ||
| dist_utils.dist_mean(loss, parallel_dims.get_optional_mesh("loss")), | ||
| dist_utils.dist_max(loss, parallel_dims.get_optional_mesh("loss")), |
There was a problem hiding this comment.
why the loss mesh is optional, because it could be of size 1 and we'd want to return None?
| return funcol.all_reduce(x, reduceOp=reduceOp, group=mesh).item() | ||
|
|
||
|
|
||
| def dist_max( |
There was a problem hiding this comment.
if reduction may not happen, then probably need to rename to maybe_dist_max
There was a problem hiding this comment.
We should do this in a separate PR, this PR already encapsulate too much logic. This is a pre-exist design.
| @@ -206,7 +206,7 @@ def monkey_patch_checks(moe): | |||
| assert not list(moe.reorderer.buffers()) | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
I can feel how much work it is to work on this PR, lol
f3a0c0c to
3e3c9e5
Compare
commented
Dec 17, 2025
|
Please raise an issue and tag me if you see a DevicMesh issue. I'm going to merge this PR. |
Summary
This PR utilizes the latest APIs provided by DeviceMesh to simplify the creation of all different meshes.
The design philosophy is as follow: