Skip to content

[Perf] [NPU] moe: Add DeepGEMM-Ascend MegaMoE for Prefill - #41

Merged
AkiYangDev merged 12 commits into
randgun:dsv41-perf-1202from
AkiYangDev:draft/randgun-deepgemm-prefill
Dec 3, 2026
Merged

AkiYangDev merged 12 commits into
randgun:dsv41-perf-1202from
AkiYangDev:draft/randgun-deepgemm-prefill

Conversation

@AkiYangDev

@AkiYangDev AkiYangDev commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Port of the routed-expert Prefill provider from Ascend/sglang #1548 to dsv41-perf-1202.

What changes

On a dedicated Ascend 950 Prefill worker, fused_op_provider="deepgemm" lets DeepGEMM-Ascend dispatch tokens to their routed experts, run the expert FFN and combine the outputs in one device path. Shared experts keep their existing SGLang path. The default fused-op provider is cann.

The dispatcher reuses the existing TP device communicator after checking that TP and EP have the same ranks in the same order. All eight ranks enter MegaMoE, including a rank with zero local rows. The group shares one symmetric workspace across layers, sized from the resolved Prefill budget. This version supports single-node TP8, attention DP8, EP8, static placement and synchronous eager Prefill with speculative decoding disabled.

The loader packs MXFP4 expert weights and E8M0 scales once. The worker keeps one layout and must restart for a weight replacement. Argument resolution rejects FP8 experts and FP4-to-FP8 dequantization.

Eight-card offline prototype

The prototype measured +21.8% new-input throughput at one point on the Prefill curve. The PR head still needs a fixed-seed eight-card comparison. The table reports the prototype on DeepSeek-V4.1-Flash, eight Ascend 950DT cards, CANN 9.3.0-beta.1 and torch-npu 2.13.0.

Metric AscendOps AllGather DeepGEMM prototype
Non-cached input throughput (tokens/s/NPU) 13,035.87 15,872.72
Mean common Prefill step (ms) 314.230 258.091
Offline first-token latency P50 (ms) 313.958 257.830
Completed requests 80/80 80/80

Each request had 131,072 input tokens, with 126,976 cached and 4,096 newly computed. Each arm timed 10 steps across eight ranks, for 327,680 new input tokens. Per-NPU throughput divides that count by the common elapsed time and by eight. Both arms used real routing, 384 routed experts and 32 static replicas with trivial placement. The prototype recorded 3,200 provider calls across 40 routed layers.

The prototype used DeepGEMM-Ascend fd5d22d plus a patch that rounds at the SwiGLU boundary in BF16 and applies routing weights after the down projection. The reproduction kit identifies that patch as late-weight-dense.patch, SHA-256 82b428684f3c5370f576f6fbfb83cbb6645a33923886088d79a61591954d53ea. Record the vendor build along with the SGLang revision when comparing results. DeepGEMM-Ascend base revision

Accuracy evidence

Offline comparison Matching first output tokens Matching held-out logit argmax
AllGather vs. DeepGEMM prototype 64/80 30/32
AllGather vs. AllGather repeat 69/80 30/32

The AllGather and DeepGEMM prototype arms had identical token inputs but different engine seeds (184205489 and 993405340, respectively). The repeat also shows baseline variation. These runs leave the contribution of the provider to the observed differences unresolved.

A separate operator diagnostic matched AllToAllV's scale_alg=1 and found bitwise agreement on the first matched-input call at each of 40 layers across eight ranks. The provider in this PR passes scale_alg=None. The fixed-seed AllGather comparison in the benchmark PR #43 exercises that path.

Reproduction

The benchmark PR #43 contains the CANN 9.3.0 setup, vendor patches, offline sweep and fixed-seed AllGather / DeepGEMM / AllGather commands.

Validation status

  • Provider CPU tests and local lint. The CPU tests cover opt-in and startup guards, packed weights, live rows and ignored routes. The dispatcher test checks TP group reuse and rejects a different rank order.
  • Run the PR implementation on eight cards with the pinned vendor build and attach the fixed-seed AllGather / DeepGEMM / AllGather accuracy and throughput results.
python -m pytest -q test/registered/unit/moe/test_ascend_deepgemm_prefill.py \
  test/registered/unit/moe/test_ascend_ops.py::TestAscendOpsDispatcherContracts::test_deepgemm_reuses_the_ordered_tp_group_on_idle_ranks

AkiYangDev and others added 10 commits December 3, 2026 15:33
- aclnnGemmSyrkGetWorkspaceSize grew an int8_t cubeMathType argument
  between 9.3.0-beta.1 and the 9.3.0 release; apply the call-site
  adaptation to the DeepGEMM worktree as cann93-release-syrk.patch.
- Record the patched-file digests in their Linux line-ending view and
  cover csrc/apis/aclnn.hpp as well; the previous digests were taken
  from a CRLF checkout and never matched a Linux prepare.
- Prebuild the cann_ops_transformer ops and the triton Ascend
  npu_utils host extension during prepare with the default toolchain
  headers: their g++-13 -std=c++20 builds fail at runtime against the
  GCC 11 include path kept for the device JIT.
Validated on 141.61.45.121, CANN 9.3.0 release, 8 x Ascend950DT:
offline 4096 finished=80, new_tokens=327680, measured_steps=10.

- Drop CPLUS_INCLUDE_PATH from the run-time vendor environment: the
  device JIT has not needed the GCC 11 headers on the 9.3.0 release,
  while they break the cann_ops_transformer ops and the triton Ascend
  npu_utils host builds (g++-13 -std=c++20). Opt back in with
  DEVICE_JIT_GCC11=1.
- Prepend the pip site-packages in vendor_env so the pinned pip
  cannbot-dsl 0.8.0 (tensor.reinterpret) shadows the cannbotdsl bundled
  with the host CANN release.
- Extend the adapter's mHC runtime gate to the 9.3.0 release after
  extraction; the beta.1 pilot kernel runs on it.
- Add run_all.sh: one-click offline tiers and the native vs DeepGEMM
  serve comparison with readiness polling and short smoke mode.
- runtime_libraries preloads the system libstdc++: the hcc toolchain
  dir first in LD_LIBRARY_PATH shadows it with a build missing the
  GLIBCXX_3.4.29 futex symbols, and mooncake (the default PD transfer
  backend) fails to import in the serve arm.
- run_all.sh wait_ready exits as soon as the server process dies
  instead of polling for the full 40 minutes.
Drop the defensive layers: model-path candidate scanning, precondition
re-checks, and duplicate idle checking (repro.sh already fails loudly on
all of those). Keep the one-line defaults, the readiness poll that dies
with the server, the SHORT smoke flag, and the per-tier summary print.
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.

1 participant