Skip to content

[Cherry-Pick][RL] Support moe_topk_select using Paddle native operators and Add fused stack-transpose-quant for BlockWiseFP8 MoE weight quantization and swiglu-fp8-quant op for DeepGemmFusedMoE for training alignment (#6850) - #6935

Merged
zoooo0820 merged 16 commits into
PaddlePaddle:release/2.5from
DanielSun11:topk_cp_2.5
Mar 24, 2026

Conversation

@DanielSun11

Copy link
Copy Markdown
Contributor

Motivation

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

Modifications

Usage or Command

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.

Copilot AI review requested due to automatic review settings March 19, 2026 08:35
@paddle-bot

paddle-bot Bot commented Mar 19, 2026

Copy link
Copy Markdown

Thanks for your contribution!

Copilot AI 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.

Pull request overview

该 PR 主要围绕 MoE 的 TopK 选择与 FP8(含 UE8M0 scale)量化路径做增强:在 DeepGemmFusedMoE 侧引入基于 Paddle 原生算子的 moe_topk_select 选择逻辑,并新增/对齐 Fleet 侧的 fused 算子接入(stack+transpose+fp8 quant、以及带 routed prob 的 fused swiglu+fp8 quant),同时补充对应单测与环境开关。

Changes:

  • 在 DeepGemm MoE 路径新增 moe_topk_select(Paddle native)并通过 FD_USE_PHI_TOPK 控制启用。
  • 新增 fp8_utils.fused_stack_transpose_quant 并在 Triton MoE 的 UE8M0 量化权重处理里通过 FD_USE_FLEET_FP8_QUANT 切到 Fleet fused kernel。
  • 新增 FD_MOE_PROB_IN_ADVANCE/FD_USE_FLEET_FP8_QUANT/FD_USE_PHI_TOPK 环境变量,并补充 deepgemm/fused-quant 相关测试用例。

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/operators/test_noaux_tc_redundant.py 增加基于 moe_topk_select 的 group-topk 对齐测试
tests/layers/test_fp8_ue8m0.py 增加 Fleet fused stack+transpose+quant 及 fused_stack_transpose_quant 的单测覆盖
tests/layers/test_deepgemm_fused_moe.py 新增 DeepGemmFusedMoE 多路径(TP/EP、prob-in-advance、phi permute 等)对齐测试
fastdeploy/model_executor/layers/quantization/fp8_utils.py 新增 try_importpaddlefleet_ops 引入与 fused_stack_transpose_quant 等量化辅助能力
fastdeploy/model_executor/layers/moe/fused_moe_triton_backend.py UE8M0 权重量化新增 Fleet fused 路径(chunk 化处理)
fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py 引入 moe_topk_selectFD_MOE_PROB_IN_ADVANCE 下的 fused swiglu+fp8 quant 路径,并调整 unpermute combine 开关
fastdeploy/envs.py 新增 MoE TopK/Fleet FP8 quant/prob-in-advance 等环境变量开关

Comment thread tests/layers/test_fp8_ue8m0.py
Comment thread tests/layers/test_fp8_ue8m0.py
Comment thread tests/layers/test_deepgemm_fused_moe.py
Comment thread fastdeploy/model_executor/layers/quantization/fp8_utils.py Outdated
Comment thread fastdeploy/model_executor/layers/quantization/fp8_utils.py Outdated
Comment thread fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py
Comment thread fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py
Comment thread fastdeploy/model_executor/layers/moe/fused_moe_triton_backend.py
Comment thread tests/layers/test_deepgemm_fused_moe.py
@codecov-commenter

codecov-commenter commented Mar 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.68421% with 25 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.5@d585b22). Learn more about missing BASE report.

Files with missing lines Patch % Lines
..._executor/layers/moe/fused_moe_deepgemm_backend.py 64.44% 9 Missing and 7 partials ⚠️
...oy/model_executor/layers/quantization/fp8_utils.py 65.38% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.5    #6935   +/-   ##
==============================================
  Coverage               ?   69.18%           
==============================================
  Files                  ?      389           
  Lines                  ?    53474           
  Branches               ?     8394           
==============================================
  Hits                   ?    36995           
  Misses                 ?    13812           
  Partials               ?     2667           
Flag Coverage Δ
GPU 69.18% <73.68%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

Copilot AI review requested due to automatic review settings March 23, 2026 05:13

Copilot AI 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.

Pull request overview

该 PR(Cherry-pick)主要围绕 MoE 路由与 FP8 权重量化路径做增强:一方面在 DeepGemm MoE 中新增基于 Paddle 原生算子的 moe_topk_select(用于 noaux_tc 训练对齐),另一方面引入 Fleet 的 fused stack-transpose-fp8-quant / fused weighted swiglu-fp8-quant 相关能力,并补充/扩展对应单测覆盖。

Changes:

  • 新增 moe_topk_select(Paddle 原生算子实现)并在 DeepGemm MoE 的 TP/EP prefill 路径按开关启用
  • 在 BlockWiseFP8 MoE 权重量化中接入 fused_stack_transpose_quant(支持按 chunk 处理专家权重)
  • 增加/扩展多份测试文件以覆盖 Triton/DeepGemm/ue8m0 分支与 fused quant 行为

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/operators/test_noaux_tc_redundant.py 新增用例对比 moe_topk_select 与参考实现的一致性
tests/layers/test_fused_moe_triton_backend.py 新增 Triton MoE backend 的大量单测(mock/patch 覆盖多分支)
tests/layers/test_fp8_ue8m0.py 扩展 ue8m0 与 fused_stack_transpose_quant 等分支的测试覆盖
tests/layers/test_deepgemm_fused_moe.py 新增 DeepGemmFusedMoE 训练对齐相关路径的测试(含 EP/TP 分支)
fastdeploy/model_executor/layers/quantization/fp8_utils.py 增加 try_importpaddlefleet_ops 探测与 fused_stack_transpose_quant 封装
fastdeploy/model_executor/layers/moe/fused_moe_triton_backend.py BlockWiseFP8 MoE 动态量化 ue8m0 分支中接入 fused stack-transpose-quant
fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py 新增 moe_topk_select 并引入 prob-in-advance + fused swiglu-fp8-quant 的分支
fastdeploy/envs.py 新增/调整若干 env 开关(MoE TopK / prob-in-advance 等)

Comment thread fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py
Comment thread fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py
Comment thread fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py
Comment thread fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py
Comment thread fastdeploy/envs.py Outdated
Comment thread fastdeploy/envs.py
Comment thread tests/operators/test_noaux_tc_redundant.py
Comment thread tests/layers/test_deepgemm_fused_moe.py
Comment thread fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py
Comment thread fastdeploy/envs.py Outdated
# Whether to use phi MOE permute,if 1,use paddle op.
"FD_USE_PHI_MOE_PERMUTE": lambda: bool(int(os.getenv("FD_USE_PHI_MOE_PERMUTE", "0"))),
# Whether to use phi TopK, when need select moe by noaux_tc method if 1,use paddle default.
"FD_USE_PHI_TOPK": lambda: bool(int(os.getenv("FD_USE_PHI_TOPK", "0"))),

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.

这里是不是合并代码的时候漏了,同时加了2个topk环境变量

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

解决conflict的时候漏删掉了。现在已经删掉了

@zoooo0820
zoooo0820 merged commit 370db86 into PaddlePaddle:release/2.5 Mar 24, 2026
20 of 27 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.

7 participants