Skip to content

Conversation

@MrGeva
Copy link
Collaborator

@MrGeva MrGeva commented Nov 16, 2025

When using demollm mode in AD the fused_allreduce_residual_rmsnorm fails because it tried to call trtllm's allreduce, however it is not supported in this mode. Added a check and fallback to torch op.

e.g.
python3 /opt/tensorrt-llm/examples/auto_deploy/build_and_run_ad.py --model unsloth/Meta-Llama-3.1-8B-Instruct --args.model-factory AutoModelForCausalLM '--args.model-kwargs={}' --args.tokenizer null --args.world-size 2 --args.compile-backend torch-compile --args.attn-backend triton --args.runtime demollm --args.skip-loading-weights False --args.transforms.detect-sharding.simple-shard-only False --args.max-seq-len 512 --benchmark.enabled True --benchmark.results-path /jet/logs/basic/auto-deploy-model-coverage_ab-triton_b-true_cb-torch-compile_m-unsloth-meta-llama-3-1-8b-instruct_mf-automodelforcausallm_mk--_msl-512_r-demollm_sso-false_sw-false_t-null_ws-2/extra.json --benchmark.store-results true

Summary by CodeRabbit

  • Bug Fixes

    • Improved fallback behavior for distributed tensor operations when optimized implementations are unavailable, ensuring consistent functionality across different system configurations.
  • Improvements

    • Enhanced conditional handling to use optimized paths when available, with graceful degradation to alternative implementations.

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

  • Update tava architecture diagram if there is a significant design change in PR.

  • 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 the stage-list parameter 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.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip 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-pipeline

Reuse 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.

Signed-off-by: Eran Geva <19514940+MrGeva@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2025

📝 Walkthrough

Walkthrough

Modified fused_allreduce_residual_rmsnorm to conditionally use TRT-LLM fused ops when available, otherwise fallback to a torch.distributed-based implementation that performs all-reduce on a cloned tensor, adds residual, and applies RMSNorm. Both execution paths return the same outputs.

Changes

Cohort / File(s) Summary
Conditional fallback for TRT-LLM ops availability
tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
Added conditional check (is_trtllm_op_available) to branch between fused AllReduceParams path and non-fused torch.distributed fallback. Fallback implements all-reduce on tensor clone, residual addition, and RMSNorm computation. Both paths return consistent outputs.

Sequence Diagram

sequenceDiagram
    actor Caller
    participant fused_allreduce_residual_rmsnorm as fused_allreduce_residual_rmsnorm
    participant TRTLLMPath as Fused Path<br/>(TRT-LLM ops)
    participant FallbackPath as Fallback Path<br/>(torch.distributed)
    
    Caller->>fused_allreduce_residual_rmsnorm: Call with tensor, residual
    
    rect rgb(220, 240, 255)
    Note over fused_allreduce_residual_rmsnorm: Check is_trtllm_op_available
    alt TRT-LLM ops available
        fused_allreduce_residual_rmsnorm->>TRTLLMPath: Use fused AllReduceParams
        TRTLLMPath->>TRTLLMPath: AllReduce + Residual + RMSNorm (fused)
        TRTLLMPath-->>fused_allreduce_residual_rmsnorm: norm_out, tensor_with_residual
    else TRT-LLM ops unavailable
        fused_allreduce_residual_rmsnorm->>FallbackPath: Use torch.distributed
        FallbackPath->>FallbackPath: Clone tensor
        FallbackPath->>FallbackPath: All-reduce on clone
        FallbackPath->>FallbackPath: Add residual
        FallbackPath->>FallbackPath: Apply RMSNorm
        FallbackPath-->>fused_allreduce_residual_rmsnorm: norm_out, tensor_with_residual
    end
    end
    
    fused_allreduce_residual_rmsnorm-->>Caller: Return outputs
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Primary focus areas:
    • Verify correctness of the torch.distributed fallback implementation (all-reduce, residual addition, RMSNorm)
    • Confirm tensor cloning behavior and memory efficiency
    • Ensure both code paths return identical output shapes and semantics
    • Validate RMSNorm epsilon and weight scaling in fallback matches expected behavior

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ⚠️ Warning PR description lacks required template sections (Title format, formal Description, Test Coverage) and doesn't follow repository guidelines. Add proper PR title with ticket format and type prefix. Fill in the Description and Test Coverage sections with detailed explanations of the issue, solution, and test cases.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing fused_allreduce_residual_rmsnorm to support demollm mode, which aligns with the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (2)
tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py (2)

58-76: Consider adding tests for the fallback path.

The fallback implementation for demollm mode is a new code path that should be covered by tests to ensure it produces equivalent results to the fused kernel.

Would you like me to help generate unit tests that verify the fallback path produces correct results, especially comparing its output against expected values when is_trtllm_op_available() returns False?


71-74: Consider adding shape validation for norm_weight.

The RMSNorm implementation is correct, but there's no explicit validation that norm_weight has a compatible shape with the input tensor (typically norm_weight.shape[-1] should match tensor_with_residual.shape[-1]). While PyTorch's broadcasting will raise an error if shapes are incompatible, an explicit check could provide a clearer error message.

Example validation:

# 3. Apply RMSNorm
assert norm_weight.shape[-1] == tensor_with_residual.shape[-1], \
    f"norm_weight shape {norm_weight.shape} incompatible with tensor shape {tensor_with_residual.shape}"
variance = tensor_with_residual.pow(2).mean(-1, keepdim=True)
normalized = tensor_with_residual * torch.rsqrt(variance + eps)
norm_out = normalized * norm_weight
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2854f0c and 8fb0f39.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py (1 hunks)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/thop/allreduceOp.cpp:352-446
Timestamp: 2025-09-23T15:12:38.312Z
Learning: In TensorRT-LLM NCCL device allreduce implementation (cpp/tensorrt_llm/thop/allreduceOp.cpp), the goto pattern in runNCCLAllReduceDeviceFusion is intentionally used for future extensibility, allowing multiple switch cases to fallback to the default handler. While not aesthetically ideal, this pattern supports adding more fusion cases later that can reuse the same fallback logic.
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py:6-6
Timestamp: 2025-10-20T16:54:09.824Z
Learning: In tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py, the import `from ...modules.mamba.layernorm_gated import _layer_norm_fwd` is correct and should not be changed to modules.fla.layernorm_gated. The _layer_norm_fwd function exists in both modules/mamba/layernorm_gated.py and modules/fla/layernorm_gated.py, but the mamba version is the intended implementation for this use case.
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py:180-182
Timestamp: 2025-10-20T17:09:21.560Z
Learning: In tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py, the _gated_rmsnorm_replacement function does not need to cast the output of torch.ops.auto_deploy.torch_rmsnorm_gated back to the input dtype, even though the custom op returns fp32. The dtype handling is managed elsewhere or the fp32 output is acceptable for downstream consumers.
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/thop/allreduceOp.cpp:352-446
Timestamp: 2025-09-23T15:12:38.312Z
Learning: In TensorRT-LLM NCCL device implementation, NCCL version 2.28+ requirements are handled at runtime in the nccl_device/config layer rather than with compile-time guards. This allows the allreduceOp to remain version-agnostic and delegates version compatibility validation to the appropriate lower-level components that can gracefully handle unsupported configurations.
Learnt from: timlee0212
Repo: NVIDIA/TensorRT-LLM PR: 6886
File: tensorrt_llm/_torch/models/modeling_deepseekv3.py:0-0
Timestamp: 2025-08-14T06:36:40.701Z
Learning: In DeepSeek V3 model (tensorrt_llm/_torch/models/modeling_deepseekv3.py), the disagreement between AllReduce.__init__ guard and _compute_mlp_tp_size logic for MNNVL usage is expected by design. The AllReduce component and MLP TP-size computation intentionally use different criteria for MNNVL availability decisions.
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: tests/unittest/_torch/multi_gpu/test_nccl_device.py:138-149
Timestamp: 2025-10-13T19:45:03.518Z
Learning: In test_nccl_device.py, the NCCL device AllReduce implementation compares the entire residual tensor on each rank, unlike the UB implementation which compares per-rank chunks. The residual chunking calculations in the test are intentionally overridden to reflect this design difference.
Learnt from: tongyuantongyu
Repo: NVIDIA/TensorRT-LLM PR: 7763
File: cpp/tensorrt_llm/CMakeLists.txt:297-301
Timestamp: 2025-09-16T09:30:09.716Z
Learning: In the TensorRT-LLM project, NCCL libraries are loaded earlier by PyTorch libraries or the bindings library, so the main shared library doesn't need NCCL paths in its RPATH - the libraries will already be available in the process address space when needed.
Learnt from: amitz-nv
Repo: NVIDIA/TensorRT-LLM PR: 7033
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:0-0
Timestamp: 2025-08-19T12:45:11.997Z
Learning: In tensorrt_llm/_torch/pyexecutor/model_engine.py, DoRA (Delta Orthogonal Rank Adaptation) functionality was removed from the PyTorch flow to eliminate issues with inverted DoRA detection logic. The original is_dora condition was checking if scaling_vec_pointer == 0, which was potentially incorrect.
Learnt from: tongyuantongyu
Repo: NVIDIA/TensorRT-LLM PR: 7520
File: tensorrt_llm/_torch/pyexecutor/resource_manager.py:605-613
Timestamp: 2025-09-24T03:31:28.908Z
Learning: In TensorRT-LLM Ray orchestrator mode, ProcessGroups are initialized with both Gloo and NCCL backends (e.g., "cuda:nccl,cpu:gloo"), allowing PyTorch distributed to automatically route CPU tensors through Gloo and GPU tensors through NCCL. This eliminates the need for manual device placement when performing allreduce operations on base types.
Learnt from: moraxu
Repo: NVIDIA/TensorRT-LLM PR: 6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.
📚 Learning: 2025-10-20T16:54:09.824Z
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py:6-6
Timestamp: 2025-10-20T16:54:09.824Z
Learning: In tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py, the import `from ...modules.mamba.layernorm_gated import _layer_norm_fwd` is correct and should not be changed to modules.fla.layernorm_gated. The _layer_norm_fwd function exists in both modules/mamba/layernorm_gated.py and modules/fla/layernorm_gated.py, but the mamba version is the intended implementation for this use case.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-09-23T15:12:38.312Z
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/thop/allreduceOp.cpp:352-446
Timestamp: 2025-09-23T15:12:38.312Z
Learning: In TensorRT-LLM NCCL device allreduce implementation (cpp/tensorrt_llm/thop/allreduceOp.cpp), the goto pattern in runNCCLAllReduceDeviceFusion is intentionally used for future extensibility, allowing multiple switch cases to fallback to the default handler. While not aesthetically ideal, this pattern supports adding more fusion cases later that can reuse the same fallback logic.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-08-14T06:36:40.701Z
Learnt from: timlee0212
Repo: NVIDIA/TensorRT-LLM PR: 6886
File: tensorrt_llm/_torch/models/modeling_deepseekv3.py:0-0
Timestamp: 2025-08-14T06:36:40.701Z
Learning: In DeepSeek V3 model (tensorrt_llm/_torch/models/modeling_deepseekv3.py), the disagreement between AllReduce.__init__ guard and _compute_mlp_tp_size logic for MNNVL usage is expected by design. The AllReduce component and MLP TP-size computation intentionally use different criteria for MNNVL availability decisions.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-09-23T15:12:38.312Z
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/thop/allreduceOp.cpp:352-446
Timestamp: 2025-09-23T15:12:38.312Z
Learning: In TensorRT-LLM NCCL device implementation, NCCL version 2.28+ requirements are handled at runtime in the nccl_device/config layer rather than with compile-time guards. This allows the allreduceOp to remain version-agnostic and delegates version compatibility validation to the appropriate lower-level components that can gracefully handle unsupported configurations.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-10-20T17:09:21.560Z
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py:180-182
Timestamp: 2025-10-20T17:09:21.560Z
Learning: In tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py, the _gated_rmsnorm_replacement function does not need to cast the output of torch.ops.auto_deploy.torch_rmsnorm_gated back to the input dtype, even though the custom op returns fp32. The dtype handling is managed elsewhere or the fp32 output is acceptable for downstream consumers.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-09-09T09:40:45.658Z
Learnt from: fredricz-20070104
Repo: NVIDIA/TensorRT-LLM PR: 7645
File: tests/integration/test_lists/qa/llm_function_core.txt:648-648
Timestamp: 2025-09-09T09:40:45.658Z
Learning: In TensorRT-LLM test lists, it's common and intentional for the same test to appear in multiple test list files when they serve different purposes (e.g., llm_function_core.txt for comprehensive core functionality testing and llm_function_core_sanity.txt for quick sanity checks). This duplication allows tests to be run in different testing contexts.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-09-16T09:30:09.716Z
Learnt from: tongyuantongyu
Repo: NVIDIA/TensorRT-LLM PR: 7763
File: cpp/tensorrt_llm/CMakeLists.txt:297-301
Timestamp: 2025-09-16T09:30:09.716Z
Learning: In the TensorRT-LLM project, NCCL libraries are loaded earlier by PyTorch libraries or the bindings library, so the main shared library doesn't need NCCL paths in its RPATH - the libraries will already be available in the process address space when needed.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-08-19T12:45:11.997Z
Learnt from: amitz-nv
Repo: NVIDIA/TensorRT-LLM PR: 7033
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:0-0
Timestamp: 2025-08-19T12:45:11.997Z
Learning: In tensorrt_llm/_torch/pyexecutor/model_engine.py, DoRA (Delta Orthogonal Rank Adaptation) functionality was removed from the PyTorch flow to eliminate issues with inverted DoRA detection logic. The original is_dora condition was checking if scaling_vec_pointer == 0, which was potentially incorrect.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-08-21T00:16:56.457Z
Learnt from: farshadghodsian
Repo: NVIDIA/TensorRT-LLM PR: 7101
File: docs/source/blogs/tech_blog/blog9_Deploying_GPT_OSS_on_TRTLLM.md:36-36
Timestamp: 2025-08-21T00:16:56.457Z
Learning: TensorRT-LLM container release tags in documentation should only reference published NGC container images. The README badge version may be ahead of the actual published container versions.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
📚 Learning: 2025-08-01T15:14:45.673Z
Learnt from: yibinl-nvidia
Repo: NVIDIA/TensorRT-LLM PR: 6506
File: examples/models/core/mixtral/requirements.txt:3-3
Timestamp: 2025-08-01T15:14:45.673Z
Learning: In TensorRT-LLM, examples directory can have different dependency versions than the root requirements.txt file. Version conflicts between root and examples dependencies are acceptable because examples are designed to be standalone and self-contained.

Applied to files:

  • tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py
🧬 Code graph analysis (1)
tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py (2)
tensorrt_llm/functional.py (1)
  • AllReduceParams (3900-3939)
tensorrt_llm/_torch/auto_deploy/distributed/common.py (1)
  • all_reduce (44-48)
⏰ 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 (4)
tensorrt_llm/_torch/auto_deploy/distributed/trtllm.py (4)

43-47: LGTM! Clear documentation of the dual-path behavior.

The docstring accurately describes when the fused TRT-LLM kernel is used versus the torch distributed fallback.


49-57: LGTM! TRT-LLM fused path correctly preserved.

The conditional appropriately guards the TRT-LLM fused kernel path, and the AllReduceParams configuration matches the intended fusion operation.


64-65: LGTM! Clone is necessary for correctness.

The clone operation is required because torch.distributed.all_reduce mutates tensors in-place, and the custom op is declared with mutates_args=(). The memory overhead is acceptable for correctness in the fallback path.


58-76: Match tuple structure but update dtype handling in fallback to use float32 intermediate for consistency and numerical stability.

The fallback implementation returns the correct tuple structure (norm_out, tensor_with_residual), semantically matching the reference implementation. However, the reference implementation (test_allreduce.py:182-187) converts to float32 before applying RMSNorm for numerical stability, then converts back to the original dtype:

The reference converts the intermediate to float32, applies RMSNorm, then converts both outputs back to the original dtype.

The fallback (lines 72-74) applies RMSNorm directly without float32 intermediate, which could lead to precision differences. Update lines 72-74 to match the reference:

variance = tensor_with_residual.to(torch.float32).pow(2).mean(-1, keepdim=True)
normalized = tensor_with_residual.to(torch.float32) * torch.rsqrt(variance + eps)
norm_out = (normalized * norm_weight).to(tensor.dtype)
tensor_with_residual = tensor_with_residual.to(tensor.dtype)
⛔ Skipped due to learnings
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: tests/unittest/_torch/multi_gpu/test_nccl_device.py:138-149
Timestamp: 2025-10-13T19:45:03.518Z
Learning: In test_nccl_device.py, the NCCL device AllReduce implementation compares the entire residual tensor on each rank, unlike the UB implementation which compares per-rank chunks. The residual chunking calculations in the test are intentionally overridden to reflect this design difference.
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py:180-182
Timestamp: 2025-10-20T17:09:21.560Z
Learning: In tensorrt_llm/_torch/auto_deploy/transform/library/rms_norm.py, the _gated_rmsnorm_replacement function does not need to cast the output of torch.ops.auto_deploy.torch_rmsnorm_gated back to the input dtype, even though the custom op returns fp32. The dtype handling is managed elsewhere or the fp32 output is acceptable for downstream consumers.
Learnt from: nv-lschneider
Repo: NVIDIA/TensorRT-LLM PR: 7910
File: cpp/tensorrt_llm/thop/allreduceOp.cpp:352-446
Timestamp: 2025-09-23T15:12:38.312Z
Learning: In TensorRT-LLM NCCL device allreduce implementation (cpp/tensorrt_llm/thop/allreduceOp.cpp), the goto pattern in runNCCLAllReduceDeviceFusion is intentionally used for future extensibility, allowing multiple switch cases to fallback to the default handler. While not aesthetically ideal, this pattern supports adding more fusion cases later that can reuse the same fallback logic.
Learnt from: timlee0212
Repo: NVIDIA/TensorRT-LLM PR: 6886
File: tensorrt_llm/_torch/models/modeling_deepseekv3.py:0-0
Timestamp: 2025-08-14T06:36:40.701Z
Learning: In DeepSeek V3 model (tensorrt_llm/_torch/models/modeling_deepseekv3.py), the disagreement between AllReduce.__init__ guard and _compute_mlp_tp_size logic for MNNVL usage is expected by design. The AllReduce component and MLP TP-size computation intentionally use different criteria for MNNVL availability decisions.
Learnt from: nvchenghaoz
Repo: NVIDIA/TensorRT-LLM PR: 8469
File: tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py:6-6
Timestamp: 2025-10-20T16:54:09.824Z
Learning: In tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py, the import `from ...modules.mamba.layernorm_gated import _layer_norm_fwd` is correct and should not be changed to modules.fla.layernorm_gated. The _layer_norm_fwd function exists in both modules/mamba/layernorm_gated.py and modules/fla/layernorm_gated.py, but the mamba version is the intended implementation for this use case.
Learnt from: ixlmar
Repo: NVIDIA/TensorRT-LLM PR: 7294
File: tensorrt_llm/_torch/modules/rms_norm.py:96-99
Timestamp: 2025-08-27T14:41:56.665Z
Learning: In tensorrt_llm/_torch/modules/rms_norm.py, the RMSNorm class uses a custom sentinel (_ARGUMENT_NOT_SPECIFIED_SENTINEL) instead of Ellipsis (...) for detecting unspecified optional arguments. Other modules in the codebase may use Ellipsis as a sentinel but do not forward it to RMSNorm methods, so there's no need for backward compatibility with Ellipsis in RMSNorm.

@MrGeva
Copy link
Collaborator Author

MrGeva commented Nov 16, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24687 [ run ] triggered by Bot. Commit: 8fb0f39

Copy link
Member

@lucaslie lucaslie left a comment

Choose a reason for hiding this comment

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

I think it's okay as a short-term fix. However, I am not super happy that our dist ops handle so much dispatching logic at the moment. I believe most of this should be part of our transforms so that the custom ops themselves have very little logic in them and are truly pure functional calls. That was also one of the goals I had in mind for nv-auto-deploy#96. Adding a ticket to your backlog to track this: #9198

@github-project-automation github-project-automation bot moved this from Backlog to In review in AutoDeploy Board Nov 16, 2025
@tensorrt-cicd
Copy link
Collaborator

PR_Github #24687 [ run ] completed with state SUCCESS. Commit: 8fb0f39
/LLM/main/L0_MergeRequest_PR pipeline #18642 completed with status: 'SUCCESS'

@MrGeva
Copy link
Collaborator Author

MrGeva commented Nov 17, 2025

@lucaslie I will be happy to take this task, thanks

Signed-off-by: Eran Geva <19514940+MrGeva@users.noreply.github.com>
@MrGeva
Copy link
Collaborator Author

MrGeva commented Nov 17, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24745 [ run ] triggered by Bot. Commit: df13880

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24745 [ run ] completed with state FAILURE. Commit: df13880
/LLM/main/L0_MergeRequest_PR pipeline #18666 completed with status: 'FAILURE'

@MrGeva
Copy link
Collaborator Author

MrGeva commented Nov 17, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24748 [ run ] triggered by Bot. Commit: df13880

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24748 [ run ] completed with state FAILURE. Commit: df13880
/LLM/main/L0_MergeRequest_PR pipeline #18667 completed with status: 'FAILURE'

@MrGeva
Copy link
Collaborator Author

MrGeva commented Nov 17, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24771 [ run ] triggered by Bot. Commit: df13880

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24771 [ run ] completed with state SUCCESS. Commit: df13880
/LLM/main/L0_MergeRequest_PR pipeline #18688 completed with status: 'FAILURE'

@MrGeva
Copy link
Collaborator Author

MrGeva commented Nov 18, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24862 [ run ] triggered by Bot. Commit: df13880

@tensorrt-cicd
Copy link
Collaborator

PR_Github #24862 [ run ] completed with state SUCCESS. Commit: df13880
/LLM/main/L0_MergeRequest_PR pipeline #18768 completed with status: 'SUCCESS'

@MrGeva MrGeva merged commit 3ac11a6 into NVIDIA:main Nov 18, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in AutoDeploy Board Nov 18, 2025
lkomali pushed a commit to lkomali/TensorRT-LLM that referenced this pull request Nov 19, 2025
…port demollm mode (NVIDIA#9197)

Signed-off-by: Eran Geva <19514940+MrGeva@users.noreply.github.com>
Signed-off-by: lkomali <lkomali@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants