-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[#5255][autodeploy] Update FuseAllreduceResidualRMSNorm to use pattern matcher utility; remove fuse_collective #7545
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
[#5255][autodeploy] Update FuseAllreduceResidualRMSNorm to use pattern matcher utility; remove fuse_collective #7545
Conversation
📝 WalkthroughWalkthroughRemoved the fuse_collectives transform from the default config. Deleted the FuseCollectives transform implementation. Refactored FuseAllreduceResidualRMSNorm to use an ADPatternMatcher-based search/replace with a fused op. Updated sharding utils to call torch.ops.auto_deploy.torch_dist_all_reduce.default for dim-1 distribution. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant GM as GraphModule
participant PM as ADPatternMatcherPass
participant Pat as AR+Res+RMSNorm Pattern
participant Fused as torch.ops.dist.fused_allreduce_residual_rmsnorm
GM->>PM: apply(pattern=Pat, dummy_args, scalar_workaround)
PM->>GM: scan graph for matches
Note over PM,GM: Find subgraph: all_reduce(x) -> add(residual) -> RMSNorm(weight, eps)
PM->>Fused: replace matched subgraph with fused op call
Fused-->>PM: fused node
PM-->>GM: updated graph, report num_matches
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (8)
tensorrt_llm/_torch/auto_deploy/utils/sharding_utils.py (1)
1-1: Add required NVIDIA Apache-2.0 header.Per repository guidelines, prepend the 2025 NVIDIA Apache-2.0 header to this file.
Apply this at file top:
+# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.tensorrt_llm/_torch/auto_deploy/transform/library/collectives.py (7)
1-1: Add required NVIDIA Apache-2.0 header.Please prepend the 2025 NVIDIA Apache-2.0 header.
+# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.
19-21: De-duplicate the eps literal via a module constant.
0.1253appears in multiple places; define once to keep pattern, replacement, and registration in sync.-def _allreduce_residual_rmsnorm_pattern( - x: torch.Tensor, residual: torch.Tensor, weight: torch.Tensor, eps: float = 0.1253 -): +RMSNORM_EPS_DEFAULT = 0.1253 + +def _allreduce_residual_rmsnorm_pattern( + x: torch.Tensor, residual: torch.Tensor, weight: torch.Tensor, eps: float = RMSNORM_EPS_DEFAULT +):
30-40: Use the op’s default overload explicitly for consistency.Elsewhere in this PR we call
.default; align here to avoid packet vs. overload mismatches in FX.- hidden_states = torch.ops.auto_deploy.torch_dist_all_reduce(x) + hidden_states = torch.ops.auto_deploy.torch_dist_all_reduce.default(x)
60-61: OK to instantiate a fresh matcher.If this transform can run multiple times in a pipeline, consider guarding duplicate registrations (see next comment).
63-79: Harden registration: avoid dupe patterns and centralize eps.
- Pass
skip_duplicates=Trueto avoid re-registering on repeated transform runs.- Reuse
RMSNORM_EPS_DEFAULTin dummy args andscalar_workaround.- dummy_args = [ + dummy_args = [ torch.randn(bsz, hidden, device="meta", dtype=torch.bfloat16), # x torch.randn(bsz, hidden, device="meta", dtype=torch.bfloat16), # residual torch.randn(hidden, device="meta", dtype=torch.bfloat16), # weight - 0.1253, # eps + RMSNORM_EPS_DEFAULT, # eps ] @@ - register_ad_pattern( + register_ad_pattern( search_fn=_allreduce_residual_rmsnorm_pattern, replace_fn=_allreduce_residual_rmsnorm_repl, patterns=patterns, dummy_args=dummy_args, op_ignore_types={torch.ops.aten.to.dtype: (torch.dtype,)}, - scalar_workaround={"eps": 0.1253}, + scalar_workaround={"eps": RMSNORM_EPS_DEFAULT}, + skip_duplicates=True, )
80-81: Recompile after graph edits to materialize codegen.Pattern pass mutates
gm.graph; call dead-code elimination and recompile.- num_matches = patterns.apply(gm.graph) + num_matches = patterns.apply(gm.graph) + gm.graph.eliminate_dead_code() + gm.recompile()
43-47: Wraptorch.ops.dist.fused_allreduce_residual_rmsnormin try/except to fall back to the Python implementation
This avoids hard failures on builds without the fused op:try: _FUSED_ARRN = torch.ops.dist.fused_allreduce_residual_rmsnorm except AttributeError: from ...distributed.trtllm import fused_allreduce_residual_rmsnorm as _FUSED_ARRN def _allreduce_residual_rmsnorm_repl(x: torch.Tensor, residual: torch.Tensor, weight: torch.Tensor, eps: float): return _FUSED_ARRN(x, residual, weight, eps)
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
tensorrt_llm/_torch/auto_deploy/config/default.yaml(0 hunks)tensorrt_llm/_torch/auto_deploy/transform/library/collectives.py(3 hunks)tensorrt_llm/_torch/auto_deploy/utils/sharding_utils.py(1 hunks)
💤 Files with no reviewable changes (1)
- tensorrt_llm/_torch/auto_deploy/config/default.yaml
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use only spaces, no tabs; indent with 4 spaces.
Files:
tensorrt_llm/_torch/auto_deploy/utils/sharding_utils.pytensorrt_llm/_torch/auto_deploy/transform/library/collectives.py
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.
Files:
tensorrt_llm/_torch/auto_deploy/utils/sharding_utils.pytensorrt_llm/_torch/auto_deploy/transform/library/collectives.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).
Files:
tensorrt_llm/_torch/auto_deploy/utils/sharding_utils.pytensorrt_llm/_torch/auto_deploy/transform/library/collectives.py
🧬 Code graph analysis (1)
tensorrt_llm/_torch/auto_deploy/transform/library/collectives.py (2)
tensorrt_llm/_torch/auto_deploy/utils/pattern_matcher.py (2)
ADPatternMatcherPass(61-67)register_ad_pattern(99-182)tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py (1)
fused_allreduce_residual_rmsnorm(27-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
🔇 Additional comments (5)
tensorrt_llm/_torch/auto_deploy/utils/sharding_utils.py (1)
169-175: Fallback fortorch_dist_all_reduce.defaultcompatibility
Use a module‐scope fallback to avoidAttributeErrorin builds where the.defaultoverload isn’t exposed, and manually verify its availability in your target environment.Apply this diff at lines 169–175 of
tensorrt_llm/_torch/auto_deploy/utils/sharding_utils.py:- 1: (torch.ops.auto_deploy.torch_dist_all_reduce.default,), + 1: (ALL_REDUCE_OP,),Add near the top of the module:
# Fallback for op overloads that may not expose `.default` ALL_REDUCE_OP = getattr( torch.ops.auto_deploy.torch_dist_all_reduce, "default", torch.ops.auto_deploy.torch_dist_all_reduce, )Request manual verification of the
.defaultattribute in your build (e.g.,dir(torch.ops.auto_deploy.torch_dist_all_reduce)) to ensure this change is necessary.tensorrt_llm/_torch/auto_deploy/transform/library/collectives.py (4)
8-8: Import switch to pattern matcher looks good.
23-28: Docstring clarity is fine.Return order is explicit; matches replacement’s tuple intent.
49-52: Transform registration retained; good.
83-85: TransformInfo wiring looks fine.Consider setting
has_valid_shapes=Trueif this transform does not rely on runtime shapes; otherwise leave as-is.
71094e3 to
ee93804
Compare
ee93804 to
33e098f
Compare
eebb455 to
701a6e3
Compare
.../auto_deploy/unit/multigpu/transformations/library/test_allreduce_residual_rmsnorm_fusion.py
Show resolved
Hide resolved
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.
lgtm
…tcher Signed-off-by: Frida Hou <201670829+Fridah-nv@users.noreply.github.com> fix fuse_allreduce_residual_rsmnode test Signed-off-by: Frida Hou <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Frida Hou <201670829+Fridah-nv@users.noreply.github.com> rm collective_fusion test Signed-off-by: Frida Hou <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Frida Hou <201670829+Fridah-nv@users.noreply.github.com>
…rsmnorm failure for DeepSeek small build test Signed-off-by: Frida Hou <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com> minor: update unit test Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
…agation Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
Signed-off-by: Fridah-nv <201670829+Fridah-nv@users.noreply.github.com>
0e29fda to
bc21976
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #20624 [ run ] triggered by Bot |
|
PR_Github #20625 [ run ] triggered by Bot |
|
PR_Github #20624 [ run ] completed with state |
|
PR_Github #20625 [ run ] completed with state |
|
/bot run |
|
PR_Github #20630 [ run ] triggered by Bot |
|
PR_Github #20630 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #20638 [ run ] triggered by Bot |
|
PR_Github #20638 [ run ] completed with state |
Summary by CodeRabbit
Description
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.