Fix vLLM padded KV page allocation and strides - #426
Open
shipiyouniao wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns kvcached’s vLLM integration with vLLM’s page_size_padded behavior by propagating the padded physical page size into KV-cache capacity calculations and tensor view stride construction, preventing block-count/stride mismatches under vLLM 0.24+ indexes_kv_by_block_stride backends.
Changes:
- Thread
page_size_paddedfrom vLLMKVCacheSpecinto kvcached allocation/view-building entrypoints. - Compute physical page size / per-buffer block size via a shared
_resolve_page_geometry()helper and use it in bothalloc_kv_cache()andbuild_kv_views(). - Add regression tests covering padded-page stride behavior, block-count computation, and the “padded + multiple kernel blocks” loud failure mode.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_vllm_padded_page_size.py | Adds regression coverage for padded page size affecting strides and capacity calculations. |
| kvcached/integration/vllm/patches.py | Passes vLLM’s page_size_padded through to kvcached allocation and view construction. |
| kvcached/integration/vllm/interfaces.py | Implements padded-page-aware geometry/stride logic for allocations and strided views. |
Suppressed comments (1)
kvcached/integration/vllm/interfaces.py:501
- Same ratio>1 stride issue as in build_kv_views: when kernel_block_size < block_size (ratio>1) and pages are unpadded, the KV tensor is shaped at kernel-block granularity, so the blocks dimension stride must be hidden_size_eles (kernel-block bytes) rather than block_mem_bytes (virtual-block bytes). Using block_mem_bytes here will mis-stride the attention views for ratio>1.
physical_block_stride_eles = block_mem_bytes // dtype.itemsize
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
shipiyouniao
force-pushed
the
fix/vllm-padded-page-size
branch
from
August 5, 2026 09:26
75af9b7 to
8c6ee31
Compare
shipiyouniao
force-pushed
the
fix/vllm-padded-page-size
branch
3 times, most recently
from
August 19, 2026 11:07
bdcb86f to
9da584f
Compare
shipiyouniao
force-pushed
the
fix/vllm-padded-page-size
branch
from
August 19, 2026 11:08
9da584f to
db8699e
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
page_size_paddedinto kvcached KV allocation and view constructionValidation
python3 -m pytest -q tests/test_vllm_padded_page_size.py tests/test_hybrid_contiguous_layout.py tests/test_alloc_kv_cache_alignment.py tests/test_vllm_nixl_compat.py(70 passedin a GPU-enabled Linux container)Fixes #399