[Cherry-Pick] [Optimization] TopP=1.0 using _random_sample (#7892) and Triton SamplerBackend (#7639)#7910
[Cherry-Pick] [Optimization] TopP=1.0 using _random_sample (#7892) and Triton SamplerBackend (#7639)#7910ckl117 wants to merge 7 commits into
Conversation
|
Thanks for your contribution! |
CI报告基于以下代码生成(30分钟更新一次): 1 任务总览当前 required 任务未全部通过,建议暂不通过。required 失败任务数 2,等待处理的 required 任务数 0(运行中 0、等待中 0)。主要阻塞项为单测覆盖率门禁失败与 Approval 待人工审批。
2 任务状态汇总日志列说明:失败任务直接使用日志链接;运行中任务使用 Job 链接。 2.1 Required任务 : 8/10 通过
2.2 可选任务 — 23/27 通过
3 失败详情(仅 required)Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage — 覆盖率门禁(置信度: 高)Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage
失败用例: 无。日志显示 根因详情: 关键日志: 修复建议:
修复建议摘要: 补充采样/Triton覆盖或豁免JIT内核 关联变更: 链接: 查看日志 Approval — 需要人工审批(置信度: 高)该 Job 需要人工 Approval,完成审批后 CI 才会继续执行。 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release/2.6 #7910 +/- ##
==============================================
Coverage ? 71.83%
==============================================
Files ? 383
Lines ? 55071
Branches ? 8620
==============================================
Hits ? 39560
Misses ? 12732
Partials ? 2779
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-25 16:44:39
📋 Review 摘要
PR 概述:Cherry-Pick 两项采样优化——新增 Triton 采样后端和 top_p=1.0 快速路径优化
变更范围:model_executor/layers/sample/、worker/gpu_model_runner.py、envs.py
影响面 Tag:[OP] [Optimization]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | meta_data.py:46 |
top_p_list 使用裸 list 类型,缺乏元素类型注解 |
| ❓ 疑问 | top_k_top_p_sampling.py:108 |
移除 topp_seed CPU→GPU 拷贝,需确认调用侧已保证在 GPU 上 |
| 🟡 建议 | gpu_model_runner.py |
A6:通用路径有改动,请确认是否需同步其他硬件 ModelRunner |
| 📝 PR 规范 | PR 描述 | Modifications、Usage or Command、Accuracy Tests 三节为空 |
📝 PR 规范检查
PR 标题 Cherry-Pick 格式中 [Cherry-Pick] 与 [Optimization] 之间有多余空格(规范为 [Cherry-Pick][Tag] 紧邻),且 Modifications、Usage or Command、Accuracy Tests 三节内容均为空。
标题建议(可直接复制):
[Cherry-Pick][Optimization] TopP=1.0 using _random_sample and Triton SamplerBackend (#7892, #7639)
PR 描述建议(可直接复制):
## Motivation
1. 支持 Triton 采样后端(`FD_SAMPLING_CLASS=triton`),基于 Qrita 算法实现高性能 Top-K + Top-P 联合采样 kernel(#7639)。
2. 优化 top_p=1.0 采样路径,当 `FD_ENABLE_TOP_P_ONE_OPT=1` 时直接走 random_sample 跳过 top-p 过滤,降低 RL 验证场景延迟(#7892)。
3. 新增环境变量 `FD_ENABLE_TOP_P_ONE_OPT`,待 RL 场景验证通过后移除。
## Modifications
- `fastdeploy/model_executor/layers/sample/ops/top_k_top_p_triton.py`:新增 Triton Top-K/Top-P 联合采样 kernel,基于 Qrita 论文 pivot-based 截断算法
- `fastdeploy/model_executor/layers/sample/ops/top_k_top_p_sampling.py`:提取 `dispatch_top_k_renorm_probs` 公共函数,简化 `topp_seed` 传参逻辑
- `fastdeploy/model_executor/layers/sample/sampler.py`:集成 triton 采样后端分支及 top_p=1.0 优化路径
- `fastdeploy/model_executor/layers/sample/meta_data.py`:新增 `top_p_list` 字段供 triton 路径使用
- `fastdeploy/worker/gpu_model_runner.py` / `input_batch.py`:透传 top_p_list 至采样层
- `fastdeploy/envs.py`:新增 `FD_ENABLE_TOP_P_ONE_OPT` 环境变量
- `tests/layers/test_triton_sampler.py`:新增 triton 采样算子单测
## Usage or Command
```bash
# 启用 Triton 采样后端
FD_SAMPLING_CLASS=triton python -m fastdeploy.entrypoints.openai.api_server ...
# 启用 top_p=1.0 优化(RL 验证场景)
FD_ENABLE_TOP_P_ONE_OPT=1 python -m fastdeploy.entrypoints.openai.api_server ...
```
## Accuracy Tests
N/A(采样输出为随机分布,无确定性精度对比;triton 后端与 base 后端的分布等价性由 `tests/layers/test_triton_sampler.py` 覆盖)
## 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.
- [x] 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.总体评价
整体代码结构清晰,Triton kernel 实现参考了 Qrita 论文,逻辑完整;dispatch_top_k_renorm_probs 的提取也改善了代码复用。建议确认 topp_seed device 保证和多硬件同步情况后即可合入。
|
|
||
| top_p: paddle.Tensor | ||
| top_p_list: Optional[list] = None | ||
| # only GPU used |
There was a problem hiding this comment.
🟡 建议 top_p_list 字段使用裸 list 类型注解,与相邻字段(top_p: paddle.Tensor)风格不一致,且缺乏元素类型信息,IDE 和类型检查工具无法推导元素类型。
建议修改为:
top_p_list: Optional[List[float]] = None(同时在文件顶部 import List 若尚未导入)
| topp_seed_device = paddle.empty(shape=topp_seed.shape, dtype=topp_seed.dtype) | ||
| topp_seed_device.copy_(topp_seed, False) | ||
| _, ids = paddle.tensor.top_p_sampling( | ||
| x, |
There was a problem hiding this comment.
❓ 疑问 原代码明确将 topp_seed 从 CPU 拷贝到 GPU(paddle.empty(...).copy_(topp_seed, False))再传入 paddle.tensor.top_p_sampling,此处直接将原始 topp_seed 传入。
若 topp_seed 在调用侧已保证在 GPU 上,此简化正确;但若仍可能在 CPU 上(如从 input_batch CPU 侧构造),则会导致运行时 device mismatch 错误。
请确认 topp_seed 的来源保证在 GPU 上,或添加注释说明。
Motivation
支持triton采样后端 #7639
优化top_p=1.0采样 #7892
新增环境变量
FD_ENABLE_TOP_P_ONE_OPT=1,方便RL验证,待验证通过后删掉环境变量。Modifications
Usage or Command
Accuracy Tests
Checklist
[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]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.