Skip to content

[Optimization] Reduce preemption occurrence when blocks not enough - #5696

Merged
Jiang-Jia-Jun merged 8 commits into
PaddlePaddle:developfrom
rainyfly:optimize_scheduler_for_preemption
Jan 7, 2026
Merged

Jiang-Jia-Jun merged 8 commits into
PaddlePaddle:developfrom
rainyfly:optimize_scheduler_for_preemption

Conversation

@rainyfly

@rainyfly rainyfly commented Dec 23, 2025

Copy link
Copy Markdown
Collaborator

Motivation

当解码 block不足时,调度会抢占正在解码的请求,释放对应的 block 资源。并分配给剩余的解码请求。
之前的调度逻辑,在 waiting 队列里有请求的时候,发现剩余的 block可以容纳下一条新请求部分的 chunk(new_token_num),就会将其调度回去做 prefill。在 block已经严重不足的时候,会造成反复 抢占->调度 prefill->抢占->调度 prefill的重调度行为,造成性能下降。
为了解决这一问题,在调度新请求做 prefill 时,考虑给正在解码的请求预留部分 block,只有在给正在解码的 每条请求所预留的 block剔除后,并且剩余的 block 还可以容纳整条当前需要 prefill 的请求,才把请求从 waiting 队列里调度出来做 prefill。

Modifications

新增环境变量:FD_RESERVE_OUTPUT_BLOCK_NUM_FOR_DECODE_WHEN_SCHEDULE_NEW_PREFILL
含义:从 waiting 队列里调度新请求做 prefill 时,需要给每条正在解码的请求预留的 block 数量,默认为 16

Usage or Command

None

Accuracy Tests

None

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.

Copilot AI review requested due to automatic review settings December 23, 2025 04:13
@paddle-bot

paddle-bot Bot commented Dec 23, 2025

Copy link
Copy Markdown

Thanks for your contribution!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the scheduler to reduce excessive preemption when GPU blocks are insufficient. The optimization introduces a reservation mechanism that reserves blocks for currently decoding requests before scheduling new prefill requests, preventing the scheduler from repeatedly preempting and rescheduling requests.

Key changes:

  • Adds configurable environment variable FD_RESERVE_OUTPUT_BLOCK_NUM_FOR_DECODE_WHEN_SCHEDULE_NEW_PREFILL (default: 16 blocks per decoding request)
  • Modifies scheduling logic to check if sufficient blocks remain after reserving blocks for running requests before scheduling new prefill requests

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
fastdeploy/envs.py Adds new environment variable to configure the number of blocks to reserve per decoding request
fastdeploy/engine/sched/resource_manager_v1.py Updates scheduling logic in two locations (WAITING and PREEMPTED request handling) to calculate and check block availability threshold that accounts for reserved blocks

Comment thread fastdeploy/envs.py Outdated
Comment thread fastdeploy/engine/sched/resource_manager_v1.py Outdated
Comment thread fastdeploy/engine/sched/resource_manager_v1.py Outdated
Comment thread fastdeploy/engine/sched/resource_manager_v1.py Outdated
Comment thread fastdeploy/envs.py Outdated
@codecov-commenter

codecov-commenter commented Dec 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.16667% with 17 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@78adf83). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/engine/sched/resource_manager_v1.py 29.16% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #5696   +/-   ##
==========================================
  Coverage           ?   66.97%           
==========================================
  Files              ?      347           
  Lines              ?    44474           
  Branches           ?     6834           
==========================================
  Hits               ?    29788           
  Misses             ?    12483           
  Partials           ?     2203           
Flag Coverage Δ
GPU 66.97% <29.16%> (?)

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.

@rainyfly rainyfly changed the title [Optimize] Reduce preemption occurrence when blocks not enough [Optimization] Reduce preemption occurrence when blocks not enough Jan 7, 2026
@Jiang-Jia-Jun
Jiang-Jia-Jun merged commit c883a2d into PaddlePaddle:develop Jan 7, 2026
15 of 21 checks passed
Jiang-Jia-Jun added a commit that referenced this pull request Jan 8, 2026
…ugh(#5696) (#5808)

* [Optim] Reduce preemption occurrence when blocks not enough

* optimize performance using adaptive block reservation

* optimize performance

* fix

* fix

---------

Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com>
chang-wenbin pushed a commit to chang-wenbin/FastDeploy that referenced this pull request Mar 2, 2026
…addlePaddle#5696)

* [Optimize] Reduce preemption occurrence when blocks not enough for decoding

* fix

* fix

* fix spell

* optimize performance

* fix
xiaoguoguo626807 pushed a commit to xiaoguoguo626807/FastDeploy that referenced this pull request May 7, 2026
…addlePaddle#5696)

* [Optimize] Reduce preemption occurrence when blocks not enough for decoding

* fix

* fix

* fix spell

* optimize performance

* fix
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