Skip to content

[Optimization] add warmup for _sample_from_probs#7956

Open
ckl117 wants to merge 3 commits into
PaddlePaddle:developfrom
ckl117:dev_sampler_warmup
Open

[Optimization] add warmup for _sample_from_probs#7956
ckl117 wants to merge 3 commits into
PaddlePaddle:developfrom
ckl117:dev_sampler_warmup

Conversation

@ckl117
Copy link
Copy Markdown
Collaborator

@ckl117 ckl117 commented May 29, 2026

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.0top_p!=1.0采样算子

💡 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.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 29, 2026

Thanks for your contribution!

PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 29, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7956   +/-   ##
==========================================
  Coverage           ?   67.60%           
==========================================
  Files              ?      467           
  Lines              ?    65194           
  Branches           ?    10009           
==========================================
  Hits               ?    44072           
  Misses             ?    18301           
  Partials           ?     2821           
Flag Coverage Δ
GPU 77.85% <100.00%> (?)
XPU 7.08% <0.00%> (?)

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.

@PaddlePaddle-bot
Copy link
Copy Markdown

PaddlePaddle-bot commented May 29, 2026

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-31 15:06:28

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


1 任务总览

所有 Required 任务均已通过,建议合并。

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

2 任务状态汇总

2.1 Required任务 : 10/10 通过

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

状态 任务 耗时 根因 修复建议 日志 重跑
其余 10 个必选任务通过 - - - - -

2.2 可选任务 — 28/32 通过

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

状态 任务 耗时 日志 重跑
Run iluvatar Tests / run_iluvatar_cases 15m28s Job -
Check PR Template 21s Job -
CI_HPU 1h4m Job -
Trigger Jenkins for PR 17s Job -
其余 28 个可选任务通过 - - -

3 失败详情(仅 required)

无 required 失败任务。

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-31 13:03:15

📋 Review 摘要

PR 概述:在 dummy_run/profile_run 阶段同时预热 _random_sampletop_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=Trueprobs 在首次迭代被覆盖,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 CommandAccuracy 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(多硬件同步)。

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.

3 participants