fix(paged-attn): resolve scheduler queue loop deadlock under memory pressure#2043
Open
glaziermag wants to merge 1 commit intoEricLBuehler:masterfrom
Open
fix(paged-attn): resolve scheduler queue loop deadlock under memory pressure#2043glaziermag wants to merge 1 commit intoEricLBuehler:masterfrom
glaziermag wants to merge 1 commit intoEricLBuehler:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses a deadlock issue in
PagedAttentionSchedulerwhere the inference engine could hang during preemption under heavy KV cache memory pressure (resolves #1470).Previously, when a sequence was preempted in the
schedulemethod via_preempt(), it was pushed to the front of theself.waitingqueue. Because the main starvation loop iterated over the queue non-destructively usingself.waiting.front(), the newly preempted sequence was immediately targeted for re-evaluation. This caused an infinite loop of preemption and failed allocations.Changes
waitingsequence queue iteration inscheduler.rsto proactivelypop_front()the sequence before checking its allocation status.max_num_seqscaps or unresolvable starvation conditions requiring a later retry), the sequence is safely re-inserted viaself.waiting.push_front(seq).Testing
g2-standard-32instance.WARNlog cycle.Blast Radius Verification
To verify the structural integrity of the scheduler state, we ran a concurrent barrage of large Qwen2.5-3B completions on a strictly bounded 4096-token KV cache environment specifically designed to exhaust the BlockPool.
Before (Unpatched):
The engine immediately hit the KV cache bottleneck and permanently hung at
0.00 T/sas it recursively thrashed the preemption loop safely catchingAllocStatus::Later:After (Patched):
Under identical
aiohttpsaturation tests, the sequence correctly stepped down onto thewaitingqueue and advanced the scheduler, letting independent completions securely evaluate until block space was liberated. The load successfully finished while keeping interval processing cleanly between 1.6K ~ 2.0K T/s: