[Optimization] add warmup for _sample_from_probs#7956
Conversation
|
Thanks for your contribution! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7956 +/- ##
==========================================
Coverage ? 67.60%
==========================================
Files ? 467
Lines ? 65194
Branches ? 10009
==========================================
Hits ? 44072
Misses ? 18301
Partials ? 2821
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:
|
CI报告基于以下代码生成(30分钟更新一次): 1 任务总览所有 Required 任务均已通过,建议合并。
2 任务状态汇总2.1 Required任务 : 10/10 通过
2.2 可选任务 — 28/32 通过
3 失败详情(仅 required)无 required 失败任务。 |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-31 13:03:15
📋 Review 摘要
PR 概述:在 dummy_run/profile_run 阶段同时预热 _random_sample 和 top_k_top_p_sampling 两条采样路径,避免真实请求 top_p≠1.0 时首次触发慢路径导致性能下降。
变更范围:model_executor/layers/sample/、worker/gpu_model_runner.py
影响面 Tag:[OP] [Optimization]
问题
未发现阻塞性问题。
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | 利用 bool + 1 控制循环次数的实现方式可读性差 |
✅ 已修复 |
| F2 | need_top_k_sampling=True 时 probs 在首次迭代被覆盖,warmup 第二次迭代收到已 renorm 的 probs |
|
| F3 | 其他硬件 model runner 是否需要同步传递 is_dummy_or_profile_run? |
F1 说明:当前实现已改为简洁的 if sampling_metadata.is_dummy_or_profile_run 分支,可读性良好。
F2 说明:当 need_top_k_sampling=True 时,probs 已被 dispatch_top_k_renorm_probs 修改后再传入 top_k_top_p_sampling 进行 warmup。由于 warmup 阶段结果不参与实际推理,功能无影响,但 warmup 路径与真实执行路径输入不完全一致(真实 top_p≠1.0 请求收到的是原始 probs)。建议后续优化时考虑保存原始 probs 副本用于 warmup 调用。
F3 说明:确认 metax_model_runner.py 的 _prepare_inputs 已接收 is_dummy_or_profile_run 参数但未传递给 SamplingMetadata。由于 sampler 中 warmup 逻辑被 current_platform.is_cuda() 门控,非 CUDA 平台(xpu/gcu/hpu)不受影响;metax/dcu 如需同等 warmup 效果,需后续同步。
📝 PR 规范检查
Modifications 章节为空,Usage or Command 和 Accuracy Tests 未填写(应填 N/A),Checklist 未勾选。
标题建议(可直接复制):
[Optimization] Add warmup for _sample_from_probs to cover both fast and slow sampling paths
PR 描述建议(点击展开,可直接复制)
## Motivation
背景:PR#7892 非Triton采样后端下top_p=1.0时会执行`_random_sample`采样。
问题:引擎默认的top_p=1.0,在dummy_run阶段只会对`_random_sample`预热,没有预热top_p!=1.0的采样算子,此时真实请求(top_p!=1.0)的性能会有下降。
解决:sampler增加`is_dummy_or_profile_run`字段,默认为False,引擎在dummy_run阶段指定`is_dummy_or_profile_run=True`会同时预热`top_p=1.0`和`top_p!=1.0`采样算子。
## Modifications
- `fastdeploy/model_executor/layers/sample/meta_data.py`:`SamplingMetadata` 新增 `is_dummy_or_profile_run: bool = False` 字段,用于区分 dummy run / profile run
- `fastdeploy/model_executor/layers/sample/sampler.py`:`_sample_from_probs` 函数在 `is_dummy_or_profile_run=True` 时同时执行快慢两条采样路径完成预热
- `fastdeploy/worker/gpu_model_runner.py`:`_prepare_inputs` 中透传 `is_dummy_or_profile_run` 给 `SamplingMetadata`
## Usage or Command
N/A
## Accuracy Tests
N/A(此 PR 不涉及精度变更,仅对 dummy_run/profile_run 阶段增加采样路径预热)
## 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.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [x] 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.总体评价
变更简洁聚焦,通过在 dummy_run 阶段额外调用 top_k_top_p_sampling 实现 warmup,逻辑正确且不影响正式推理路径。建议后续关注 F2(warmup 输入一致性)和 F3(多硬件同步)。
Motivation
背景:PR(#7892 ) 非Trion采样后端下top_p=1.0下会执行
_random_sample采样。问题:引擎默认的top_p=1.0,在dummy_run阶段只会对
_random_sample预热,没有预热top_p!=1.0的采样算子,此时真实请求(top_p!=1.0)的性能轻微下降(~5%)。解决:sampler增加
is_dummy_or_profile_run字段,默认为False,殷勤在dummy_run阶段指定is_dummy_or_profile_run=True会预热top_p=1.0和top_p!=1.0采样算子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.