Skip to content

[Cherry-Pick][Optimization]Kernel fusion: cast+sigmoid+bias+noauxtc(#7777)#7782

Open
ShaneGZhu wants to merge 3 commits into
PaddlePaddle:release/2.6from
ShaneGZhu:cp26_noauxtc
Open

[Cherry-Pick][Optimization]Kernel fusion: cast+sigmoid+bias+noauxtc(#7777)#7782
ShaneGZhu wants to merge 3 commits into
PaddlePaddle:release/2.6from
ShaneGZhu:cp26_noauxtc

Conversation

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

BingooYang and others added 3 commits May 12, 2026 10:56
* conflict

* support more cast type

* modify test

* add type check

* fix config issues

* enable more backend

* modify 2025->2026

* only support gpu backend and fix test issues

* support gpu backend

* modify format

* modify except type

* conflict fix

* format

* fix dynamic_load_weight config issues

* fix dynamic_load_weight config issue

* fix fake get_moe_scores config issues

* add mock test

* modify RL control env

* Modify code standardization

* fix test issue

* fix test issue

* fix conflict issue

* fix mockdata config issue

* enhance test converage

* fix test
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 12, 2026

Thanks for your contribution!

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

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-05-12 11:39:28

📋 Review 摘要

PR 概述:为 MoE 模型(如 DeepSeek-V3)实现 cast+sigmoid+bias+noaux_tc 融合内核优化,减少显存带宽消耗和 kernel 启动开销
变更范围custom_ops/gpu_ops/fastdeploy/model_executor/layers/moe/
影响面 Tag[OP]


📝 PR 规范检查

标题格式基本符合 Cherry-Pick 规范,但 [Optimization] 与描述之间缺少空格(当前:[Cherry-Pick][Optimization]Kernel,应为 [Cherry-Pick][Optimization] Kernel)。PR 描述所有段落均为空,仅保留了模板注释占位符,需补全。

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

  • [Cherry-Pick][Optimization] Kernel fusion: cast+sigmoid+bias+noauxtc(#7777)

PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):

## Motivation
为 MoE 模型(如 DeepSeek-V3)的 gate 路由实现内核融合优化,将 cast+sigmoid+bias+grouped_topk(noaux_tc)融合为单个 GPU kernel `grouped_topk`,减少显存带宽消耗和 kernel 启动开销;同时提供独立的 `fused_cast_sigmoid_bias` 算子供仅执行 cast+sigmoid+bias 的场景使用。Cherry-pick 自 #7777## Modifications
- `custom_ops/gpu_ops/grouped_topk_kernels.cu`:新增融合 CUDA kernel,将 cast+sigmoid+bias+grouped topk (noaux_tc) 合并为单 kernel
- `custom_ops/gpu_ops/fused_cast_sigmoid_bias.cu`:新增融合 CUDA kernel,执行 cast+sigmoid+bias
- `custom_ops/gpu_ops/cpp_extensions.cc`:注册 `grouped_topk``fused_cast_sigmoid_bias` 的 pybind11 绑定
- `custom_ops/setup_ops.py`:将两个新 `.cu` 文件加入编译列表(GPU 编译的两处位置)
- `fastdeploy/model_executor/layers/moe/fused_cast_sigmoid_bias.py`:新增 Python 封装模块
- `fastdeploy/model_executor/layers/moe/moe.py``get_moe_scores` 新增 `use_fused_cast` 参数,支持走融合 kernel 路径(`grouped_topk`- `fused_moe_cutlass_backend.py``fused_moe_deepgemm_backend.py``fused_moe_triton_backend.py`:在 CUDA + 非 RL 模式下自动启用融合内核
- 新增单测:`tests/layers/test_fused_cast_sigmoid_bias.py``tests/layers/test_deepgemm_fused_moe.py``tests/layers/test_fused_moe_cutlass_backend.py``tests/layers/test_fused_moe_triton_backend.py``tests/operators/test_grouped_topk_op.py`

## Usage or Command
N/A

## Accuracy Tests
N/A

## 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.
- [x] 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.

问题

级别 文件 概述
📝 PR 规范 PR 描述 所有段落均为空,仅保留模板注释
🟡 建议 fastdeploy/model_executor/layers/moe/moe.py:50 死代码块 if current_platform.is_cuda(): pass 应删除

总体评价

融合内核设计合理,grouped_topk 将 cast+sigmoid+bias+noaux_tc 四步合并为单 kernel,正确处理了 float32 中间精度保证与边界情况;编译注册、Python 调用侧、单测均已同步添加。主要问题是 PR 描述段落为空以及 moe.py 中残留的死代码块(if current_platform.is_cuda(): pass),建议修复后合入。

import numpy as np

if current_platform.is_cuda():
pass
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 死代码块,应删除

if current_platform.is_cuda(): pass 是一个空操作块,对运行时没有任何效果。疑似在重构过程中遗留,未在 body 内填入实际逻辑(例如条件导入 fused_cast_sigmoid_bias)。

建议直接删除这两行:

# 删除以下两行:
if current_platform.is_cuda():
    pass

@PaddlePaddle-bot
Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-12 11:51:15

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

CI 仍有任务运行中:1 个 required 任务失败(Approval),6 个 required 任务运行中,需等待完成后评估。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
35(0) 35 24 4 6 1 0

2 任务状态汇总

2.1 Required任务 : 3/10 通过

必选任务阻塞合并,失败需优先处理。

状态 任务 耗时 根因 修复建议 日志 重跑
Approval 9s PR问题:缺少自定义OP所需的 RD 双重审批 请 FastDeploy RD 和 PaddlePaddle RD 各自 Approve Job -
run_ce_cases - 运行中 - Job -
base_tests - 运行中 - Job -
run_tests_with_coverage - 运行中 - Job -
run_4_cards_tests - 运行中 - Job -
run_xpu_4cards_cases - 运行中 - Job -
run_xpu_8cards_cases - 运行中 - Job -
其余 3 个必选任务通过 - - - - -

2.2 可选任务 — 21/25 通过

可选任务不阻塞合并,失败仅供参考。

状态 任务 耗时 日志 重跑
Run iluvatar Tests / run_iluvatar_cases 13m43s Job -
Check PR Template 14s Job -
Trigger Jenkins for PR 1m25s Job -
⏸️ CI_HPU - - -
其余 21 个可选任务通过 - - -

3 失败详情(仅 required)

Approval — 审批流程(置信度: 高)

Approval

  • 状态: ❌ 失败
  • 错误类型: 审批流程
  • 置信度: 高
  • 根因摘要: PR 涉及自定义 OP 变更,缺少必要的 RD 双重审批
  • 分析器: 通用分析(fallback)

根因详情:
CI 审批脚本(scripts/check_approval.sh)检测到本 PR 涉及自定义 OP(custom op)变更,需同时满足两项审批要求:1) FastDeploy RD(qingqing01/Jiang-Jia-Jun/heavengate 之一)批准;2) PaddlePaddle RD(jeff41404/yongqiangma 之一)批准。当前两项审批均缺失,退出码 6 表示存在 2 个审批错误。

关键日志:

0. You must have one FastDeploy RD (qingqing01(dangqingqing), Jiang-Jia-Jun(jiangjiajun), heavengate(dengkaipeng)) approval for adding custom op.
1. You must have one PaddlePaddle RD (jeff41404(gaoxiang), yongqiangma(mayongqiang)) approval for adding custom op.
There are 2 approved errors.
##[error]Process completed with exit code 6.

修复建议:

  1. 请 FastDeploy RD(qingqing01 / Jiang-Jia-Jun / heavengate 之一)在本 PR 上进行 Approve
  2. 请 PaddlePaddle RD(jeff41404 / yongqiangma 之一)在本 PR 上进行 Approve

修复建议摘要: 请 FastDeploy RD 和 PaddlePaddle RD 各自在 PR 上 Approve

链接: 查看日志

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.80488% with 5 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.6@a5191f2). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...l_executor/layers/moe/fused_moe_cutlass_backend.py 50.00% 2 Missing and 2 partials ⚠️
fastdeploy/model_executor/layers/moe/moe.py 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.6    #7782   +/-   ##
==============================================
  Coverage               ?   71.89%           
==============================================
  Files                  ?      379           
  Lines                  ?    53967           
  Branches               ?     8442           
==============================================
  Hits                   ?    38801           
  Misses                 ?    12396           
  Partials               ?     2770           
Flag Coverage Δ
GPU 71.89% <87.80%> (?)

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.

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.

4 participants