[ROCm][CI] Restore attention coverage after KV-cache layout refactor (#53351)
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
@@ -971,6 +971,21 @@ def test_aiter_sparse_pa_layout_contract(monkeypatch):
|
|||||||
assert value_cache.is_contiguous()
|
assert value_cache.is_contiguous()
|
||||||
|
|
||||||
|
|
||||||
|
def test_aiter_sparse_pa_rejects_multiple_kv_heads(monkeypatch):
|
||||||
|
"""Do not pair AITER's separated cache layout with the Triton fallback."""
|
||||||
|
import vllm.models.minimax_m3.common.sparse_attention as sparse_attn_mod
|
||||||
|
|
||||||
|
monkeypatch.setattr(sparse_attn_mod.rocm_aiter_ops, "is_enabled", lambda: True)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
sparse_attn_mod.rocm_aiter_ops,
|
||||||
|
"is_shuffle_kv_cache_enabled",
|
||||||
|
lambda: True,
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="num_kv_heads == 1"):
|
||||||
|
sparse_attn_mod.minimax_m3_use_aiter_sparse_pa(2)
|
||||||
|
|
||||||
|
|
||||||
def test_indexer_cache_squeezes_to_contiguous_3d():
|
def test_indexer_cache_squeezes_to_contiguous_3d():
|
||||||
"""The indexer side cache is standardized 4D with H=1: under both layouts
|
"""The indexer side cache is standardized 4D with H=1: under both layouts
|
||||||
the allocator's logical view stays contiguous and squeezes (as
|
the allocator's logical view stays contiguous and squeezes (as
|
||||||
|
|||||||
@@ -42,9 +42,11 @@ BACKENDS_TO_TEST = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _actual_backend(backend) -> AttentionBackendEnum:
|
def _actual_backend(backend: AttentionBackendEnum | str) -> AttentionBackendEnum:
|
||||||
"""Resolve pseudo-backends (FLEX_ATTENTION_SLOW) to their real enum."""
|
"""Resolve pseudo-backends (FLEX_ATTENTION_SLOW) to their real enum."""
|
||||||
if backend == "FLEX_ATTENTION_SLOW":
|
if isinstance(backend, str):
|
||||||
|
if backend != "FLEX_ATTENTION_SLOW":
|
||||||
|
raise ValueError(f"Unknown pseudo-backend: {backend}")
|
||||||
return AttentionBackendEnum.FLEX_ATTENTION
|
return AttentionBackendEnum.FLEX_ATTENTION
|
||||||
return backend
|
return backend
|
||||||
|
|
||||||
@@ -266,7 +268,7 @@ def _clone_kv_cache_in_layout(
|
|||||||
|
|
||||||
|
|
||||||
def run_attention_backend(
|
def run_attention_backend(
|
||||||
backend: AttentionBackendEnum,
|
backend: AttentionBackendEnum | str,
|
||||||
kv_cache_spec: FullAttentionSpec,
|
kv_cache_spec: FullAttentionSpec,
|
||||||
layer_names: list[str],
|
layer_names: list[str],
|
||||||
vllm_config,
|
vllm_config,
|
||||||
@@ -283,9 +285,7 @@ def run_attention_backend(
|
|||||||
) -> torch.Tensor:
|
) -> torch.Tensor:
|
||||||
"""Run attention computation using the specified backend's AttentionImpl."""
|
"""Run attention computation using the specified backend's AttentionImpl."""
|
||||||
|
|
||||||
use_direct_block_mask = not current_platform.is_rocm() and is_torch_equal_or_newer(
|
use_direct_block_mask = is_torch_equal_or_newer("2.9.0.dev0")
|
||||||
"2.9.0.dev0"
|
|
||||||
)
|
|
||||||
if backend == "FLEX_ATTENTION_SLOW":
|
if backend == "FLEX_ATTENTION_SLOW":
|
||||||
use_direct_block_mask = False
|
use_direct_block_mask = False
|
||||||
backend = _actual_backend(backend)
|
backend = _actual_backend(backend)
|
||||||
@@ -377,7 +377,7 @@ def run_attention_backend(
|
|||||||
def _test_backend_correctness(
|
def _test_backend_correctness(
|
||||||
batch_spec: BatchSpec,
|
batch_spec: BatchSpec,
|
||||||
model: str,
|
model: str,
|
||||||
backend_to_test: list[AttentionBackendEnum],
|
backend_to_test: list[AttentionBackendEnum | str],
|
||||||
mask_mod,
|
mask_mod,
|
||||||
*,
|
*,
|
||||||
causal: bool = True,
|
causal: bool = True,
|
||||||
@@ -655,7 +655,7 @@ def _test_backend_correctness(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Check numerical similarity
|
# Check numerical similarity
|
||||||
def error_msg(msg: str, backend_name: str):
|
def error_msg(msg: str, backend_name: AttentionBackendEnum | str):
|
||||||
return f"[{backend_name}] output differs from SDPA baseline. {msg}"
|
return f"[{backend_name}] output differs from SDPA baseline. {msg}"
|
||||||
|
|
||||||
torch.testing.assert_close(
|
torch.testing.assert_close(
|
||||||
@@ -1046,14 +1046,24 @@ if current_platform.is_rocm():
|
|||||||
SLIDING_WINDOW_BACKENDS_TO_TEST = [
|
SLIDING_WINDOW_BACKENDS_TO_TEST = [
|
||||||
AttentionBackendEnum.FLEX_ATTENTION,
|
AttentionBackendEnum.FLEX_ATTENTION,
|
||||||
AttentionBackendEnum.TRITON_ATTN,
|
AttentionBackendEnum.TRITON_ATTN,
|
||||||
|
"FLEX_ATTENTION_SLOW",
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
SLIDING_WINDOW_BACKENDS_TO_TEST = [
|
SLIDING_WINDOW_BACKENDS_TO_TEST = [
|
||||||
AttentionBackendEnum.FLASH_ATTN,
|
AttentionBackendEnum.FLASH_ATTN,
|
||||||
AttentionBackendEnum.FLEX_ATTENTION,
|
AttentionBackendEnum.FLEX_ATTENTION,
|
||||||
AttentionBackendEnum.TRITON_ATTN,
|
AttentionBackendEnum.TRITON_ATTN,
|
||||||
|
"FLEX_ATTENTION_SLOW",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Encoder-only FlexAttention always uses the slow builder, so the pseudo-backend
|
||||||
|
# would run an identical implementation twice.
|
||||||
|
SLIDING_WINDOW_ENCODER_BACKENDS_TO_TEST = [
|
||||||
|
backend
|
||||||
|
for backend in SLIDING_WINDOW_BACKENDS_TO_TEST
|
||||||
|
if backend != "FLEX_ATTENTION_SLOW"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"batch_spec_name",
|
"batch_spec_name",
|
||||||
@@ -1162,7 +1172,7 @@ def test_sliding_window_encoder_backend_correctness(
|
|||||||
_test_backend_correctness(
|
_test_backend_correctness(
|
||||||
batch_spec,
|
batch_spec,
|
||||||
model,
|
model,
|
||||||
SLIDING_WINDOW_BACKENDS_TO_TEST,
|
SLIDING_WINDOW_ENCODER_BACKENDS_TO_TEST,
|
||||||
sliding_window_mask_mod_fn,
|
sliding_window_mask_mod_fn,
|
||||||
causal=False,
|
causal=False,
|
||||||
attn_type=AttentionType.ENCODER_ONLY,
|
attn_type=AttentionType.ENCODER_ONLY,
|
||||||
@@ -1173,6 +1183,7 @@ def test_sliding_window_encoder_backend_correctness(
|
|||||||
NON_CAUSAL_BACKENDS_TO_TEST = [
|
NON_CAUSAL_BACKENDS_TO_TEST = [
|
||||||
AttentionBackendEnum.FLASH_ATTN,
|
AttentionBackendEnum.FLASH_ATTN,
|
||||||
AttentionBackendEnum.FLEX_ATTENTION,
|
AttentionBackendEnum.FLEX_ATTENTION,
|
||||||
|
"FLEX_ATTENTION_SLOW",
|
||||||
]
|
]
|
||||||
|
|
||||||
if current_platform.is_rocm():
|
if current_platform.is_rocm():
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ BACKENDS_TO_TEST = [
|
|||||||
AttentionBackendEnum.TOKENSPEED_MLA,
|
AttentionBackendEnum.TOKENSPEED_MLA,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if current_platform.is_rocm():
|
||||||
|
BACKENDS_TO_TEST.append(AttentionBackendEnum.ROCM_AITER_MLA)
|
||||||
|
|
||||||
DEVICE_TYPE = current_platform.device_type
|
DEVICE_TYPE = current_platform.device_type
|
||||||
|
|
||||||
|
|
||||||
@@ -201,13 +204,18 @@ def test_mla_post_load_preserves_runtime_weight_addresses(monkeypatch):
|
|||||||
|
|
||||||
|
|
||||||
# Validate parameter combinations during collection, before GPU fixtures run.
|
# Validate parameter combinations during collection, before GPU fixtures run.
|
||||||
PREFILL_BACKENDS_TO_TEST = [
|
PREFILL_BACKENDS_TO_TEST: list[MLAPrefillBackendEnum] = []
|
||||||
MLAPrefillBackendEnum.ROCM_AITER_FA,
|
if current_platform.is_cuda():
|
||||||
MLAPrefillBackendEnum.FLASH_ATTN,
|
PREFILL_BACKENDS_TO_TEST.extend(
|
||||||
MLAPrefillBackendEnum.FLASHINFER,
|
[
|
||||||
MLAPrefillBackendEnum.TRTLLM_RAGGED,
|
MLAPrefillBackendEnum.FLASH_ATTN,
|
||||||
MLAPrefillBackendEnum.TOKENSPEED_MLA,
|
MLAPrefillBackendEnum.FLASHINFER,
|
||||||
]
|
MLAPrefillBackendEnum.TRTLLM_RAGGED,
|
||||||
|
MLAPrefillBackendEnum.TOKENSPEED_MLA,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
elif current_platform.is_rocm():
|
||||||
|
PREFILL_BACKENDS_TO_TEST.append(MLAPrefillBackendEnum.ROCM_AITER_FA)
|
||||||
|
|
||||||
MLA_DIMENSIONS_TO_TEST = [
|
MLA_DIMENSIONS_TO_TEST = [
|
||||||
("deepseek", 128, 128),
|
("deepseek", 128, 128),
|
||||||
@@ -250,15 +258,6 @@ def _prefill_backend_dimension_params():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif (
|
|
||||||
current_platform.is_rocm()
|
|
||||||
and prefill_backend == MLAPrefillBackendEnum.FLASH_ATTN
|
|
||||||
):
|
|
||||||
# Pre-existing on main: flash-attn MLA prefill returns wrong
|
|
||||||
# outputs and faults on ROCm, so it fails on the base commit too.
|
|
||||||
marks.append(
|
|
||||||
pytest.mark.skip(reason="FLASH_ATTN MLA prefill broken on ROCm")
|
|
||||||
)
|
|
||||||
params.append(
|
params.append(
|
||||||
pytest.param(
|
pytest.param(
|
||||||
prefill_backend,
|
prefill_backend,
|
||||||
|
|||||||
Reference in New Issue
Block a user