-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
[ROCm] Fix allreduce + RMSNorm fusion pattern matchin #41767
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
Closed
rbrugaro-amd
wants to merge
3
commits into
vllm-project:main
from
rbrugaro-amd:rbrugaro/fix-allreduce-rms-fusion
+11
−3
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just fix the patterns in the pass instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Investigated whether the
variance_size_overrideargument mismatch between layernorm.py (4 args) and the fusion patterns (3 args) causes a pattern-matching failure. It does not on latest nightly (sha256:18aa8ce6c3f4bf61ae220750311f0f9526bd64e1b419052817accfca625c5f90).PyTorch's C++ boxed dispatch layer (
parseIValuesToPyArgsKwargs in torch/csrc/autograd/python_variable.cpp) strips trailing positional arguments that equal their schema defaults. Since variance_size has default=None in the op schema and variance_size_override is None for all standard LLM models, the 4th argument is stripped before it reaches the FX graph the fusion passes operate on. This behavior has been in PyTorch since May 2022 (55f55a4, PR #75905).Graph dump evidence — tested on vllm/vllm-openai-rocm:nightly (fb1ac80, PyTorch 2.10.0+git8514f05) with Kimi-K2-Thinking-MXFP4 at TP=4, fresh container with zero variance_size patches:
__compiled_fn_1.BEFORE_PRE_GRAD.0.py (Dynamo trace) — rms_norm has 4 args, trailing None from self.variance_size_override:
rms_norm_default = torch.ops.vllm_ir.rms_norm.default(all_reduce, _get_data_attr, 1e-05, None)__compiled_fn_1.Forward_graph.0.py (AOT Autograd re-trace via C++ dispatch) — trailing None stripped, 3 args:
rms_norm = torch.ops.vllm_ir.rms_norm.default(all_reduce, alias, 1e-05)__compiled_fn_1.AFTER_POST_GRAD.0.py (post-fusion) — correctly replaced with the fused AITER op:
rocm_aiter_fused_allreduce_rmsnorm_default_121 = torch.ops.vllm.rocm_aiter_fused_allreduce_rmsnorm.default(where, full_default_2, arg3_1, 1e-05)245 vllm_ir.rms_norm ops pre-fusion → 366 rocm_aiter_fused_allreduce_rmsnorm ops post-fusion (includes fused_add_rms_norm variants). GSM8K accuracy on Kimi-K2-Thinking-MXFP4: 0.948 (250 samples, 5-shot).
Recommendation: The variance_size_override fix is not needed. The empty_like → zeros_like fix already merged #41972
Does this align with your observation @akii96? if so i will close this PR