Skip to content

[2/N][KV-Cache Layout Refactor] Pack K/V into the content dim across attention backends - #44455

Merged
LucasWilkinson merged 96 commits into
mainfrom
lwilkinson/kv-layout/kv-content-pack
Jul 11, 2026
Merged

[2/N][KV-Cache Layout Refactor] Pack K/V into the content dim across attention backends#44455
LucasWilkinson merged 96 commits into
mainfrom
lwilkinson/kv-layout/kv-content-pack

Conversation

@LucasWilkinson

@LucasWilkinson LucasWilkinson commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

PR #42374 (first part of RFC #42082) has been split into 4 PRs:

#44454 [1/N][KV-Cache Layout Refactor] Refactor DSV4 KV cache config
-> #44455 [2/N][KV-Cache Layout Refactor] Pack K/V into the content dim across attention backends
#44456 [3/N][KV-Cache Layout Refactor] Standardize Mamba cache; drop get_transfer_cache_regions
#44458 [4/N][KV-Cache Layout Refactor] Standardize KV cache layout

Summary

Packs K and V into the content dimension across attention backends, changing the KV cache shape from (num_blocks, 2, block_size, num_kv_heads, head_size) (separate leading K/V dim) to (num_blocks, num_kv_heads, block_size, 2*head_size). Backends recover K/V via kv_cache.transpose(1, 2).split(head_size, dim=-1). This removes the need for get_kv_cache_stride_order() in most paths and is a major diff reduction toward #42374.

Stacked on top of #44454 (land that first)

Testing

pytest tests/v1/attention/test_attention_backends.py -v
pytest tests/kernels/attention/test_cache.py -v
pytest tests/v1/worker/test_gpu_model_runner.py -v

Most backend paths require specific GPUs (ROCm, nvfp4/flashinfer); the submitter will run the relevant subset on appropriate hardware before merge.

AI assistance

This PR was prepared with AI assistance (Claude).

@mergify mergify Bot added nvidia rocm Related to AMD ROCm v1 labels Jun 3, 2026
@mergify mergify Bot added the kv-connector label Jun 3, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Jun 3, 2026
@mergify mergify Bot added the ci/build label Jun 4, 2026
@LucasWilkinson LucasWilkinson changed the title [Attention] Pack K/V into the content dim across attention backends [2/N][KV-Cache Layout Refactor] Pack K/V into the content dim across attention backends Jun 4, 2026
@LucasWilkinson
LucasWilkinson force-pushed the lwilkinson/kv-layout/bucket-layers-refactor branch from 926981a to d356e36 Compare June 4, 2026 04:10
@LucasWilkinson
LucasWilkinson force-pushed the lwilkinson/kv-layout/kv-content-pack branch from 6bf3d4c to f8182a2 Compare June 4, 2026 04:10
@LucasWilkinson
LucasWilkinson force-pushed the lwilkinson/kv-layout/bucket-layers-refactor branch from ff6bd5f to cef469f Compare June 4, 2026 04:31
@LucasWilkinson
LucasWilkinson force-pushed the lwilkinson/kv-layout/kv-content-pack branch 4 times, most recently from 189706e to 50f97c1 Compare June 4, 2026 16:54
@LucasWilkinson
LucasWilkinson marked this pull request as ready for review June 4, 2026 18:14
Comment thread vllm/v1/attention/backends/flash_attn_diffkv.py
LucasWilkinson and others added 3 commits July 10, 2026 15:08
Use the actual KV-cache head stride when writing DiffKV packed K/V rows. The FlashAttention DiffKV path passes a transposed cache view for HND layouts, where head stride is block_size * content_size rather than content_size.

Co-authored-by: Codex <codex@openai.com>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
@zhenwei-intel zhenwei-intel mentioned this pull request Jul 17, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build documentation Improvements or additions to documentation intel-gpu Related to Intel GPU kv-connector nvidia ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm rust v1

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants