Skip to content

Commit 936abaf

Browse files
Fix stale KV-cache API references missed by the standardization
- benchmarks/attention_benchmarks/runner.py: import get_kv_cache_layout (resolve_kv_cache_layout was renamed) and pass reshape_kv_cache's offset/layer_stride/block_stride. Fixes the non-optional MI355 "Attention Benchmarks Smoke Test" job. Reported by @okorzh-amd. - test_rocm_aiter_fa: replace the deleted get_kv_cache_shape assertions with the customize_spec packing contract. - test_sparse_mla_backends: squeeze the head axis before calling forward_mha directly, mirroring bind_kv_cache. Without it the chunked-context prefill read the cache at the wrong stride. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
1 parent d06f976 commit 936abaf

3 files changed

Lines changed: 36 additions & 14 deletions

File tree

benchmarks/attention_benchmarks/runner.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939
from vllm.platforms import current_platform
4040
from vllm.v1.attention.backends.utils import (
4141
CommonAttentionMetadata,
42+
get_kv_cache_layout,
4243
initialize_kv_cache_layout,
43-
resolve_kv_cache_layout,
4444
)
4545
from vllm.v1.kv_cache_interface import (
4646
FullAttentionSpec,
4747
compute_layer_kv_cache_shape_bytes,
48+
layer_kv_cache_strides,
4849
reshape_kv_cache,
4950
)
5051

@@ -357,13 +358,25 @@ def _create_kv_cache(
357358
head_size=config.head_dim,
358359
dtype=cache_dtype,
359360
)
360-
layout = resolve_kv_cache_layout()
361+
layout = get_kv_cache_layout()
361362
total_bytes = (
362363
prod(compute_layer_kv_cache_shape_bytes(spec, max_num_blocks))
363364
* config.num_layers
364365
)
365366
buf = torch.zeros(total_bytes, device=device, dtype=torch.int8)
366-
return reshape_kv_cache(buf, spec, max_num_blocks, config.num_layers, layout)
367+
layer_stride, block_stride = layer_kv_cache_strides(
368+
spec, max_num_blocks, config.num_layers, layout
369+
)
370+
return reshape_kv_cache(
371+
buf,
372+
spec,
373+
max_num_blocks,
374+
config.num_layers,
375+
layout,
376+
offset=0,
377+
layer_stride=layer_stride,
378+
block_stride=block_stride,
379+
)
367380

368381

369382
# ============================================================================

tests/kernels/attention/test_rocm_aiter_fa.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,26 @@ def test_aiter_mha_backend_contract():
309309
)
310310

311311

312-
def test_aiter_mha_backend_validates_kv_cache_block_size():
313-
"""The backend should reject KV cache shapes that cannot be gathered
314-
correctly by the ROCm kernel."""
312+
def test_aiter_mha_backend_publishes_separate_kv_head_groups(monkeypatch):
313+
"""K and V must be published as two token-major head groups, which is how
314+
the fused QK-norm+RoPE+cache kernel addresses the cache."""
315+
from vllm.v1.attention.backends import rocm_aiter_fa
315316
from vllm.v1.attention.backends.rocm_aiter_fa import AiterFlashAttentionBackend
317+
from vllm.v1.kv_cache_interface import FullAttentionSpec
316318

317-
assert AiterFlashAttentionBackend.get_kv_cache_shape(8, 16, 8, 128) == (
318-
8,
319-
8,
320-
16,
321-
256,
319+
spec = FullAttentionSpec(
320+
block_size=16, num_kv_heads=8, head_size=128, dtype=torch.bfloat16
322321
)
323-
with pytest.raises(ValueError, match="Block size must be a multiple of 16"):
324-
AiterFlashAttentionBackend.get_kv_cache_shape(8, 15, 8, 128)
322+
323+
monkeypatch.setattr(rocm_aiter_fa, "_use_separate_kv_head_groups", lambda: True)
324+
published = AiterFlashAttentionBackend.customize_spec(spec)
325+
assert (published.num_head_slots, published.state_content_bytes) == (2, 8 * 128 * 2)
326+
assert published.page_size_bytes == spec.page_size_bytes
327+
assert AiterFlashAttentionBackend.get_required_kv_cache_layout() == "LBHNC"
328+
329+
monkeypatch.setattr(rocm_aiter_fa, "_use_separate_kv_head_groups", lambda: False)
330+
assert AiterFlashAttentionBackend.customize_spec(spec) == spec
331+
assert AiterFlashAttentionBackend.get_required_kv_cache_layout() is None
325332

326333

327334
def test_aiter_mha_backend_supports_compute_capability_matches_mi3xx_probe():

tests/v1/attention/test_sparse_mla_backends.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,9 @@ def test_sparse_backend_prefill_correctness(
11571157
q=query_cat,
11581158
kv_c_normed=kv_c_cat,
11591159
k_pe=k_pe_cat,
1160-
kv_c_and_k_pe_cache=kv_cache,
1160+
# Impls receive the bind-time-squeezed [B, N, C] cache; mirror
1161+
# mla_attention.py's bind_kv_cache squeeze here.
1162+
kv_c_and_k_pe_cache=kv_cache.squeeze(1),
11611163
attn_metadata=metadata,
11621164
k_scale=torch.tensor(1.0, device=device),
11631165
output=out_buffer,

0 commit comments

Comments
 (0)