[CI][ROCm] Mirror remaining portable suites without duplicate coverage (#57877)
Signed-off-by: Andreas Karatzas <akaratza@amd.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
b8cf275382
commit
8902dbb177
@@ -2,7 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Cold start and warm start tests for vLLM-compile.
|
||||
|
||||
Cold start runs in a forked child (must fork before CUDA init) which
|
||||
Cold start runs in a separate child process which
|
||||
populates on-disk caches and asserts cold-start counters. Warm start
|
||||
then runs in the parent with clean in-memory state but populated caches.
|
||||
"""
|
||||
@@ -18,7 +18,7 @@ from vllm.compilation.counter import compilation_counter
|
||||
from vllm.config import CompilationConfig, CompilationMode, CUDAGraphMode, PassConfig
|
||||
from vllm.utils.torch_utils import is_torch_equal_or_newer
|
||||
|
||||
from ...utils import fork_new_process_for_each_test
|
||||
from ...utils import create_new_process_for_each_test, requires_spawn_multiprocessing
|
||||
|
||||
MODEL = "microsoft/Phi-tiny-MoE-instruct"
|
||||
|
||||
@@ -54,17 +54,21 @@ def _cold_start(vllm_runner):
|
||||
assert counters["aot_autograd"]["autograd_cache_hit"] == 0
|
||||
|
||||
|
||||
@fork_new_process_for_each_test
|
||||
@create_new_process_for_each_test()
|
||||
@pytest.mark.parametrize("mega_aot_artifact", ["0", "1"])
|
||||
def test_moe_startup(monkeypatch, vllm_runner, fresh_vllm_cache, mega_aot_artifact):
|
||||
monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "0")
|
||||
monkeypatch.setenv("VLLM_USE_MEGA_AOT_ARTIFACT", mega_aot_artifact)
|
||||
monkeypatch.setenv("VLLM_DEEP_GEMM_WARMUP", "skip")
|
||||
|
||||
# Cold start in a forked child (must fork before CUDA init).
|
||||
# ROCm and XPU cannot fork safely after device discovery.
|
||||
# This model has 32 identical transformer layers which produce
|
||||
# 33 subgraphs after splitting on attention — only 3 are unique.
|
||||
ctx = mp.get_context("fork")
|
||||
ctx = (
|
||||
mp.get_context("spawn")
|
||||
if requires_spawn_multiprocessing()
|
||||
else mp.get_context("fork")
|
||||
)
|
||||
p = ctx.Process(target=_cold_start, args=(vllm_runner,))
|
||||
p.start()
|
||||
p.join()
|
||||
@@ -223,13 +227,17 @@ def _cold_start_model(vllm_runner, spec: ModelStartupSpec):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("spec", MODEL_SPECS)
|
||||
@fork_new_process_for_each_test
|
||||
@create_new_process_for_each_test()
|
||||
def test_model_startup(monkeypatch, vllm_runner, fresh_vllm_cache, spec):
|
||||
monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "0")
|
||||
monkeypatch.setenv("VLLM_DEEP_GEMM_WARMUP", "skip")
|
||||
|
||||
# Cold start in a forked child (must fork before CUDA init).
|
||||
ctx = mp.get_context("fork")
|
||||
# ROCm and XPU cannot fork safely after device discovery.
|
||||
ctx = (
|
||||
mp.get_context("spawn")
|
||||
if requires_spawn_multiprocessing()
|
||||
else mp.get_context("fork")
|
||||
)
|
||||
p = ctx.Process(target=_cold_start_model, args=(vllm_runner, spec))
|
||||
p.start()
|
||||
p.join()
|
||||
|
||||
@@ -135,6 +135,7 @@ def ref_paged_attn(
|
||||
num_seqs = len(query_lens)
|
||||
block_tables = block_tables.cpu().numpy()
|
||||
_, block_size, num_kv_heads, head_size = key_cache.shape
|
||||
head_size_v = value_cache.shape[-1]
|
||||
|
||||
outputs: list[torch.Tensor] = []
|
||||
start_idx = 0
|
||||
@@ -149,7 +150,7 @@ def ref_paged_attn(
|
||||
|
||||
k = key_cache[block_indices].view(-1, num_kv_heads, head_size)
|
||||
k = k[:kv_len]
|
||||
v = value_cache[block_indices].view(-1, num_kv_heads, head_size)
|
||||
v = value_cache[block_indices].view(-1, num_kv_heads, head_size_v)
|
||||
v = v[:kv_len]
|
||||
|
||||
if q.shape[1] != k.shape[1]:
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from tests.kernels.attention.test_triton_unified_attention import ref_paged_attn
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.math_utils import next_power_of_2
|
||||
from vllm.utils.torch_utils import (
|
||||
@@ -81,7 +82,7 @@ def _alloc_segm_buffers(seq_threshold_3D: int, num_query_heads: int, head_size_v
|
||||
@pytest.mark.parametrize("dtype", DTYPES)
|
||||
@pytest.mark.parametrize("seq_threshold_3D", SEQ_THRESHOLD_3D_VALUES)
|
||||
@torch.inference_mode()
|
||||
def test_triton_unified_attn_diffkv_vs_fa(
|
||||
def test_triton_unified_attn_diffkv_vs_reference(
|
||||
seq_lens: list[tuple[int, int]],
|
||||
num_heads: tuple[int, int],
|
||||
head_sizes: tuple[int, int],
|
||||
@@ -93,12 +94,13 @@ def test_triton_unified_attn_diffkv_vs_fa(
|
||||
) -> None:
|
||||
head_size_qk, head_size_v = head_sizes
|
||||
|
||||
# DiffKV requires FA3 (Hopper) / FA4 (Blackwell) as the reference.
|
||||
fa_version = get_flash_attn_version(head_size=head_size_qk, head_size_v=head_size_v)
|
||||
if not is_flash_attn_varlen_func_available() or fa_version not in (3, 4):
|
||||
pytest.skip(f"FA DiffKV needs FA3/FA4 (got version {fa_version}).")
|
||||
|
||||
from vllm.v1.attention.backends.fa_utils import flash_attn_varlen_func
|
||||
# Keep the FA3/FA4 comparison on NVIDIA; ROCm uses the PyTorch oracle.
|
||||
if not current_platform.is_rocm():
|
||||
fa_version = get_flash_attn_version(
|
||||
head_size=head_size_qk, head_size_v=head_size_v
|
||||
)
|
||||
if not is_flash_attn_varlen_func_available() or fa_version not in (3, 4):
|
||||
pytest.skip(f"FA DiffKV needs FA3/FA4 (got version {fa_version}).")
|
||||
|
||||
torch.set_default_device(DEVICE_TYPE)
|
||||
set_random_seed(0)
|
||||
@@ -135,28 +137,44 @@ def test_triton_unified_attn_diffkv_vs_fa(
|
||||
0, NUM_BLOCKS, (num_seqs, max_num_blocks_per_seq), dtype=torch.int32
|
||||
)
|
||||
|
||||
# ---- FlashAttention DiffKV (ground truth) ---------------------------
|
||||
# Mirror the backend: fix degenerate strides on size-1 dims so FA's
|
||||
# TMA path sees ≥16-byte-aligned strides (matters for num_kv_heads==1).
|
||||
fa_k = canonicalize_singleton_dim_strides(key_cache)
|
||||
fa_v = canonicalize_singleton_dim_strides(value_cache)
|
||||
fa_out = torch.empty(sum(query_lens), num_query_heads, head_size_v, dtype=dtype)
|
||||
flash_attn_varlen_func(
|
||||
q=query,
|
||||
k=fa_k,
|
||||
v=fa_v,
|
||||
out=fa_out,
|
||||
cu_seqlens_q=cu_query_lens,
|
||||
max_seqlen_q=max_query_len,
|
||||
seqused_k=kv_lens_t,
|
||||
max_seqlen_k=max_kv_len,
|
||||
softmax_scale=scale,
|
||||
causal=True,
|
||||
window_size=list(window_size),
|
||||
block_table=block_tables,
|
||||
softcap=soft_cap if soft_cap is not None else 0,
|
||||
fa_version=fa_version,
|
||||
)
|
||||
if current_platform.is_rocm():
|
||||
# FP32 also keeps the helper's in-place scaling off the kernel input.
|
||||
ref_out = ref_paged_attn(
|
||||
query.float(),
|
||||
key_cache.float(),
|
||||
value_cache.float(),
|
||||
query_lens,
|
||||
kv_lens,
|
||||
block_tables,
|
||||
scale,
|
||||
sliding_window=sliding_window,
|
||||
soft_cap=soft_cap,
|
||||
).to(dtype)
|
||||
else:
|
||||
from vllm.v1.attention.backends.fa_utils import flash_attn_varlen_func
|
||||
|
||||
# FA's TMA path needs aligned singleton strides (num_kv_heads == 1).
|
||||
fa_k = canonicalize_singleton_dim_strides(key_cache)
|
||||
fa_v = canonicalize_singleton_dim_strides(value_cache)
|
||||
ref_out = torch.empty(
|
||||
sum(query_lens), num_query_heads, head_size_v, dtype=dtype
|
||||
)
|
||||
flash_attn_varlen_func(
|
||||
q=query,
|
||||
k=fa_k,
|
||||
v=fa_v,
|
||||
out=ref_out,
|
||||
cu_seqlens_q=cu_query_lens,
|
||||
max_seqlen_q=max_query_len,
|
||||
seqused_k=kv_lens_t,
|
||||
max_seqlen_k=max_kv_len,
|
||||
softmax_scale=scale,
|
||||
causal=True,
|
||||
window_size=list(window_size),
|
||||
block_table=block_tables,
|
||||
softcap=soft_cap if soft_cap is not None else 0,
|
||||
fa_version=fa_version,
|
||||
)
|
||||
|
||||
# ---- Triton DiffKV --------------------------------------------------
|
||||
segm_output, segm_max, segm_expsum = _alloc_segm_buffers(
|
||||
@@ -183,7 +201,4 @@ def test_triton_unified_attn_diffkv_vs_fa(
|
||||
softmax_segm_expsum=segm_expsum,
|
||||
)
|
||||
|
||||
(
|
||||
torch.testing.assert_close(triton_out, fa_out, atol=2e-2, rtol=2e-2),
|
||||
f"triton vs FA max abs diff: {torch.max(torch.abs(triton_out - fa_out))}",
|
||||
)
|
||||
torch.testing.assert_close(triton_out, ref_out, atol=2e-2, rtol=2e-2)
|
||||
|
||||
@@ -4,18 +4,23 @@
|
||||
|
||||
The decode path hands the kernel column slices of the merged ``q|k|v`` conv
|
||||
output and of the fused ``qkvbfg_a`` projection (beta), so q/k/v/beta are
|
||||
token-strided rather than contiguous. The kernel must read them in place,
|
||||
match a pure-PyTorch recurrence, and reject layouts it cannot address.
|
||||
token-strided rather than contiguous. Both backends must match a pure-PyTorch
|
||||
recurrence. CUDA reads these slices in place and rejects unsupported layouts;
|
||||
the ROCm wrapper makes contiguous copies before launching its kernel.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from vllm.models.glm5next.nvidia.ops.third_party.kda import fused_recurrent_kda
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
if current_platform.is_rocm():
|
||||
from vllm.models.glm5next.amd.ops.third_party.kda import fused_recurrent_kda
|
||||
else:
|
||||
from vllm.models.glm5next.nvidia.ops.third_party.kda import fused_recurrent_kda
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not current_platform.is_cuda(), reason="CUDA-only Triton kernel"
|
||||
not current_platform.is_cuda_alike(), reason="Requires CUDA or ROCm"
|
||||
)
|
||||
|
||||
H, D = 16, 128
|
||||
@@ -160,6 +165,10 @@ def test_fused_recurrent_kda_strided_inputs_bit_identical_to_contiguous(
|
||||
torch.testing.assert_close(state, state_ref, rtol=0, atol=0)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not current_platform.is_cuda(),
|
||||
reason="Only the CUDA implementation requires zero-copy token-strided layouts",
|
||||
)
|
||||
@torch.inference_mode()
|
||||
def test_fused_recurrent_kda_rejects_unaddressable_layouts():
|
||||
"""Layouts the token-stride addressing cannot express must fail loudly
|
||||
|
||||
Reference in New Issue
Block a user