[ROCm][CI] Speed up test_rocm_aiter_qk_norm_rope_kvcache_fusion (#53004)
Signed-off-by: Micah Williamson <micah.williamson@amd.com> Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com> Co-authored-by: Andreas Karatzas <akaratza@amd.com> Co-authored-by: Andreas Karatzas <Andreas.Karatzas@amd.com>
This commit is contained in:
co-authored by
Andreas Karatzas
Andreas Karatzas
parent
6a962071bd
commit
fbb4c04db4
@@ -2,9 +2,11 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from importlib.metadata import version
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
|
from packaging.version import Version
|
||||||
|
|
||||||
import vllm.config
|
import vllm.config
|
||||||
from tests.compile.backend import TestBackend
|
from tests.compile.backend import TestBackend
|
||||||
@@ -40,10 +42,27 @@ from vllm.v1.attention.backend import (
|
|||||||
from vllm.v1.attention.backends.registry import AttentionBackendEnum
|
from vllm.v1.attention.backends.registry import AttentionBackendEnum
|
||||||
from vllm.v1.kv_cache_interface import AttentionSpec
|
from vllm.v1.kv_cache_interface import AttentionSpec
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.skip_global_cleanup
|
||||||
|
|
||||||
|
if not is_aiter_found_and_supported():
|
||||||
|
pytest.skip(
|
||||||
|
"ROCm with supported AITER is required",
|
||||||
|
allow_module_level=True,
|
||||||
|
)
|
||||||
|
|
||||||
INDEX_SELECT_OP = torch.ops.aten.index.Tensor
|
INDEX_SELECT_OP = torch.ops.aten.index.Tensor
|
||||||
FP8_DTYPE = current_platform.fp8_dtype()
|
FP8_DTYPE = current_platform.fp8_dtype()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module", autouse=True)
|
||||||
|
def module_global_cleanup():
|
||||||
|
# Cleanup once at the end of the module
|
||||||
|
from vllm.distributed import cleanup_dist_env_and_memory
|
||||||
|
|
||||||
|
yield
|
||||||
|
cleanup_dist_env_and_memory()
|
||||||
|
|
||||||
|
|
||||||
class QKNormRoPEKVCacheTestModel(torch.nn.Module):
|
class QKNormRoPEKVCacheTestModel(torch.nn.Module):
|
||||||
"""Minimal model that reproduces the QK-norm + RoPE + KV cache update
|
"""Minimal model that reproduces the QK-norm + RoPE + KV cache update
|
||||||
pattern matched by QkNormRopeKvCacheFusionPass:
|
pattern matched by QkNormRopeKvCacheFusionPass:
|
||||||
@@ -416,8 +435,7 @@ _FUSION_CONFIGS = [
|
|||||||
AttentionBackendEnum.ROCM_AITER_FA,
|
AttentionBackendEnum.ROCM_AITER_FA,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize("num_tokens", [5, 16, 2048])
|
@pytest.mark.parametrize("num_tokens", [5, 2048])
|
||||||
@pytest.mark.parametrize("use_shuffle_kv_layout", ["1", "0"])
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"kv_stride_order",
|
"kv_stride_order",
|
||||||
# FA/unified use the 4D packed cache (num_blocks, num_kv_heads, block_size,
|
# FA/unified use the 4D packed cache (num_blocks, num_kv_heads, block_size,
|
||||||
@@ -428,11 +446,17 @@ _FUSION_CONFIGS = [
|
|||||||
@pytest.mark.parametrize("block_size", [16, 32, 64])
|
@pytest.mark.parametrize("block_size", [16, 32, 64])
|
||||||
@pytest.mark.parametrize("dtype", [torch.bfloat16])
|
@pytest.mark.parametrize("dtype", [torch.bfloat16])
|
||||||
@pytest.mark.parametrize("kv_cache_dtype", ["auto", "fp8"])
|
@pytest.mark.parametrize("kv_cache_dtype", ["auto", "fp8"])
|
||||||
@pytest.mark.parametrize("rms_norm_eps", [1e-5, 1e-6])
|
@pytest.mark.parametrize("rms_norm_eps", [1e-6])
|
||||||
@pytest.mark.parametrize("custom_op", ["+rotary_embedding", "+rms_norm"])
|
@pytest.mark.parametrize("custom_op", ["+rotary_embedding", "+rms_norm"])
|
||||||
|
# The fused_qk_norm_rope_cache kernel used by this test aborts on AITER < 0.1.20
|
||||||
|
# (fused_qk_norm_rope_cache_quant.cu: "k_cache/v_cache must be contiguous within
|
||||||
|
# a block")
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
not is_aiter_found_and_supported(),
|
not Version(version("amd_aiter")) >= Version("0.1.20"),
|
||||||
reason="Only test on ROCm with AITER installed and supported",
|
reason=(
|
||||||
|
"Requires AITER >= 0.1.20; older kernels abort on "
|
||||||
|
"fused_qk_norm_rope_cache (k_cache/v_cache contiguity)"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
def test_qk_norm_rope_kvcache_fusion(
|
def test_qk_norm_rope_kvcache_fusion(
|
||||||
num_tokens: int,
|
num_tokens: int,
|
||||||
@@ -443,7 +467,6 @@ def test_qk_norm_rope_kvcache_fusion(
|
|||||||
is_neox: bool,
|
is_neox: bool,
|
||||||
attn_backend: AttentionBackendEnum,
|
attn_backend: AttentionBackendEnum,
|
||||||
enable_aiter_triton_rope: bool,
|
enable_aiter_triton_rope: bool,
|
||||||
use_shuffle_kv_layout: str,
|
|
||||||
kv_stride_order: tuple[int, ...],
|
kv_stride_order: tuple[int, ...],
|
||||||
block_size: int,
|
block_size: int,
|
||||||
dtype: torch.dtype,
|
dtype: torch.dtype,
|
||||||
@@ -452,19 +475,6 @@ def test_qk_norm_rope_kvcache_fusion(
|
|||||||
custom_op: str,
|
custom_op: str,
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
):
|
):
|
||||||
if (
|
|
||||||
attn_backend == AttentionBackendEnum.ROCM_AITER_UNIFIED_ATTN
|
|
||||||
and use_shuffle_kv_layout == "1"
|
|
||||||
):
|
|
||||||
pytest.skip("ROCM_AITER_UNIFIED_ATTN is NHD-only; shuffle env is ignored")
|
|
||||||
if (
|
|
||||||
attn_backend == AttentionBackendEnum.ROCM_AITER_FA
|
|
||||||
and use_shuffle_kv_layout == "1"
|
|
||||||
):
|
|
||||||
pytest.skip(
|
|
||||||
"ROCM_AITER_FA gates the qk_norm+rope+kvcache fusion off under shuffle "
|
|
||||||
"layout (defers to reshape_and_cache_shuffle_triton), so nothing fuses"
|
|
||||||
)
|
|
||||||
_run_qk_norm_rope_kvcache_fusion_test(
|
_run_qk_norm_rope_kvcache_fusion_test(
|
||||||
attn_backend=attn_backend,
|
attn_backend=attn_backend,
|
||||||
enable_aiter_triton_rope=enable_aiter_triton_rope,
|
enable_aiter_triton_rope=enable_aiter_triton_rope,
|
||||||
@@ -475,7 +485,7 @@ def test_qk_norm_rope_kvcache_fusion(
|
|||||||
rotary_dim=rotary_dim,
|
rotary_dim=rotary_dim,
|
||||||
block_size=block_size,
|
block_size=block_size,
|
||||||
is_neox=is_neox,
|
is_neox=is_neox,
|
||||||
use_shuffle_kv_layout=use_shuffle_kv_layout,
|
use_shuffle_kv_layout="0",
|
||||||
kv_stride_order=kv_stride_order,
|
kv_stride_order=kv_stride_order,
|
||||||
dtype=dtype,
|
dtype=dtype,
|
||||||
kv_cache_dtype=kv_cache_dtype,
|
kv_cache_dtype=kv_cache_dtype,
|
||||||
|
|||||||
Reference in New Issue
Block a user