Repository navigation
[Bugfix] Force all reduce in bwd for router at MoE boundary - #2416
Conversation
| # so the router gate receives the correct full gradient. | ||
| top_scores = DTensor.from_local( | ||
| top_scores, device_mesh, (Replicate(),) | ||
| ).to_local(grad_placements=(Partial(),)) |
There was a problem hiding this comment.
is doing 2 DTensor operations (to, from) really the best way here? why not just insert one autograd.function where the backwards is an all_reduce?
There was a problem hiding this comment.
ok. well short term it seems harmless to land this, other than it would have more overhead. (worth confirming, but I assume it does not do any extra collectives or operations?) anyway, we could fix them all to use a dedicated function from spmd_types once that's available.
There was a problem hiding this comment.
it should not have any extra collectives other than the all reduce in bwd. yes I think we could directly use the function from spmd_types once it's ready!
|
@acisseJZhong I'm glad @volcacius and I were on the right track with the NoParallel wrapper being the correct conceptual boundary for the reduction, but your fix handling the activations directly is a really clean solution. Really happy to have helped kick off this investigation and grateful for the opportunity to learn from the team here :) Thanks everyone once again |
|
@fatih-uzlmz thanks for the kind words! Turns out your fix was definitely on the right direction! Please feel free to help review the PR, and also test on your end to verify the bug goes away, and let us know if you have doubts. I used Claude extensively(e.g. claude thinking) for this bug fix so might be missing something lol Although now each rank router weights are the same, there's actually no strong guarantee that MoE numerics are correct? Going forward, we plan to introduce spmd_types as a type checker for DTensor to guarantee correctness, and hopefully this kind of bugs could surface quicker. |
|
@acisseJZhong haha yeah, it's honestly super validating to hear that! it's also pretty cool to know even the team relies on Claude's thinking mode for this kind of heavy DTensor math I unfortunately don't have a multi-GPU hardware setup on my end to run the physical reproduction tests right now but the logic in the PR looks very solid to me. and introducing |
| # so gradient reduction happens once at the MoE boundary (reduce-scatter) | ||
| # rather than being duplicated inside the MoE. | ||
| if isinstance(x, DTensor): | ||
| x = x.to_local(grad_placements=(Partial(),)) |
There was a problem hiding this comment.
You are assuming
- 1D mesh
- The mesh is TP
At least do assertions on them.
| self.w3 = nn.Linear(dim, hidden_dim, bias=False) | ||
|
|
||
| def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
| if getattr(self.w1, "_moe_no_hooks", False): |
There was a problem hiding this comment.
this part is where I am not very certain of 🤣
Seems like this changes inside FeedFoward forward is necessary: because we remove the input and output hooks for Col and RowwiseParallel, and MoE input is Partial plain tensor because L496, so we need to convert the shared expert weight to plain tensor to avoid DTensor wrapping x as DTensor(Replicate).
However, FeedForward is used by both shared expert and dense FFN layers, and I only want this fix to apply for the first case. Therefore I added the check: to decide if I should do F.linear or self.w1
| raise NotImplementedError( | ||
| "MoERowwiseParallel currently only supports nn.Linear and nn.Embedding!" | ||
| ) | ||
| module._moe_no_hooks = True |
There was a problem hiding this comment.
why do you need this field?
There was a problem hiding this comment.
answered above
| transformer_block.set_modules_to_backward_prefetch([model.tok_embeddings]) | ||
|
|
||
|
|
||
| class MoEColwiseParallel(ColwiseParallel): |
There was a problem hiding this comment.
Name is bad. Does it have anything to do with MoE?
There was a problem hiding this comment.
Put them in distributed/tensor_parallel.py instead of here
There was a problem hiding this comment.
good point, it's parallel to MoE. Maybe rename it to ColwisePartitionOnly which indicates that it only partition the weights/no hooks?
| input_layout: Placement | None = None, | ||
| output_layout: Placement | None = None, | ||
| use_local_output: bool = True, | ||
| output_grad_as_partial: bool = False, |
There was a problem hiding this comment.
This sounds too restrictive. Maybe merge use_local_output and this field as local_output_grad_placements. If None, then don't cast to local.
In some sense, we would require user to think about grad placement when casting to local, as there's no guarantee on correctness automatically.
There was a problem hiding this comment.
also need to audit all callsites
https://github.com/search?q=repo%3Apytorch%2Ftorchtitan%20NoParallel&type=code
The qwen3 one seems correct as it's not using local outputs.
2bb065a to
1703117
Compare
| def _prepare_output_fn( | ||
| output_layout: Placement, | ||
| use_local_output: bool, | ||
| local_output_grad_placements: Sequence[Placement] | None, |
There was a problem hiding this comment.
| local_output_grad_placements: Sequence[Placement] | None, | |
| local_output_grad_placements: tuple[Placement] | None, |
There was a problem hiding this comment.
| { | ||
| "moe.shared_experts.w1": ColwiseParallel(), | ||
| "moe.shared_experts.w1": ColwiseParallel( | ||
| grad_placements=(Partial(),), |
There was a problem hiding this comment.
wait did you add this support somewhere?
I didn't see it in #2416
I don't mind us creating ad hoc ParallelStyle in torchtitan/distributed/tensor_parallel.py
There was a problem hiding this comment.
oops I literally was tying git push command and we went for lunch 😆
I added to ColwiseParallel https://github.com/pytorch/pytorch/pull/175867/changes#diff-b4e400af23b02b381f3f4ab90eb0bc0ae2691b63d2b587257c76d22848dd33bbL108, if you think it's too much change in pytorch, I am okay with creating a new Style in Torchtitan as well.
There was a problem hiding this comment.
I think we can temporarily put it in torchtitan, given that we are going to migrate to spmd anyway.
The necessity to change ParallelStyle in core is not as much as that for changing from_local.
There was a problem hiding this comment.
Is it fair to say NoParallel is only used on TP mesh? If so, let's move it to tensor_parallel.py.
There was a problem hiding this comment.
yeah I think so, since the default desired input and output layout are all Replicate(1 dimensional). It's fair to claim this. All the current usages of NoParallel also always apply on TP mesh.
| Returns: | ||
| out (torch.Tensor): Output tensor with shape ``(bs, slen, dim)``. | ||
| """ | ||
| # Convert DTensor to local tensor for MoE-internal computation. |
There was a problem hiding this comment.
mention that in all cases [TP only, TP + EP and ETP=1, TP + EP and ETP=TP] x [router.gate, routed experts, shared experts] x [score before vs. after experts], the gradient that's flowing back is always Partial. That's why we are converting it to Partial here.
There was a problem hiding this comment.
updated, please lmk if i misunderstand anything.
There was a problem hiding this comment.
should also update moe file, including gpt-oss/moe.py and moe_deepep.py
There was a problem hiding this comment.
GptOssMoE inherits MoE here. Will update moe_deepep
| # | ||
| # This holds for all MoE components (router.gate, routed experts, shared | ||
| # experts) and regardless of score_before_experts. | ||
| if isinstance(x, DTensor): |
There was a problem hiding this comment.
this should be correct for deepep moe as it also has Reorderer when ETP=1
tianyu-l
left a comment
There was a problem hiding this comment.
lgtm, please wait until pytorch side change is landed
|
|
||
| __all__ = [ | ||
| "ParallelDims", | ||
| "NoParallel", |
There was a problem hiding this comment.
NoParallel is not very special. Let's not add this shortcut. Instead, imports need to be changed to from ...tensor_parallel
| ) | ||
|
|
||
|
|
||
| class ColwiseParallelWithGradPlacement(ColwiseParallel): |
There was a problem hiding this comment.
Maybe should change all torchtitan to use these two, as they are strictly safer. Don't need to do in this PR.
| device_mesh, | ||
| input_layouts, | ||
| run_check=False, | ||
| grad_placements=local_input_grad_placements, |
There was a problem hiding this comment.
I think we should enforce this field to be not None if input is plain tensor.
There was a problem hiding this comment.
sure, it's not enforced in pytorch from_local, but doesn't hurt to add a check in titan to force user think.
## Problem While fixing a MoE numerics bug (pytorch/torchtitan#2416), we discovered the root cause was a lack of strict gradient placement control/strict typing in `from_local`. Specifically, `from_local(Replicate)` in `ColwiseLinear` (used by the shared expert) produced correct forward behavior, but the backward pass performed an unnecessary all-reduce. The desired backward gradient placement was `Partial`, not `Replicate`. ## Solution To address this, we add a `grad_placements` keyword argument to `from_local`, mirroring the existing `grad_placements` support in `to_local`. When `grad_placements` is `None` (the default), the backward gradient placement follows the original guarantees established in #173153. When specified, it overrides the default and uses the user-provided gradient placements directly. In the longer term, we hope to address this kind of issues through spmd_types as a type checker. ## Test ``` python3 test/distributed/tensor/test_dtensor.py -k test_from_local_grad_placements ``` Pull Request resolved: #175867 Approved by: https://github.com/wconstab, https://github.com/tianyu-l
solve #2387 where user reported a bug that MoE router weights diff on each rank due to a missing all reduce under certain senarios: - `self.score_before_experts=False` for both ETP=1 and ETP=TP - `self.score_before_experts=True` and ETP=1 similar fix was proposed #2388 by @fatih-uzlmz ## Bug analysis **Case1:** When ETP=1 < TP, MoE is using TP2EP(`etp_mesh` is None, there is no ETP), `gate` is Replicated(via NoParallel), experts weight is Sharded(via EP mesh), MoE input is Replicated. _Root Cause:_ `ReordererSequenceParallell` is applied to split `top_scores` across TP ranks. Since each TP rank process its local slice of tokens through the experts, `d_routed_input` is Partial and there is no forced all-reduce. **Case2:** When ETP = TP, MoE is using DP2EP, `gate` is Replicated(via NoParallel), experts weight is Sharded(via ETP which force all reduce in bwd #1878), MoE input is Replicated on TP mesh. _Root Cause:_ The gradient flowing back to `gate.weight` is Partial when `self.score_before_experts=False`, which we incorrectly marked as Replicated and therefore results in wrong numerics. _Explanation:_ When `self.score_before_experts=True`, `d_routed_input` is already all reduced because of the fix #1878 we added to ETP. ``` routed_input = routed_input * top_scores_experts_sorted routed_output = self.experts(routed_input, ...) out_experts = routed_output_unsorted.sum(dim=1) ``` When `self.score_before_experts=False`, gradient of `top_scores` from `bmm` is Partial. The previous all reduce fix only force all reduce on `d_routed_input`, but not `d_top_scores` which is wrong. ``` routed_output = self.experts(routed_input, ...) out_experts = bmm(top_scores, routed_output_unsorted) ``` ## The fix we propose that could fix both Case1 and 2 - We revert the fix in #1878 to keep Partial dx flowing back, and delay the all reduce later at the boundary of MoE. - We choose to not use [`ColWiseParallel/RowwiseParallel`](https://github.com/pytorch/pytorch/blob/e81980ea58c65a283cf01a7132e0f420834ecf10/torch/distributed/tensor/parallel/style.py#L181) for shared expert as they force all reduce dx; but we want to keep Partial dx. So we introduced `MoEColWiseParallel/MoERowwiseParallel` which removed the input and output hooks. See the [reasoning here](https://gist.github.com/acisseJZhong/b27ecd7eca9ca1f0c050282516de2e21) for more details. - We annotate gradient of router to be partial in bwd through adding a field to NoParallel(), so that DTensor will handle the all reduce <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/8c65e360-434c-4138-9c58-f99041da5389" /> <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/474f431f-a469-400c-9256-77b514a40d7f" /> **Caveat:** The graph is plotted from [Claude generated computational graph ](https://gist.github.com/acisseJZhong/7101c2542530365b7b06bdf1f78068cb), please take it with a grain of salt. cc @volcacius @fatih-uzlmz
solve #2387 where user reported a bug that MoE router weights diff on each rank due to a missing all reduce under certain senarios: - `self.score_before_experts=False` for both ETP=1 and ETP=TP - `self.score_before_experts=True` and ETP=1 similar fix was proposed #2388 by @fatih-uzlmz ## Bug analysis **Case1:** When ETP=1 < TP, MoE is using TP2EP(`etp_mesh` is None, there is no ETP), `gate` is Replicated(via NoParallel), experts weight is Sharded(via EP mesh), MoE input is Replicated. _Root Cause:_ `ReordererSequenceParallell` is applied to split `top_scores` across TP ranks. Since each TP rank process its local slice of tokens through the experts, `d_routed_input` is Partial and there is no forced all-reduce. **Case2:** When ETP = TP, MoE is using DP2EP, `gate` is Replicated(via NoParallel), experts weight is Sharded(via ETP which force all reduce in bwd #1878), MoE input is Replicated on TP mesh. _Root Cause:_ The gradient flowing back to `gate.weight` is Partial when `self.score_before_experts=False`, which we incorrectly marked as Replicated and therefore results in wrong numerics. _Explanation:_ When `self.score_before_experts=True`, `d_routed_input` is already all reduced because of the fix #1878 we added to ETP. ``` routed_input = routed_input * top_scores_experts_sorted routed_output = self.experts(routed_input, ...) out_experts = routed_output_unsorted.sum(dim=1) ``` When `self.score_before_experts=False`, gradient of `top_scores` from `bmm` is Partial. The previous all reduce fix only force all reduce on `d_routed_input`, but not `d_top_scores` which is wrong. ``` routed_output = self.experts(routed_input, ...) out_experts = bmm(top_scores, routed_output_unsorted) ``` ## The fix we propose that could fix both Case1 and 2 - We revert the fix in #1878 to keep Partial dx flowing back, and delay the all reduce later at the boundary of MoE. - We choose to not use [`ColWiseParallel/RowwiseParallel`](https://github.com/pytorch/pytorch/blob/e81980ea58c65a283cf01a7132e0f420834ecf10/torch/distributed/tensor/parallel/style.py#L181) for shared expert as they force all reduce dx; but we want to keep Partial dx. So we introduced `MoEColWiseParallel/MoERowwiseParallel` which removed the input and output hooks. See the [reasoning here](https://gist.github.com/acisseJZhong/b27ecd7eca9ca1f0c050282516de2e21) for more details. - We annotate gradient of router to be partial in bwd through adding a field to NoParallel(), so that DTensor will handle the all reduce <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/8c65e360-434c-4138-9c58-f99041da5389" /> <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/474f431f-a469-400c-9256-77b514a40d7f" /> **Caveat:** The graph is plotted from [Claude generated computational graph ](https://gist.github.com/acisseJZhong/7101c2542530365b7b06bdf1f78068cb), please take it with a grain of salt. cc @volcacius @fatih-uzlmz
## Problem While fixing a MoE numerics bug (pytorch/torchtitan#2416), we discovered the root cause was a lack of strict gradient placement control/strict typing in `from_local`. Specifically, `from_local(Replicate)` in `ColwiseLinear` (used by the shared expert) produced correct forward behavior, but the backward pass performed an unnecessary all-reduce. The desired backward gradient placement was `Partial`, not `Replicate`. ## Solution To address this, we add a `grad_placements` keyword argument to `from_local`, mirroring the existing `grad_placements` support in `to_local`. When `grad_placements` is `None` (the default), the backward gradient placement follows the original guarantees established in pytorch#173153. When specified, it overrides the default and uses the user-provided gradient placements directly. In the longer term, we hope to address this kind of issues through spmd_types as a type checker. ## Test ``` python3 test/distributed/tensor/test_dtensor.py -k test_from_local_grad_placements ``` Pull Request resolved: pytorch#175867 Approved by: https://github.com/wconstab, https://github.com/tianyu-l
…2416) solve pytorch#2387 where user reported a bug that MoE router weights diff on each rank due to a missing all reduce under certain senarios: - `self.score_before_experts=False` for both ETP=1 and ETP=TP - `self.score_before_experts=True` and ETP=1 similar fix was proposed pytorch#2388 by @fatih-uzlmz ## Bug analysis **Case1:** When ETP=1 < TP, MoE is using TP2EP(`etp_mesh` is None, there is no ETP), `gate` is Replicated(via NoParallel), experts weight is Sharded(via EP mesh), MoE input is Replicated. _Root Cause:_ `ReordererSequenceParallell` is applied to split `top_scores` across TP ranks. Since each TP rank process its local slice of tokens through the experts, `d_routed_input` is Partial and there is no forced all-reduce. **Case2:** When ETP = TP, MoE is using DP2EP, `gate` is Replicated(via NoParallel), experts weight is Sharded(via ETP which force all reduce in bwd pytorch#1878), MoE input is Replicated on TP mesh. _Root Cause:_ The gradient flowing back to `gate.weight` is Partial when `self.score_before_experts=False`, which we incorrectly marked as Replicated and therefore results in wrong numerics. _Explanation:_ When `self.score_before_experts=True`, `d_routed_input` is already all reduced because of the fix pytorch#1878 we added to ETP. ``` routed_input = routed_input * top_scores_experts_sorted routed_output = self.experts(routed_input, ...) out_experts = routed_output_unsorted.sum(dim=1) ``` When `self.score_before_experts=False`, gradient of `top_scores` from `bmm` is Partial. The previous all reduce fix only force all reduce on `d_routed_input`, but not `d_top_scores` which is wrong. ``` routed_output = self.experts(routed_input, ...) out_experts = bmm(top_scores, routed_output_unsorted) ``` ## The fix we propose that could fix both Case1 and 2 - We revert the fix in pytorch#1878 to keep Partial dx flowing back, and delay the all reduce later at the boundary of MoE. - We choose to not use [`ColWiseParallel/RowwiseParallel`](https://github.com/pytorch/pytorch/blob/e81980ea58c65a283cf01a7132e0f420834ecf10/torch/distributed/tensor/parallel/style.py#L181) for shared expert as they force all reduce dx; but we want to keep Partial dx. So we introduced `MoEColWiseParallel/MoERowwiseParallel` which removed the input and output hooks. See the [reasoning here](https://gist.github.com/acisseJZhong/b27ecd7eca9ca1f0c050282516de2e21) for more details. - We annotate gradient of router to be partial in bwd through adding a field to NoParallel(), so that DTensor will handle the all reduce <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/8c65e360-434c-4138-9c58-f99041da5389" /> <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/474f431f-a469-400c-9256-77b514a40d7f" /> **Caveat:** The graph is plotted from [Claude generated computational graph ](https://gist.github.com/acisseJZhong/7101c2542530365b7b06bdf1f78068cb), please take it with a grain of salt. cc @volcacius @fatih-uzlmz
…2416) solve pytorch#2387 where user reported a bug that MoE router weights diff on each rank due to a missing all reduce under certain senarios: - `self.score_before_experts=False` for both ETP=1 and ETP=TP - `self.score_before_experts=True` and ETP=1 similar fix was proposed pytorch#2388 by @fatih-uzlmz ## Bug analysis **Case1:** When ETP=1 < TP, MoE is using TP2EP(`etp_mesh` is None, there is no ETP), `gate` is Replicated(via NoParallel), experts weight is Sharded(via EP mesh), MoE input is Replicated. _Root Cause:_ `ReordererSequenceParallell` is applied to split `top_scores` across TP ranks. Since each TP rank process its local slice of tokens through the experts, `d_routed_input` is Partial and there is no forced all-reduce. **Case2:** When ETP = TP, MoE is using DP2EP, `gate` is Replicated(via NoParallel), experts weight is Sharded(via ETP which force all reduce in bwd pytorch#1878), MoE input is Replicated on TP mesh. _Root Cause:_ The gradient flowing back to `gate.weight` is Partial when `self.score_before_experts=False`, which we incorrectly marked as Replicated and therefore results in wrong numerics. _Explanation:_ When `self.score_before_experts=True`, `d_routed_input` is already all reduced because of the fix pytorch#1878 we added to ETP. ``` routed_input = routed_input * top_scores_experts_sorted routed_output = self.experts(routed_input, ...) out_experts = routed_output_unsorted.sum(dim=1) ``` When `self.score_before_experts=False`, gradient of `top_scores` from `bmm` is Partial. The previous all reduce fix only force all reduce on `d_routed_input`, but not `d_top_scores` which is wrong. ``` routed_output = self.experts(routed_input, ...) out_experts = bmm(top_scores, routed_output_unsorted) ``` ## The fix we propose that could fix both Case1 and 2 - We revert the fix in pytorch#1878 to keep Partial dx flowing back, and delay the all reduce later at the boundary of MoE. - We choose to not use [`ColWiseParallel/RowwiseParallel`](https://github.com/pytorch/pytorch/blob/e81980ea58c65a283cf01a7132e0f420834ecf10/torch/distributed/tensor/parallel/style.py#L181) for shared expert as they force all reduce dx; but we want to keep Partial dx. So we introduced `MoEColWiseParallel/MoERowwiseParallel` which removed the input and output hooks. See the [reasoning here](https://gist.github.com/acisseJZhong/b27ecd7eca9ca1f0c050282516de2e21) for more details. - We annotate gradient of router to be partial in bwd through adding a field to NoParallel(), so that DTensor will handle the all reduce <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/8c65e360-434c-4138-9c58-f99041da5389" /> <img width="4096" height="2056" alt="image" src="https://github.com/user-attachments/assets/474f431f-a469-400c-9256-77b514a40d7f" /> **Caveat:** The graph is plotted from [Claude generated computational graph ](https://gist.github.com/acisseJZhong/7101c2542530365b7b06bdf1f78068cb), please take it with a grain of salt. cc @volcacius @fatih-uzlmz
solve #2387 where user reported a bug that MoE router weights diff on each rank due to a missing all reduce under certain senarios:
self.score_before_experts=Falsefor both ETP=1 and ETP=TPself.score_before_experts=Trueand ETP=1similar fix was proposed #2388 by @fatih-uzlmz
Bug analysis
Case1:
When ETP=1 < TP, MoE is using TP2EP(
etp_meshis None, there is no ETP),gateis Replicated(via NoParallel), experts weight is Sharded(via EP mesh), MoE input is Replicated.Root Cause:
ReordererSequenceParallellis applied to splittop_scoresacross TP ranks. Since each TP rank process its local slice of tokens through the experts,d_routed_inputis Partial and there is no forced all-reduce.Case2:
When ETP = TP, MoE is using DP2EP,
gateis Replicated(via NoParallel), experts weight is Sharded(via ETP which force all reduce in bwd #1878), MoE input is Replicated on TP mesh.Root Cause: The gradient flowing back to
gate.weightis Partial whenself.score_before_experts=False, which we incorrectly marked as Replicated and therefore results in wrong numerics.Explanation:
When
self.score_before_experts=True,d_routed_inputis already all reduced because of the fix #1878 we added to ETP.When
self.score_before_experts=False, gradient oftop_scoresfrombmmis Partial. The previous all reduce fix only force all reduce ond_routed_input, but notd_top_scoreswhich is wrong.The fix we propose that could fix both Case1 and 2
ColWiseParallel/RowwiseParallelfor shared expert as they force all reduce dx; but we want to keep Partial dx. So we introducedMoEColWiseParallel/MoERowwiseParallelwhich removed the input and output hooks. See the reasoning here for more details.Caveat: The graph is plotted from Claude generated computational graph , please take it with a grain of salt.
cc @volcacius @fatih-uzlmz