[Kernel][Test] Make kernel tests for mamba dual-HW (CUDA + XPU) (#42736)

Signed-off-by: Dobrzyniewicz, Agata <agata.dobrzyniewicz@intel.com>
This commit is contained in:
Agata Dobrzyniewicz
2026-06-08 08:22:47 +08:00
committed by GitHub
parent 4dcd10eb0d
commit 2ed0a9627b
3 changed files with 49 additions and 14 deletions
+24 -7
View File
@@ -17,6 +17,21 @@ from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.attention.backends.utils import NULL_BLOCK_ID
DEVICE = current_platform.device_type
pytestmark = pytest.mark.skipif(
not (current_platform.is_cuda_alike() or current_platform.is_xpu()),
reason="mamba_ssm kernels require CUDA-alike or XPU",
)
# selective_scan_fn is backed by the CUDA-only `ops.selective_scan_fwd` C++ op,
# so tests exercising it must be skipped on XPU. selective_state_update is
# pure Triton and runs on both CUDA-alike and XPU.
skip_unless_cuda_alike = pytest.mark.skipif(
not current_platform.is_cuda_alike(),
reason="selective_scan_fn uses CUDA-only custom op",
)
def selective_scan_ref(
u,
@@ -181,6 +196,7 @@ def selective_scan_opcheck_fn(
@pytest.mark.parametrize("is_variable_C", [True])
@pytest.mark.parametrize("is_variable_B", [True])
@pytest.mark.parametrize("scan_chunks", [1, 3])
@skip_unless_cuda_alike
def test_selective_scan(
is_variable_B,
is_variable_C,
@@ -327,7 +343,7 @@ def test_selective_scan(
@pytest.mark.parametrize("dstate", [16, 64])
@pytest.mark.parametrize("dim", [2048, 2048 + 16, 4096])
def test_selective_state_update(dim, dstate, has_z, itype):
device = "cuda"
device = DEVICE
rtol, atol = (3e-4, 1e-3) if itype == torch.float32 else (5e-3, 1e-2)
if itype == torch.bfloat16:
rtol, atol = 1e-2, 5e-2
@@ -370,7 +386,7 @@ def test_selective_state_update(dim, dstate, has_z, itype):
" on compute capability 10.0 CUDA devices.",
)
def test_selective_state_update_stochastic_rounding(dim, dstate, has_z, philox_rounds):
device = "cuda"
device = DEVICE
rtol, atol = 5e-3, 1e-1
# set seed
set_random_seed(0)
@@ -417,7 +433,7 @@ def test_selective_state_update_stochastic_rounding(dim, dstate, has_z, philox_r
@pytest.mark.parametrize("dim", [2048, 2048 + 16, 4096])
@pytest.mark.parametrize("max_seq_len", [1, 2, 4])
def test_selective_state_update_varlen(dim, dstate, has_z, itype, max_seq_len):
device = "cuda"
device = DEVICE
rtol, atol = (3e-4, 1e-3) if itype == torch.float32 else (5e-3, 1e-2)
if itype == torch.bfloat16:
rtol, atol = 5e-2, 1.5e-1
@@ -498,6 +514,7 @@ def test_selective_state_update_varlen(dim, dstate, has_z, itype, max_seq_len):
@pytest.mark.parametrize("is_variable_B", [True])
# tests correctness in case subset of the sequences are padded
@pytest.mark.parametrize("with_padding", [False, True])
@skip_unless_cuda_alike
def test_selective_scan_varlen(
with_padding,
is_variable_B,
@@ -679,7 +696,7 @@ def test_selective_scan_varlen(
def test_selective_state_update_with_batch_indices(
with_padding, dim, dstate, has_z, itype
):
device = "cuda"
device = DEVICE
rtol, atol = (3e-4, 1e-3) if itype == torch.float32 else (5e-3, 1e-2)
if itype == torch.bfloat16:
rtol, atol = 1e-1, 1e-1
@@ -771,7 +788,7 @@ def test_selective_state_update_with_batch_indices(
def test_selective_state_update_with_heads_with_batch_indices(
dim, dstate, ngroups, has_z, tie_hdim, itype
):
device = "cuda"
device = DEVICE
rtol, atol = (3e-4, 1e-3) if itype == torch.float32 else (5e-3, 3e-2)
if itype == torch.bfloat16:
rtol, atol = 1e-1, 1e-1
@@ -844,7 +861,7 @@ def test_selective_state_update_with_heads_with_batch_indices(
def test_selective_state_update_with_num_accepted_tokens(
dim, dstate, has_z, itype, max_seq_len
):
device = "cuda"
device = DEVICE
rtol, atol = (3e-4, 1e-3) if itype == torch.float32 else (5e-3, 1e-2)
if itype == torch.bfloat16:
rtol, atol = 5e-2, 1.5e-1
@@ -970,7 +987,7 @@ def test_selective_state_update_with_num_accepted_tokens(
def test_selective_state_update_varlen_with_num_accepted(
dim, dstate, has_z, itype, max_seq_len
):
device = "cuda"
device = DEVICE
rtol, atol = (3e-4, 1e-3) if itype == torch.float32 else (5e-3, 1e-2)
if itype == torch.bfloat16:
rtol, atol = 5e-2, 1.5e-1