Skip to content

feat: add HND KV layout support#449

Open
hlin99 wants to merge 6 commits into
vllm-project:mainfrom
hlin99:ww30_PR_HND
Open

feat: add HND KV layout support#449
hlin99 wants to merge 6 commits into
vllm-project:mainfrom
hlin99:ww30_PR_HND

Conversation

@hlin99

@hlin99 hlin99 commented Jul 3, 2026

Copy link
Copy Markdown

Motivation:
HND KV layout is required by PD disaggregation scenario

This PR adds HND layout and keeping this other layout unchanged.

Copilot AI review requested due to automatic review settings July 3, 2026 06:01
Signed-off-by: Tony Lin <tony.lin@intel.com>

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.

Pull request overview

This PR adds support for an additional paged KV-cache layout (“HND”, implemented as a permuted view) across the XPU attention stack, enabling stride-based layout auto-detection while keeping existing behavior unchanged for the current “NHD” layout.

Changes:

  • Add HND/NHD layout auto-detection and layout-aware stride/shape handling in Xe2 chunk-prefill and paged-decode paths.
  • Update FlashAttention XPU entrypoints to derive heads/block_size correctly under HND and to pass layout-aware KV strides to kernels.
  • Expand FlashAttention varlen tests to cover both KV layouts and construct HND caches via permutation.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/flash_attn/test_flash_attn_varlen_func.py Adds HND/NHD parametrization and builds HND test tensors via permute; updates reference attention for both layouts.
csrc/xpu/attn/xe_2/paged_decode.hpp Updates documentation/comments to reflect NHD/HND stride support and caller-provided stride fields.
csrc/xpu/attn/xe_2/paged_decode_xe2.cpp Detects HND via strides and computes layout-aware K/V strides for paged decode.
csrc/xpu/attn/xe_2/fmha_xe2.cpp Detects HND and sets layout-aware KV strides for chunk prefill kernels.
csrc/xpu/attn/xe_2/collective/chunk_prefill_mainloop.hpp Fixes tile-index computation to use page-stride tiles when clamping to the last page.
csrc/xpu/attn/paged_kv_utils.h Adds HND layout detection and makes page-stride normalization/layout handling HND-aware.
csrc/flash_attn/flash_api.cpp Makes paged-decode shape extraction layout-aware (num_heads_kv, block_size) for HND.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread csrc/xpu/attn/paged_kv_utils.h
Comment thread csrc/xpu/attn/xe_2/paged_decode_xe2.cpp Outdated
Comment thread tests/flash_attn/test_flash_attn_varlen_func.py Outdated
Comment thread tests/flash_attn/test_flash_attn_varlen_func.py Outdated
Comment thread tests/flash_attn/test_flash_attn_varlen_func.py Outdated
Comment thread tests/flash_attn/test_flash_attn_varlen_func.py Outdated
hlin99 added 2 commits July 3, 2026 07:09
Signed-off-by: Tony Lin <tony.lin@intel.com>
hlin99 added 3 commits July 6, 2026 07:03
Signed-off-by: Tony Lin <tony.lin@intel.com>
Signed-off-by: Tony Lin <tony.lin@intel.com>
@YizhouZ

YizhouZ commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

hi, we already have one PR WIP for this feature #382.

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.

3 participants