Skip to content

[Feature] Support MegaMoE (#7943)#8038

Merged
Jiang-Jia-Jun merged 5 commits into
PaddlePaddle:release/online/20260415from
Wanglongzhi2001:release_online_0415
Jun 11, 2026
Merged

[Feature] Support MegaMoE (#7943)#8038
Jiang-Jia-Jun merged 5 commits into
PaddlePaddle:release/online/20260415from
Wanglongzhi2001:release_online_0415

Conversation

@Wanglongzhi2001

@Wanglongzhi2001 Wanglongzhi2001 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Support MegaMoE, cherry-pick from 7943

Modifications

Support MegaMoE

Usage or Command

refer to 7943

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

* [Feature] Support MegaMoE

* update code

* fix code style

* fix code style

* fix test

* fix test

* fix test

* fix test

* fix typo

* fix code style

* fix test

* fix xpu test

* fix test

* fix test

* fix code style

* fix typo

* fix typo
@CLAassistant

CLAassistant commented Jun 11, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Wanglongzhi2001
❌ root


root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter

codecov-commenter commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 18.79433% with 229 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/online/20260415@d4e7e7d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
..._executor/layers/moe/fused_moe_deepgemm_backend.py 8.57% 160 Missing ⚠️
...loy/model_executor/layers/quantization/wfp4afp8.py 36.66% 19 Missing ⚠️
...oy/model_executor/layers/quantization/fp8_utils.py 11.11% 16 Missing ⚠️
...loy/model_executor/layers/quantization/__init__.py 28.57% 9 Missing and 1 partial ⚠️
fastdeploy/model_executor/layers/moe/ep.py 38.46% 8 Missing ⚠️
...el_executor/layers/attention/flash_attn_backend.py 0.00% 4 Missing ⚠️
fastdeploy/__init__.py 50.00% 2 Missing ⚠️
...executor/layers/attention/dsa_attention_backend.py 50.00% 2 Missing ⚠️
...executor/layers/attention/mla_attention_backend.py 50.00% 2 Missing ⚠️
.../layers/batch_invariant_ops/batch_invariant_ops.py 0.00% 2 Missing ⚠️
... and 2 more
Additional details and impacted files
@@                    Coverage Diff                     @@
##             release/online/20260415    #8038   +/-   ##
==========================================================
  Coverage                           ?   72.02%           
==========================================================
  Files                              ?      389           
  Lines                              ?    54428           
  Branches                           ?     8526           
==========================================================
  Hits                               ?    39201           
  Misses                             ?    12519           
  Partials                           ?     2708           
Flag Coverage Δ
GPU 72.02% <18.79%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Paddle-CI-Agent | pr_review | 2026-06-11 15:01:22

📋 Review 摘要

PR 概述:支持 MegaMoE / wfp4afp8 路径,包含新增 pre-dispatch CUDA op、DeepGEMM MegaMoE backend、量化配置和 CLI/worker 透传。
变更范围:custom_ops、MoE/EP backend、quantization、engine/config、相关测试。
影响面 TagOP Quantization FDConfig Engine

问题

级别 文件 概述
🔴 Bug custom_ops/gpu_ops/mega_moe_pre_dispatch.cu:43 warp reduce 使用全掩码,合法小 hidden/非整 warp 输入会触发未定义行为

历史 Findings 修复情况

Finding 问题 状态
F1 MegaMoE 默认 full quant config 与 torch 格式量化解析冲突 ⚠️ 仍存在
F2 apply_mega_moe() 未处理 topk_ids_hookfunc / shared_experts ⚠️ 仍存在

📝 PR 规范检查

标题当前为 [Feature] Support MegaMoE (#7943),目标分支是 release/online/20260415,按仓库 release 分支规则需要使用 [Cherry-Pick] 前缀;PR 描述保留了模板但 Motivation / Modifications / Usage or Command / Accuracy Tests 均为空。

标题建议(可直接复制):

  • [Cherry-Pick][Feature] Support MegaMoE (#7943)
PR 描述建议(点击展开,可直接复制)
## Motivation
Support MegaMoE on Blackwell/SM100 for MoE models on the release/online/20260415 branch, using wfp4afp8 for MoE and block_wise_fp8 for dense Linear layers. This PR is a cherry-pick from #7943.

## Modifications
- Added `--enable-mega-moe` configuration and worker propagation.
- Added the `mega_moe_pre_dispatch` CUDA custom op and operator tests.
- Added `wfp4afp8` quantization config and DeepGEMM MegaMoE backend integration.
- Updated DeepEP/MoE top-k selection calls and safetensors weight iteration ordering.
- Replaced torch-proxy compatibility calls with `paddle.enable_compat`.

## Usage or Command
Use `--enable-mega-moe --enable-expert-parallel` on supported SM100 devices. Full end-to-end launch command: N/A.

## Accuracy Tests
N/A. Accuracy results were not provided in the PR description.

## Checklist

- [x] Add at least a tag in the PR title.
  - Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
  - You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [x] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.

总体评价

核心 MegaMoE 路径仍有一个新增 CUDA op 边界正确性问题;另外两条历史 finding 在当前代码中仍未修复,建议合入前一并处理。

"kNumThreads must be a power of 2");
#pragma unroll
for (int mask = kNumThreads / 2; mask > 0; mask >>= 1) {
value = fmaxf(value, __shfl_xor_sync(0xffffffffu, value, mask, WARP_SIZE));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Bug WarpReduceMax 固定使用全 warp 掩码,但 host 侧 shape 校验允许非整 warp 的合法输入。

num_threads_i64 = hidden_i64 / 8 只检查了 <= 1024>= top_k,因此 group_size=32, hidden=128 会以 16 个线程启动一个 block。此时 __shfl_xor_sync(0xffffffffu, ..., WARP_SIZE) 把未参与的 lane 也放进同步掩码,结果是未定义的,可能导致 scale 错误或 kernel hang;现有单测只覆盖了 hidden_size=7168 这种整 warp 情况。

建议修复方式:在 WarpReduceMax 内使用 active mask 并按 kNumThreads 分组,例如 const unsigned m = __activemask(); __shfl_xor_sync(m, value, offset, kNumThreads);或者在 host 侧显式拒绝 num_threads_i64 % WARP_SIZE != 0,并补充 group_size=32, hidden=128 的算子测试。

@Jiang-Jia-Jun
Jiang-Jia-Jun merged commit 9f2f09d into PaddlePaddle:release/online/20260415 Jun 11, 2026
19 of 21 checks passed
@paddle-bot

paddle-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

Thanks for your contribution!

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.

6 participants