Skip to content

[XPU][OP] Add build_sampling_params kernel for MTP speculative decoding#8032

Merged
hong19860320 merged 4 commits into
PaddlePaddle:developfrom
Clarity256:feature/xpu-build-sampling-params-kernel
Jun 17, 2026
Merged

[XPU][OP] Add build_sampling_params kernel for MTP speculative decoding#8032
hong19860320 merged 4 commits into
PaddlePaddle:developfrom
Clarity256:feature/xpu-build-sampling-params-kernel

Conversation

@Clarity256

@Clarity256 Clarity256 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Motivation

在 XPU MTP 投机解码启用 CUDAGraph 的过程中,原有的 padding_sampling_params(Python 侧 CPU 实现)会产生 host-device 同步,无法被 CUDAGraph 捕获。本 PR 新增 build_sampling_params XPU 自定义算子,将 sampling 参数(top_p, top_k, topp_seed)的构造和 infer_seed 的原地更新完全在 device 端完成,为后续 CUDAGraph capture 扫清障碍。

Modifications

  • custom_ops/xpu_ops/src/ops/mtp/build_sampling_params.cc:新增 Paddle 自定义算子入口,注册 build_sampling_params op。
  • custom_ops/xpu_ops/src/plugin/include/xpu/plugin.h:声明 build_sampling_params C 接口。
  • custom_ops/xpu_ops/src/plugin/src/kernel/kunlun3cpp/mtp_kernel/build_sampling_params.xpu:新增 XPU3 kernel 实现。
  • custom_ops/xpu_ops/src/plugin/src/wrapper/mtp_wrapper/build_sampling_params.cpp:新增 CPU wrapper 和 XPU3 wrapper。
  • custom_ops/xpu_ops/test/test_build_sampling_params.py:新增单元测试,覆盖纯 decoder、纯 encoder、混合、单条、seed wrap-around 等场景。

Usage or Command

cd custom_ops/xpu_ops/test && python test_build_sampling_params.py

Accuracy Tests

单元测试对比 Python reference 实现(原 padding_sampling_params 逻辑),全部 case 通过。

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.

Add a new XPU custom operator `build_sampling_params` that constructs
sampling parameters (top_p, top_k, topp_seed) on device for MTP
speculative decoding verification. This replaces the previous Python-level
`padding_sampling_params` approach with a more efficient XPU kernel
implementation that supports CudaGraph capture.

Key components:
- XPU kernel implementation (build_sampling_params.xpu)
- C++ wrapper and op registration
- Plugin header declaration
- Unit tests with comprehensive coverage
@codecov-commenter

codecov-commenter commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@4ba6625). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #8032   +/-   ##
==========================================
  Coverage           ?   67.79%           
==========================================
  Files              ?      475           
  Lines              ?    66657           
  Branches           ?    10283           
==========================================
  Hits               ?    45191           
  Misses             ?    18575           
  Partials           ?     2891           
Flag Coverage Δ
GPU 77.82% <ø> (?)
XPU 6.98% <ø> (?)

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

This comment was marked as outdated.

@PaddlePaddle-bot

PaddlePaddle-bot commented Jun 11, 2026

Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-06-16 10:50:40 UTC+08:00

CI报告基于以下代码生成(30分钟更新一次):
PR commit: 4b9287f | Merge base: 4ba6625 (branch: develop)


1 Required任务 : 8/10 通过

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
59(17) 42 37 4 1 0 0
任务 错误类型 置信度 日志
Approval 需要 Approval Job

2 失败详情

🔴 Approval — 需要 Approval(置信度: 高)

根因摘要:该 Job 需要人工 Approval,完成审批后 CI 才会继续执行。

修复建议摘要:请通过人工审批。

Align the per-position seed offset stride with the Python
padding_sampling_params implementation it replaces: XPU requires a
stride of 32 (not 4) so that the generated topp_seed sequence matches
the original reference. Update both the kernel and CPU wrapper, and the
unit test reference accordingly.
PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@zhupengyang zhupengyang left a comment

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.

LGTM

@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-15 14:53:46

📋 Review 摘要

PR 概述:新增 XPU build_sampling_params 自定义算子,用于在设备端构造采样参数并更新 infer_seed
变更范围custom_ops/xpu_ops 的 op 注册、plugin 接口、XPU3 kernel 和单测。
影响面 Tag[OP] [XPU] [Speculative Decoding]

问题

级别 文件 概述
🔴 Bug custom_ops/xpu_ops/src/ops/mtp/build_sampling_params.cc:97 infer_seed 被算子写回,但注册未声明这个原地更新关系

历史 Findings 修复情况

Finding 问题 状态
F1 新增 op 目前没有接入实际 XPU sampler 路径。 ⚠️ 仍存在

📝 PR 规范检查

标题包含 [XPU][OP] 两个 Tag;FastDeploy 规范要求标题必须且仅包含一个官方 Tag。描述结构符合模板。

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

  • [XPU] Add build_sampling_params kernel for MTP speculative decoding

总体评价

新增算子的构建收录和基础测试覆盖方向是合理的,但目前注册层没有暴露 infer_seed 的写回语义,会影响图依赖与 CUDAGraph capture 的正确性,需要先修复后再合入。

Comment thread custom_ops/xpu_ops/src/ops/mtp/build_sampling_params.cc

@yongqiangma yongqiangma left a comment

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.

LGTM

@hong19860320 hong19860320 left a comment

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.

LGTM

@hong19860320
hong19860320 merged commit 74a363e into PaddlePaddle:develop Jun 17, 2026
56 of 61 checks passed
@paddle-bot

paddle-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants