Skip to content

fix: reject a KV page pool smaller than one max_context request (#169) - #186

Merged
gspark-etri merged 2 commits into
optimus-rmfrom
fix/169-paged-pool-size
Oct 23, 2026
Merged

gspark-etri merged 2 commits into
optimus-rmfrom
fix/169-paged-pool-size

Conversation

@gspark-etri

Copy link
Copy Markdown
Collaborator

Background

submit checks only max_context. With pages < max_context / page_size, a request within max_context that needs more pages than the whole pool could never be admitted (PagedKV.alloc returns None forever). FIFO admission then blocked every request behind it, and the owner loop spun because the batcher never went idle (batching.py:177-179, pd_batching.py:363-365, paged.py:281).

Changes

  • opt_prime/opt_prime/accel/pd/paged.py (PagedKV.__init__): raises ValueError("pages must hold one max_context request") when pages < max_context // page_size. This covers ContinuousBatcher, PDBatcher and TorchPrefillEngine, which all build a PagedKV.
  • opt_prime/tests/test_pd_batching.py::test_paged_pool_smaller_than_one_request_is_rejected: pages=2, max_context=64, page_size=16 must raise.
  • test_paged_admission_follows_pages_not_slots used exactly such a pool (6 pages, max_context=128). It now uses max_context=96 (6 pages). Its requests (at most 38 tokens) and its assertions are unchanged.

Verification

Python 3.10, torch 2.10.0+cu128, transformers 5.1.0, CPU plus one A100 (CUDA_VISIBLE_DEVICES=1) on the RNGD+A100 host. Base: optimus-rm @253be20.

  • New test on the unfixed code: FAILED, DID NOT RAISE ValueError.
  • After the fix: tests/test_pd_batching.py tests/test_pd_prefix_cache.py tests/test_pd_batching_disagg.py gave 38 passed.
  • Whole suite (From opt_prime/: TORCH_DEVICE_BACKEND_AUTOLOAD=0 CUDA_VISIBLE_DEVICES=1 PYTHONPATH=$PWD python3 -m pytest -q tests): 400 passed, 23 skipped before; 401 passed, 23 skipped after.

Compatibility and limits

  • Configurations with an explicit pages below max_context / page_size now fail at startup instead of hanging on the first long request. The fix for those is to lower max_context or raise pages. The defaults (slots * max_context / page_size, and 4 * max_context / page_size for the prefill engine) and examples/pd/kv_tier_replay.py (384 pages vs 29 needed) are unaffected.
  • A request that fits the pool but waits behind others for pages still waits FIFO, by design.

Related Issue

Closes #169

🤖 Generated with Claude Code

gspark-etri and others added 2 commits October 23, 2026 09:56
submit() admits requests up to max_context, but with pages < max_context /
page_size such a request could never get its pages: FIFO admission blocked
everything behind it and the owner loop spun. PagedKV now rejects that
configuration at construction.

test_paged_admission_follows_pages_not_slots used such a pool (6 pages,
max_context 128); it now uses max_context 96, which its requests fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gspark-etri
gspark-etri merged commit de29c50 into optimus-rm Oct 23, 2026
1 check passed
@gspark-etri
gspark-etri deleted the fix/169-paged-pool-size branch October 23, 2026 01:08
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.

1 participant