fix: defer tp prealloc until first alloc#341
Open
shipiyouniao wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Defers starting the background page preallocation thread in multi-process (TP/IPC) setups until the first alloc() call to avoid a startup race that can stall TP initialization.
Changes:
- Add logic in
KVCacheManagerto optionally defer prealloc-thread startup and introduce_start_prealloc_thread()guard. - Start the prealloc thread on first allocation when deferral is enabled, while keeping eager behavior for single-process.
- Add unit tests covering deferred vs eager prealloc startup behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
kvcached/kv_cache_manager.py |
Adds deferred prealloc startup behavior and a guarded helper to start the prealloc thread. |
tests/test_tp_prealloc_startup.py |
Introduces tests verifying deferred prealloc in multi-process and eager prealloc in single-process. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2c73eba to
476b679
Compare
476b679 to
fabc1ce
Compare
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.
Summary
Defer the background prealloc thread until after the first null-block allocation completes in the TP multi-process startup path.
Related issue: #339
Root cause
After the TP coordinator world size is corrected, vLLM still performs one early
KVCacheManager.alloc(1)to reserve its real null block.In the TP multi-process path, starting the background prealloc thread before that first alloc finishes can send both flows through the same multi-process page-map path during startup.
That race can leave the server alive but never ready, even though worker IPC sockets and direct map/unmap operations are otherwise healthy.
Changes
start_prealloc_thread()until after that first alloc completesWhy this approach
This is narrower than globally disabling preallocation and matches the verified behavior from the TP2 reproduction.
The goal is not to remove preallocation, but to prevent it from racing the first null-block allocation in the one startup path where that ordering matters.
Validation
python -m pytest tests/test_tp_prealloc_startup.py -qStarting vLLM server on http://0.0.0.0:19113Application startup completeGET /health -> 200Notes
This PR is intentionally split from the coordinator
world_sizefix. The TP2 startup issue turned out to be a two-defect chain, and this PR addresses the second one.