Skip to content

[None][fix] Keep chunked-MoE size vectors identical across attention-DP ranks - #16745

Merged
dongfengy merged 1 commit into
NVIDIA:mainfrom
dongfengy:fix/chunked-moe-adp-size-desync
Jul 28, 2026
Merged

[None][fix] Keep chunked-MoE size vectors identical across attention-DP ranks#16745
dongfengy merged 1 commit into
NVIDIA:mainfrom
dongfengy:fix/chunked-moe-adp-size-desync

Conversation

@dongfengy

@dongfengy dongfengy commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Description

Under attention-DP, when a heavy prefill exceeds moe_config.max_num_tokens the MoE forward is chunked. On the varsize allgather/reduce-scatter comm lane (the fallback whenever the alltoall lane cannot run chunked, e.g. DeepEP on multi-node IB), the collectives cannot take an empty chunk, so a rank whose chunk is empty re-sends its chunk-0 data instead — but the size-vector update in _forward_multiple_chunks only patched the local rank's entry of all_rank_num_tokens_list. Different ranks then derive different size vectors for the same collective, and NCCL deadlocks: all GPUs spin at 100%, no error until the watchdog aborts (~300 s).

The fix patches every rank's empty entries from all_rank_chunk_size_list (the shared ground truth all ranks compute identically), so the per-chunk size vectors are identical across ranks. This is a no-op for the alltoall lanes, whose existing 0→1 substitution already yields identical vectors.

Test Coverage

Reproduced deterministically with Qwen3.5-397B-A17B (NVFP4) wide-EP EP16 (attention-DP) across 2×8 B200 over InfiniBand, 32k-ISL prefills with moe_config.max_num_tokens=32768: the run deadlocks at the second chunked iteration without this patch and completes 210k+ iterations cleanly with it (same wheel A/B). Accuracy sanity of the same setup is unaffected (single-chunk paths untouched).

Trigger conditions covered: attention-DP + chunked MoE (cap exceeded) + at least one rank with fewer tokens than chunks (mixed prefill/decode across DP ranks — the steady state of any real serving workload).

PR Checklist

  • The PR title follows the required format.
  • The PR description explains the issue and the fix.
  • Relevant reviewers are aware (mirror of an internal fix, validated as described above).

🤖 Generated with Claude Code

Dev Engineer Review

  • Fixed a deadlock in chunked MoE execution under attention-DP when varsize allgather/reduce-scatter collectives encounter empty chunks.
  • In tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py (ExternalCommMoEScheduler._forward_multiple_chunks), expanded the DP empty-chunk substitution so that for every chunk index idx_chunk and every DP rank j:
    • If all_rank_chunk_size_list[j][idx_chunk] == 0, the code patches all_rank_num_tokens_list[idx_chunk][j] to all_rank_chunk_size_list[j][0].
    • This mirrors the empty-chunk substitution behavior across ranks, ensuring all ranks build identical per-chunk varsize “size vectors” even when a chunk is empty locally.
  • Verified related scope: the earlier per-chunk substitution that swaps local x_list/router_logits_list/input_ids_list from empty chunks to chunk-0 remains in place; the change specifically updates the DP collective shape inputs (all_rank_num_tokens_list) to eliminate rank divergence.
  • Confirmed change does not affect the single-chunk or Alltoall paths (Alltoall uses a separate guard that substitutes 1 token for an all-zero rank).

QA Engineer Review

No test changes.

@dongfengy
dongfengy requested a review from a team as a code owner July 22, 2026 16:32
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c42671a8-dda7-44ae-b1c0-98b4225c6816

📥 Commits

Reviewing files that changed from the base of the PR and between 0700d8a and 9089e19.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py

Walkthrough

The MoE scheduler now patches token-count entries for every DP rank with an empty chunk, using chunk-0 values for consistent variable-size collective shape vectors.

Changes

DP empty-chunk synchronization

Layer / File(s) Summary
Synchronize empty-chunk token counts
tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
Empty-chunk substitution now updates all affected DP-rank entries instead of only the current TP-rank entry.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: rosong11

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required ticket/type format and clearly summarizes the chunked MoE size-vector fix.
Description check ✅ Passed The description includes clear Description, Test Coverage, and PR Checklist sections with relevant details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
✨ 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.

Actionable comments posted: 1

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

Inline comments:
In `@tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py`:
- Around line 638-647: Restrict the empty-chunk substitution loop over
all_rank_num_tokens_list to the varsize collective path by guarding it with not
moe.enable_alltoall. Preserve the earlier AllToAll zero-to-one sizing
established in the surrounding scheduler logic, and leave
all_rank_chunk_size_list unchanged as the empty-chunk reference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 205070eb-4946-4acf-96d1-24510eacc946

📥 Commits

Reviewing files that changed from the base of the PR and between 8341fb1 and fe63115.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py

Comment thread tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61030 [ run ] triggered by Bot. Commit: fe63115 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61030 [ run ] completed with state FAILURE. Commit: fe63115
/LLM/main/L0_MergeRequest_PR pipeline #49286 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

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61037 [ run ] triggered by Bot. Commit: fe63115 Link to invocation

@dongfengy
dongfengy force-pushed the fix/chunked-moe-adp-size-desync branch from fe63115 to 20444da Compare July 22, 2026 17:28
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61045 [ run ] triggered by Bot. Commit: 20444da Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61037 [ run ] completed with state ABORTED. Commit: fe63115

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61045 [ run ] completed with state FAILURE. Commit: 20444da
/LLM/main/L0_MergeRequest_PR pipeline #49300 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

@dongfengy
dongfengy force-pushed the fix/chunked-moe-adp-size-desync branch from 20444da to 00c8ffa Compare July 23, 2026 00:33
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61131 [ run ] triggered by Bot. Commit: 00c8ffa Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61131 [ run ] completed with state SUCCESS. Commit: 00c8ffa
/LLM/main/L0_MergeRequest_PR pipeline #49384 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

@dongfengy
dongfengy force-pushed the fix/chunked-moe-adp-size-desync branch from 00c8ffa to 0700d8a Compare July 24, 2026 04:14
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61497 [ run ] triggered by Bot. Commit: 0700d8a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61497 [ run ] completed with state FAILURE. Commit: 0700d8a
/LLM/main/L0_MergeRequest_PR pipeline #49716 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

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61602 [ run ] triggered by Bot. Commit: 0700d8a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61602 [ run ] completed with state FAILURE. Commit: 0700d8a
/LLM/main/L0_MergeRequest_PR pipeline #49810 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

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61651 [ run ] triggered by Bot. Commit: 0700d8a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61651 [ run ] completed with state FAILURE. Commit: 0700d8a
/LLM/main/L0_MergeRequest_PR pipeline #49857 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

…DP ranks

On cross-node IB (no MNNVL) the MoE comm lane is DeepEP; when a heavy
prefill exceeds moe_config.max_num_tokens the forward is chunked, and
DeepEP cannot run chunked, so each chunk goes through the varsize
allgather/reducescatter fallback. The collectives cannot take an empty
chunk, so a rank whose chunk is empty resends its chunk 0 instead -- but
the size-vector update only covered the local rank's entry. Ranks then
post mismatched counts for the same collective and NCCL deadlocks: all
GPUs spin at 100%, no error, watchdog abort after 300 s.

Fix: patch every rank's empty entries from the shared chunk-size table,
so all ranks derive identical size vectors. No-op for the alltoall path
(its existing 0->1 patch already yields the same values).

Repro: Qwen3.5-397B-A17B-NVFP4, 2-node x86 B200, DEP16 (attention-DP,
moe_ep=16, moe_tp=1), moe_config.max_num_tokens=32768, 32k-ISL bench at
concurrency 1 -- deterministic hang at iter 2 without this fix, clean
208k+ iterations with it.

Signed-off-by: dongfengy <99041270+dongfengy@users.noreply.github.com>
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
@dongfengy
dongfengy force-pushed the fix/chunked-moe-adp-size-desync branch from 0700d8a to 9089e19 Compare July 27, 2026 17:09
@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61954 [ run ] triggered by Bot. Commit: 9089e19 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61954 [ run ] completed with state FAILURE. Commit: 9089e19
/LLM/main/L0_MergeRequest_PR pipeline #50143 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

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62003 [ run ] triggered by Bot. Commit: 9089e19 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62003 [ run ] completed with state SUCCESS. Commit: 9089e19
/LLM/main/L0_MergeRequest_PR pipeline #50190 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

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62038 [ run ] triggered by Bot. Commit: 9089e19 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62038 [ run ] completed with state SUCCESS. Commit: 9089e19
/LLM/main/L0_MergeRequest_PR pipeline #50223 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

@dongfengy

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62138 [ run ] triggered by Bot. Commit: 9089e19 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62138 [ run ] completed with state SUCCESS. Commit: 9089e19
/LLM/main/L0_MergeRequest_PR pipeline #50316 completed with status: 'SUCCESS'

CI Report

Link to invocation

@dongfengy
dongfengy merged commit e2b7145 into NVIDIA:main Jul 28, 2026
10 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.

4 participants