Skip to content

[BugFix][MoE] Share the MegaMoE buffer for DeepSeek V4.1 DSpark on A5 - #23017

Merged
wenjun91 merged 5 commits into
vllm-project:mainfrom
rikakuhi:codex/megamoe-guarded-draft
Nov 25, 2026
Merged

wenjun91 merged 5 commits into
vllm-project:mainfrom
rikakuhi:codex/megamoe-guarded-draft

Conversation

@rikakuhi

@rikakuhi rikakuhi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

DeepSeek V4.1 Flash with DSpark can have 384 routed experts and top-k 6 in the target, and 128 experts and top-k 3 in the draft. The different expert counts create distinct FUSED_MC2 communication objects. On Atlas A5, creating two CANN MegaMoE buffers on the same communicator and op tag can leave the second context with invalid peer addresses during startup profiling. This PR follows up on #21727 and its revert #22964.

After the MRv2 DeepSeek V4.1 DSpark loader returns, it attempts sharing only when the draft executes MoE, the hardware supports the A5 CANN MXFP channel, MegaMoE is enabled and FUSED_MC2 is selected. A target and draft with different expert counts can share if they execute serially, use the same supported routed quantization and hidden width, have compatible communication parameters, and the draft fits the target buffer. The participating ranks must agree.

On CANN r148 the target and draft can use different expert counts on the same communicator and op tag when they run serially, their communication attributes match, and the draft fits the target allocation. The target owns the allocation. The draft view retains that context and supplies its own expert count and top-k.

After the layout checks, all ranks compare the draft's requirements with the actual target allocation using the installed CANN size query. If the target owns a buffer on this group and any rank rejects sharing, model loading fails before the draft can allocate a second buffer on the same tag.

Across sleep/wake, the shared buffer preserves the captured context address. If the CANN factory raises on any rank, all ranks require a fresh MC2 group before retrying because CANN may already have registered the tag. Failures after a successful allocation can retry over that allocation.

Does this PR introduce any user-facing change?

Eligible target/draft pairs on A5 reuse one MegaMoE buffer. Equal expert counts and layouts rejected by the initial eligibility checks follow their existing initialization paths. A final compatibility check that fails after the current group has been claimed reports a startup error. A3 skips the sharing check at the hardware gate. Relative to the PR base, the quantization modules, the unquantized MoE weight path, and the platform communication selector are unchanged.

How was this patch tested?

CPU regression tests

The following runs cover earlier revisions of this PR.

Source and test coverage Result
#23017 focused suite with the repository's vLLM pin (c410543d9) 732 passed
#23017 focused suite with the image's vLLM (4ba787ec9) 725 passed, 7 skipped
#23017 and #21830 together with the repository's vLLM pin 1069 passed
#23017 and #21830 together with the image's vLLM, rerun after the test-file rename in 112's lhf_r148 1062 passed, 7 skipped

The core cases are in tests/ut/ops/test_dspark_mega_moe_buffer.py. They cover a compatible 384/128 pair, equal expert counts, A3 and A5 hardware profiles, W4A8 target with an unquantized draft, existing draft buffers, capacity checks, rank disagreement, and sleep/wake. The incompatible-quantization cases verify that the existing buffers and transport registry entries retain their identities. The wider suite covers MoE, quantization, model loading, graph configuration, and other model paths. A two-process CPU Gloo test exercised rank-local release failure and collective retry with a simulated allocator.

On the review revision, three new regression cases failed against the previous implementation and passed with the fix. They cover a local capacity veto, a peer capacity veto, and a factory failure after tag registration. The 12-file suite passed all 596 tests against the repository's paired vLLM (c410543d9). A two-rank Gloo test injected factory errors on one rank and on both ranks, verified that no rank reallocated on the failed group, and recovered on a fresh group. CANN allocation failures were simulated in this test.

A5 hardware validation

The two earlier runs used DeepSeek V4.1 Flash W4A8MXFP with five-token DSpark, the CANN 9.3.0 r148 image (9722b0304456), and #23017 together with #21830. MegaMoE was explicitly enabled with enable_fused_mc2=2.

  • 1P1D on 107 and 108. All eight Prefill ranks shared the target's MegaMoE context with the draft and submitted the CANN MegaMoE kernel for both models. Short, long, and decode requests returned HTTP 200, with the same text and token IDs as the dispatch_ffn_combine baseline. A separate fresh 2493-token prompt exercised Mooncake KV transfer and produced 32 output tokens. The MegaMoE run recorded 33 draft proposals and 80 accepted tokens.
  • Colocated Prefill and Decode on 112 in lhf_r148. DP8/TP1/EP8 started with FULL_DECODE_ONLY. All eight ranks confirmed that the 384-expert/top-6 target and 128-expert/top-3 draft had the same context, device address, and buffer owner. All 22 requests returned HTTP 200, including 11 long prompts of 2492 tokens. After the initial pair, four serial calls and two eight-way concurrent rounds exercised all eight DP ranks. The repeated rounds added 136 draft proposals and 218 accepted tokens. All responses contained the expected answer. In 15 of 20 repeated calls, generated token IDs matched the corresponding initial response. Five concurrent long responses differed in tokens after the correct answer. The health check still returned HTTP 200 after the last round.

Review revision on A5 with EPLB enabled. The Prefill and Decode roles ran separately on the same eight A5 devices with the openEuler CANN 9.3.0 r148 image (9bd8129dbc44), the reviewed MegaMoE changes and #21830 on the image's vLLM-Ascend base. Both used DP8/TP1/EP8, W4A8MXFP, five-token DSpark, enable_fused_mc2=3, and EPLB with 16 redundant target experts. On all eight ranks in both roles, the 400-expert/top-6 target and 128-expert/top-3 draft shared the same context object, device address and buffer owner.

  • Prefill, eager. Six requests sent directly to the producer returned HTTP 200 and generated 1, 1, 1, 8, 16 and 32 tokens. Speculative decoding counters recorded 130 proposed tokens and 29 accepted tokens.
  • Decode, FULL_DECODE_ONLY. All eight API ranks became ready. Graph capture completed for all 41 target and 37 draft sizes.

Native HCCL sleep/wake, formal accuracy evaluation, and throughput benchmarking remain open.

Checklist

Testing

  • Boundary and edge cases for expert counts, quantization, topology and buffer capacity

  • Regression cases for sharing and for preserving native behavior when sharing is skipped

  • Failure-path coverage for rank disagreement and buffer recovery

  • Tests assert buffer identity, registered method identity and captured addresses

  • A5 performance benchmarks

  • vLLM main: vllm-project/vllm@c410543

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

🤖 How to trigger CI

CI runs automatically when the PR is opened or reopened. Pushing a new commit no longer re-runs the E2E CI (to save NPU runner resources), so use the comment commands below when needed. They are available to the PR author and users with triage permission or above:

  • /run — run the full PR CI gate on the latest commit.
  • /rerun — re-run the failed CI jobs (e.g. after a flaky failure).
  • /e2e — run selected E2E tests instead of the full gate.
  • /nightly / /presmoke / /weekly — run the corresponding large-scale tests (triage permission or above; blocked during the nightly maintenance window).
  • /cancel — cancel a running CI on this PR.

Note

Until the CI gate has run on a commit, the required ci-gate check stays pending and the PR cannot merge — remember to comment /run after pushing.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [BugFix] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a mechanism to share a single CANN channel context between serial DeepSeek V4.1 DSpark forwards, adding the ChannelWindow and ExpertLayout abstractions in mega_moe_context.py along with corresponding unit tests and configuration updates. The review feedback highlights several critical robustness and correctness issues in the new mega_moe_context.py file: (1) using vars(self.owner) may raise a TypeError if the owner is a C++ extension object, so attributes should be copied explicitly; (2) bind_dspark_window needs an early check for a None scope to prevent crashes in single-NPU environments; (3) the group attribute must be explicitly set on newly created symmetric buffers to avoid AttributeErrors; (4) target._dspark_window should be cleaned up on failure to avoid triggering unnecessary and expensive buffer restorations; and (5) wrapping process_weights_after_loading on shared quant_method instances should be tracked to prevent deep recursion nesting.

@zhenwenqi2024 zhenwenqi2024 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.

Could test_w4a8_target_unquantized_draft_first_forward reuse one of its two rows for a peer veto of AllToAll? Both target quant labels use a stand-in target and hit the same mismatch with QuantType.NONE, so both currently run the same AllToAll draft forward. Keep one row for the original mismatch and use the other to drive the first routed forward through AllGather when one peer cannot use AllToAll. The existing packing test checks the AllGather decision, but not that the selected method reaches the actual forward.

@rikakuhi
rikakuhi force-pushed the codex/megamoe-guarded-draft branch from 0fa1cb3 to f83aff7 Compare November 24, 2026 11:20
@rikakuhi rikakuhi changed the title [BugFix][MoE] Guard CANN window sharing for DeepSeek V4.1 DSpark on A5 [BugFix][MoE] Share the MegaMoE buffer for DeepSeek V4.1 DSpark on A5 Nov 24, 2026
@rikakuhi
rikakuhi force-pushed the codex/megamoe-guarded-draft branch from f83aff7 to 0cdc367 Compare November 24, 2026 11:26
@rikakuhi

Copy link
Copy Markdown
Contributor Author

@zhenwenqi2024 Thanks for the review. Review comment

We removed the PR-specific AllToAll/AllGather fallback when we narrowed this PR to A5 MegaMoE buffer sharing. For a W4A8 target and an unquantized draft, the current test verifies that sharing is skipped and the existing buffers and communication registrations are preserved. The draft’s first forward through native AllGather is still outside this test’s coverage.

@rikakuhi

rikakuhi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 8fa7f3287132325b64dfa1ed05f447e39b335d92 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026
@rikakuhi

Copy link
Copy Markdown
Contributor Author

Thanks for catching both mypy errors, @zhenwenqi2024. I addressed them in 8fa7f32. The fixture now declares allocated: set[object], and agree() returns separately from the tuple and next(peer_results) branches, preserving the peer fault injection.

Pre-commit passed on the updated commit. CI job

Review

@rikakuhi
rikakuhi force-pushed the codex/megamoe-guarded-draft branch from 4812340 to 0a91e40 Compare November 25, 2026 04:12
@rikakuhi

rikakuhi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 0a91e40c6a489368f14fa55d0e2a6ea73aa969be of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026

@zhenwenqi2024 zhenwenqi2024 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 documenting the A5 runs and the scope of the V4.1 validation. I left two questions about failure recovery and one about the CANN contract for sharing a context.

@rikakuhi

rikakuhi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 8f89467a4d7a2c9494dc501469ac583509bddc99 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026
Comment thread release_notes/fragments/23017.yaml Resolved

@zhenwenqi2024 zhenwenqi2024 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.

One suggestion on where to put the MegaMoE buffer-sharing checks.

Avoid a duplicate CANN MegaMoE buffer when the compatible DeepSeek V4.1 Flash target and draft use different expert layouts. Give the draft its own metadata over the target-owned allocation and cover the layout, quantization, and recovery checks.

Validated with CPU regression tests and A5 1P1D and mixed-serving requests.

Signed-off-by: rikakuhi <942697235@qq.com>
Annotate the mocked allocations and separate the tuple and peer-status return paths so mypy can type-check the existing fixtures.

Validated the affected test file with mypy for Python 3.10, 3.11, and 3.12 and with Ruff.

Signed-off-by: rikakuhi <942697235@qq.com>
Document why broader A5 DSpark support needs validation of startup synchronization and target buffer allocation.

Verified that the Python AST matches the previous PR head.

Signed-off-by: rikakuhi <942697235@qq.com>
Fail startup collectively when the target owns the MC2 group and the final draft buffer check fails. Require a fresh communicator after a factory error that may have registered the tag.

Three regression cases reproduce the failures on the previous revision. The focused suite passed 596 tests, and two Gloo ranks exercised recovery after an injected allocation failure.

Signed-off-by: rikakuhi <942697235@qq.com>
Move model and CANN transport eligibility into the MegaMoE helper so the
draft loader only invokes one entrypoint. Preserve the existing V4.1/A5
scope, short-circuit order, and buffer lifecycle.

Validation: 597 CPU-mock UTs passed in lhf_r148 with paired vLLM c410543d9,
including ten entrypoint cases. Windows-compatible pre-commit passed;
full mypy remains pending because local dependencies are unavailable.

Signed-off-by: rikakuhi <942697235@qq.com>
@rikakuhi
rikakuhi force-pushed the codex/megamoe-guarded-draft branch from 683c133 to 830c1f0 Compare November 25, 2026 08:53
@rikakuhi

rikakuhi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command accepted. E2E has been queued on the latest commit 830c1f0eb3fbbd63925a14fea916dbb02d1da690 of this PR, with whatever test-scope labels the PR currently carries. Track progress in PR checks.

@vllm-ascend-ci vllm-ascend-ci added ci-run E2E requested manually on the latest commit and removed ci-run E2E requested manually on the latest commit labels Nov 25, 2026
@rikakuhi

rikakuhi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

/run
[Bot]: run command skipped. E2E is already queued or running for commit 830c1f0eb3fbbd63925a14fea916dbb02d1da690. Comment /rerun instead if you only want to retry failed jobs.

@wenjun91
wenjun91 merged commit cc4c76e into vllm-project:main Nov 25, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-run E2E requested manually on the latest commit module:ops module:tests ready-precise run selected e2e test for pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants