[Optimization] Reduce preemption occurrence when blocks not enough - #5696
Jiang-Jia-Jun merged 8 commits into
Conversation
|
Thanks for your contribution! |
There was a problem hiding this comment.
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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5696 +/- ##
==========================================
Coverage ? 66.97%
==========================================
Files ? 347
Lines ? 44474
Branches ? 6834
==========================================
Hits ? 29788
Misses ? 12483
Partials ? 2203
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:
|
…into optimize_scheduler_for_preemption
…into optimize_scheduler_for_preemption
…addlePaddle#5696) * [Optimize] Reduce preemption occurrence when blocks not enough for decoding * fix * fix * fix spell * optimize performance * fix
…addlePaddle#5696) * [Optimize] Reduce preemption occurrence when blocks not enough for decoding * fix * fix * fix spell * optimize performance * fix
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
[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.