Skip to content

fix(vllm): handle physical capacity changes at the block-pool recheck - #511

Merged
RixinLiu merged 1 commit into
ovg-project:mainfrom
shipiyouniao:fix/vllm-capacity-recheck
Sep 25, 2026
Merged

RixinLiu merged 1 commit into
ovg-project:mainfrom
shipiyouniao:fix/vllm-capacity-recheck

Conversation

@shipiyouniao

Copy link
Copy Markdown
Collaborator

Problem

The elastic pool can still terminate EngineCore when physical capacity drops between the scheduler's preflight and get_new_blocks(). This is a normal possibility on a shared GPU: the earlier free-block count is a snapshot, not a reservation.

Related: #197 and #509. #206 adds a reproduction workload for #197; it does not change this allocation path. This PR addresses the escaping exception, not every multi-instance failure mentioned in that issue.

Root cause

At the current base, the pool performs another capacity check:

if num_blocks > self.get_num_free_blocks():
    raise ValueError(...)

The existing allocate_slots() wrapper intentionally catches only KVCachePoolExhausted and returns None to the scheduler. Therefore, exhaustion detected by this early recheck escapes, while exhaustion detected later in the allocator already follows the recoverable path.

Before

sequenceDiagram
    participant S as Scheduler
    participant P as Elastic block pool
    participant G as Shared GPU capacity
    S->>P: Read free blocks for preflight
    P-->>S: Enough blocks at this instant
    G->>G: Another allocation consumes capacity
    S->>P: allocate_slots / get_new_blocks
    P->>G: Recheck available capacity
    G-->>P: Not enough now
    P-->>S: Plain ValueError escapes typed handler
    Note over S: EngineCore exits
Loading

Change

Raise KVCachePoolExhausted at that recheck, matching the allocator's existing exhaustion signal. Keep the wrapper narrow: unrelated ValueError and CUDA/runtime failures still propagate. There is no broad exception catch, new lock, capacity-policy change, or retry loop.

After

sequenceDiagram
    participant S as Scheduler
    participant W as allocate_slots wrapper
    participant P as Elastic block pool
    S->>W: Allocate after preflight
    W->>P: get_new_blocks
    P-->>W: KVCachePoolExhausted on reduced capacity
    W-->>S: None (cannot allocate now)
    Note over P: Early rejection leaves pool bookkeeping unchanged
    S->>W: Retry through normal scheduler behavior
    W->>P: get_new_blocks
    P-->>S: Blocks when capacity is available
Loading

Tests and scope

The regression tests exercise the actual injected pool with prefix caching both enabled and disabled. They check rejection without allocator calls or changes to reference counts/cache bookkeeping, a successful retry, translation through the enabled wrapper, and propagation of unrelated errors. The focused suite has 12 tests.

Validated revision: aeade716fee796997e9d967304b267ee43223d32, independently based on main, without the pending adaptation stack.

  • Full pre-commit and GPU-free C++ checks passed. Python 3.9-3.13 each passed 488 CPU tests, test classification and MyPy. Dedicated Codex review found no actionable issues.
  • T4, vLLM 0.29.0+cu129, MRV2, eager execution, TP=PP=1: contiguous and non-contiguous layouts each handled three injected capacity drops at the real block-pool recheck after scheduler preflight. Both runs completed all 16 prompts / 256 output tokens, with exact native/patched token equality and explicit shutdown.
  • A separate oversized CUDA allocation was caught in each layout's isolated failure probe, followed by a successful GPU operation. This deliberate OOM is not a serving failure. Source fingerprints remained unchanged and the GPU returned to idle.

The capacity injection changes the reported free count at the recheck; it is not a natural multi-instance pressure benchmark. The serving model has random tiny attention-only weights, so token equality is a regression check, not a model-quality claim. No multi-GPU/MPS safety or performance improvement is claimed.

Copilot AI lite review requested due to automatic review settings September 24, 2026 18:08

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@rishabhsinha17 rishabhsinha17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. The release needs this. #197 is this exact raise, its message comes from the early recheck in get_new_blocks, not from the allocator path #453 already reports as a scheduling miss. #453 kept the recheck fail-loud because asking for more than the reported free count meant a caller bug, but under kvcached that count reads shared physical capacity, so a colocated engine can invalidate the preflight with no bug anywhere. Raising KVCachePoolExhausted, the typed signal the allocate_slots wrapper already turns into the scheduler's cannot-allocate-now answer, is the smallest fix.

Verified at aeade71. Pool injection and wrapper share one version range, the NativeBlockPoolMixin that 0.29 mixes in does not override get_new_blocks, and KVCachePoolExhausted subclasses ValueError so existing catchers keep working. Your new recheck cases fail against main, all six, and the file is 12/12 at this head. Full cpu manifest here is 476 passed with a failure set byte-identical to main on my mac. T4 serving evidence stays yours.

@RixinLiu
RixinLiu self-requested a review September 25, 2026 01:58

@RixinLiu RixinLiu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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