Skip to content

[TRTLLM-14575][fix] MoE: fp32 accumulation in deferred MoEAllReduce finalize#16778

Merged
xwang233 merged 1 commit into
NVIDIA:mainfrom
xwang233:fix/moe-deferred-finalize-fp32-accum
Jul 24, 2026
Merged

[TRTLLM-14575][fix] MoE: fp32 accumulation in deferred MoEAllReduce finalize#16778
xwang233 merged 1 commit into
NVIDIA:mainfrom
xwang233:fix/moe-deferred-finalize-fp32-accum

Conversation

@xwang233

@xwang233 xwang233 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Description

The deferred fused MoE finalize path (do_finalize=false) in
moefinalize_allreduce_fusion_kernel_oneshot_lamport accumulated the top-k
weighted expert sum and the shared-expert add directly in DType (bf16),
rounding after each of the top_k terms. The non-deferred in-kernel finalize
(do_finalize=true) accumulates the same sum in fp32, so the two combine paths
were not numerically equivalent.

The bf16 per-term rounding biases the routed MoE output. With attention-DP
disabled + MTP speculative decoding, the drift in the target hidden states is
large enough to lower the MTP acceptance length.

Fix

Accumulate the top-k sum and the shared-expert add in a local fp32 array and
round to DType once, when packing into the accumulator for the 128-bit
Lamport all-reduce store. The Lamport transport is unchanged; the only added
work is a per-lane fp32 add, so the decode step time is unchanged.

Measured impact

GLM-5.2 (NVFP4) with MTP speculative decoding — GB300, TP4/EP4, attention-DP
off, batch size 1, decode-only:

deferred combine MTP acceptance length decode tok/s/user step time
bf16 (before) 2.28 ~152.7 ~14.9 ms
fp32 (this PR) 2.99 ~200.6 ~14.9 ms

+31% decode throughput at unchanged step time, with the acceptance length
recovering to match the fp32 in-kernel finalize. Only decode is affected; the
prefill/context path already uses the non-deferred fp32 finalize.

Test Coverage

The modified kernel moefinalize_allreduce_fusion_kernel_oneshot_lamport is
exercised by the existing MoE finalize / AllReduce-fusion paths. The
accuracy/perf impact above was measured on an end-to-end NVFP4 MoE + MTP decode
workload; output remains coherent.

PR Checklist

  • Change is limited to the deferred finalize accumulation precision; no API
    or transport change.
  • Commit is DCO signed-off.

Dev Engineer Review

  • Updated the deferred fused MoE finalize path to accumulate top-k weighted expert outputs and shared-expert output in fp32.
  • Converts to DType only once before the existing 128-bit Lamport all-reduce store, removing per-term rounding and fixing precision asymmetry.
  • Lamport transport and public APIs are unchanged; no configuration or test-list changes were detected.
  • The change is localized and consistent with the reported performance and acceptance-length improvements.

QA Engineer Review

No test changes.

@xwang233
xwang233 marked this pull request as ready for review July 23, 2026 05:27
@xwang233
xwang233 requested a review from a team as a code owner July 23, 2026 05:27
@xwang233
xwang233 requested review from rosong11 and xxi-nv July 23, 2026 05:27
…inalize

The deferred fused-finalize path (do_finalize=false) in
moefinalize_allreduce_fusion_kernel_oneshot_lamport accumulated the top-k
weighted expert sum and the shared-expert add directly in DType (bf16),
rounding after each of the top_k terms. The non-deferred in-kernel finalize
(do_finalize=true) accumulates the same sum in fp32. This precision asymmetry
degrades the routed MoE output, and with attention-DP disabled + MTP
speculative decoding it drifts the target hidden states enough to lower the
MTP acceptance length.

Accumulate the top-k sum and the shared-expert add in a local fp32 array,
rounding to DType only once when packing into the accumulator for the 128-bit
Lamport all-reduce store. Transport is unchanged; the added work is a per-lane
fp32 add, so the decode step time is unchanged.

Measured on GLM-5.2 (NVFP4) with MTP speculative decoding (GB300, TP4/EP4,
attention-DP off, batch size 1, decode-only):
  - before (bf16 deferred combine): acceptance length 2.28, ~152.7 tok/s/user
  - after  (fp32 deferred combine): acceptance length 2.99, ~200.6 tok/s/user
i.e. +31% decode throughput at an unchanged ~14.9 ms/step, with the acceptance
length recovering to match the fp32 in-kernel finalize.

Signed-off-by: Xiao Wang <24860335+xwang233@users.noreply.github.com>
@xwang233

Copy link
Copy Markdown
Collaborator Author

/bot run

@xwang233
xwang233 force-pushed the fix/moe-deferred-finalize-fp32-accum branch from df5994b to 3fa37f3 Compare July 23, 2026 05:29
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The fused MoE one-shot Lamport kernel accumulates top-k weighted expert outputs and optional shared-expert outputs in fp32, then converts each accumulated result to DType once before the packed store.

Changes

MoE accumulation precision

Layer / File(s) Summary
FP32 accumulation and final conversion
cpp/tensorrt_llm/kernels/communicationKernels/moeAllReduceFusionKernels.cu
Top-k and shared-expert contributions accumulate in facc using fp32 arithmetic, then populate the DType accumulator with a single conversion before the Lamport store.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: wanli-jiang

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise, specific, and accurately reflects the main precision fix in the deferred MoE finalize path.
Description check ✅ Passed The description follows the template and includes Description, Test Coverage, and PR Checklist sections with relevant details.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cpp/tensorrt_llm/kernels/communicationKernels/moeAllReduceFusionKernels.cu (1)

595-595: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use complete, capitalized comments.

These comment fragments violate the C++ comment convention.

Proposed cleanup
-            // * acc += scale(data)  (fp32 accumulation)
+            // Accumulate scaled expert data in fp32.
...
-        // * Add shared expert output  (fp32 accumulation)
+        // Add the shared-expert output using fp32 accumulation.

As per coding guidelines, “capitalize and punctuate full-sentence comments.”

Also applies to: 603-603

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tensorrt_llm/kernels/communicationKernels/moeAllReduceFusionKernels.cu`
at line 595, Update the comments near the fp32 accumulation expressions at the
referenced locations to use complete, capitalized sentences with appropriate
ending punctuation, while preserving their existing meaning.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cpp/tensorrt_llm/kernels/communicationKernels/moeAllReduceFusionKernels.cu`:
- Line 595: Update the comments near the fp32 accumulation expressions at the
referenced locations to use complete, capitalized sentences with appropriate
ending punctuation, while preserving their existing meaning.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8e52e2f9-546f-451e-b839-c58a8686af95

📥 Commits

Reviewing files that changed from the base of the PR and between b039094 and df5994b.

📒 Files selected for processing (1)
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAllReduceFusionKernels.cu

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61198 [ run ] triggered by Bot. Commit: 3fa37f3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61198 [ run ] completed with state FAILURE. Commit: 3fa37f3
/LLM/main/L0_MergeRequest_PR pipeline #49443 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@xwang233
xwang233 marked this pull request as draft July 23, 2026 14:49
@xwang233
xwang233 marked this pull request as ready for review July 23, 2026 15:51
@xwang233

Copy link
Copy Markdown
Collaborator Author

/bot run --reuse-test

1 similar comment
@xwang233

Copy link
Copy Markdown
Collaborator Author

/bot run --reuse-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61351 [ run ] triggered by Bot. Commit: 3fa37f3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61351 [ run ] completed with state FAILURE. Commit: 3fa37f3
/LLM/main/L0_MergeRequest_PR pipeline #49579 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@xwang233 xwang233 changed the title [TRTLLM-14417][fix] MoE: fp32 accumulation in deferred MoEAllReduce finalize [TRTLLM-14575][fix] MoE: fp32 accumulation in deferred MoEAllReduce finalize Jul 23, 2026

@xxi-nv xxi-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the catch.

@xwang233

Copy link
Copy Markdown
Collaborator Author

/bot run --reuse-test --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61442 [ run ] triggered by Bot. Commit: 3fa37f3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61442 [ run ] completed with state SUCCESS. Commit: 3fa37f3
/LLM/main/L0_MergeRequest_PR pipeline #49664 completed with status: 'SUCCESS'

CI Report

Link to invocation

@xwang233
xwang233 merged commit 2801e94 into NVIDIA:main Jul 24, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants