Repository navigation
[BugFix][MoE] Share the MegaMoE buffer for DeepSeek V4.1 DSpark on A5 - #23017
Conversation
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. 🤖 How to trigger CI
Note Until the CI gate has run on a commit, the required Tip 💡 Consider Linking a Related Issue or RFCYour 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:
🙏 Thanks for helping us keep the project well-organized! |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
0fa1cb3 to
f83aff7
Compare
f83aff7 to
0cdc367
Compare
|
@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. |
|
/run |
|
Thanks for catching both mypy errors, @zhenwenqi2024. I addressed them in 8fa7f32. The fixture now declares Pre-commit passed on the updated commit. CI job |
4812340 to
0a91e40
Compare
|
/run |
zhenwenqi2024
left a comment
There was a problem hiding this comment.
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.
|
/run |
zhenwenqi2024
left a comment
There was a problem hiding this comment.
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>
683c133 to
830c1f0
Compare
|
/run |
|
/run |
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.
c410543d9)4ba787ec9)lhf_r148The 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 withenable_fused_mc2=2.dispatch_ffn_combinebaseline. 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.lhf_r148. DP8/TP1/EP8 started withFULL_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.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