From 1c7476ec19899f1e61838e23e9fad3505403b9b9 Mon Sep 17 00:00:00 2001 From: andyluo7 <43718156+andyluo7@users.noreply.github.com> Date: Thu, 17 Sep 2026 20:13:07 -0700 Subject: [PATCH] [CI/Build][ROCm] Stabilize shared AMD test lanes (#7706) Signed-off-by: andyluo7 Signed-off-by: haic0 Co-authored-by: haic0 Co-authored-by: Cursor --- .buildkite/amd/test-amd-merge.yml | 16 ++- .buildkite/amd/test-amd-ready.yml | 48 ++++++- .buildkite/amd/test-template-amd-omni.j2 | 16 +++ .buildkite/cuda/test-ready.yml | 6 + tests/buildkite/test_amd_pipeline.py | 24 ++++ tests/diffusion/attention/test_flash_attn.py | 33 ++++- .../models/magi2/test_native_compile_cuda.py | 3 +- .../e2e/offline_inference/test_qwen3_omni.py | 4 +- .../cosyvoice3/test_cosyvoice3_components.py | 112 --------------- .../test_cosyvoice3_components_cuda.py | 127 ++++++++++++++++++ .../test_cosyvoice3_incremental_hift.py | 5 + .../qwen3_omni/test_qwen3_omni_embed.py | 7 +- 12 files changed, 275 insertions(+), 126 deletions(-) create mode 100644 tests/model_executor/models/cosyvoice3/test_cosyvoice3_components_cuda.py diff --git a/.buildkite/amd/test-amd-merge.yml b/.buildkite/amd/test-amd-merge.yml index b1b9e7ecc..6ee36de48 100644 --- a/.buildkite/amd/test-amd-merge.yml +++ b/.buildkite/amd/test-amd-merge.yml @@ -9,15 +9,26 @@ steps: steps: - label: "Simple · Model Executor Test · Shard %N/%t" agent_pool: mi300_1 - parallelism: 2 + parallelism: 3 depends_on: amd-build mirror_hardwares: [amdproduction] grade: Blocking + timeout_in_minutes: 90 commands: - export VLLM_ROCM_USE_AITER=0 # ignore test_teacache_extractors.py because it use rocm gemm kernel from vLLM # that is not supported on CPU - - "pytest -sv tests/model_executor -m 'core_model and cpu' --num-shards=$$BUILDKITE_PARALLEL_JOB_COUNT --shard-id=$$BUILDKITE_PARALLEL_JOB" + - "pytest -sv tests/model_executor -m 'core_model and cpu and not omni' --num-shards=$$BUILDKITE_PARALLEL_JOB_COUNT --shard-id=$$BUILDKITE_PARALLEL_JOB" + + - label: "Simple · Omni Processor Test" + agent_pool: mi300_1 + depends_on: amd-build + mirror_hardwares: [amdproduction] + grade: Blocking + timeout_in_minutes: 60 + commands: + - export VLLM_ROCM_USE_AITER=0 + - "pytest -sv tests/model_executor/models/test_omni_processing.py -m 'core_model and cpu and omni'" - label: "Simple · Diffusion Test · Shard %N/%t" agent_pool: mi300_1 @@ -25,6 +36,7 @@ steps: depends_on: amd-build mirror_hardwares: [amdproduction] grade: Blocking + timeout_in_minutes: 45 commands: - export VLLM_ROCM_USE_AITER=0 # ignore test_teacache_extractors.py because it use rocm gemm kernel from vLLM diff --git a/.buildkite/amd/test-amd-ready.yml b/.buildkite/amd/test-amd-ready.yml index 505ed1b87..e46b559f3 100644 --- a/.buildkite/amd/test-amd-ready.yml +++ b/.buildkite/amd/test-amd-ready.yml @@ -9,26 +9,39 @@ steps: steps: - label: "Simple · Model Executor Test · Shard %N/%t" agent_pool: mi300_1 - parallelism: 2 + parallelism: 3 depends_on: amd-build mirror_hardwares: [amdproduction] grade: Blocking + timeout_in_minutes: 90 commands: - export VLLM_ROCM_USE_AITER=0 # ignore test_teacache_extractors.py because it use rocm gemm kernel from vLLM # that is not supported on CPU - - "pytest -sv tests/model_executor -m 'core_model and cpu' --num-shards=$$BUILDKITE_PARALLEL_JOB_COUNT --shard-id=$$BUILDKITE_PARALLEL_JOB" + - "pytest -sv tests/model_executor -m 'core_model and cpu and not omni' --num-shards=$$BUILDKITE_PARALLEL_JOB_COUNT --shard-id=$$BUILDKITE_PARALLEL_JOB" - - label: "Simple · Diffusion Test" + - label: "Simple · Omni Processor Test" agent_pool: mi300_1 depends_on: amd-build mirror_hardwares: [amdproduction] grade: Blocking + timeout_in_minutes: 60 + commands: + - export VLLM_ROCM_USE_AITER=0 + - "pytest -sv tests/model_executor/models/test_omni_processing.py -m 'core_model and cpu and omni'" + + - label: "Simple · Diffusion Test · Shard %N/%t" + agent_pool: mi300_1 + parallelism: 4 + depends_on: amd-build + mirror_hardwares: [amdproduction] + grade: Blocking + timeout_in_minutes: 45 commands: - export VLLM_ROCM_USE_AITER=0 # ignore test_teacache_extractors.py because it use rocm gemm kernel from vLLM # that is not supported on CPU - - "pytest -sv tests/diffusion -m 'core_model and cpu' --ignore=tests/diffusion/cache/test_teacache_extractors.py" + - "pytest -sv tests/diffusion -m 'core_model and cpu' --ignore=tests/diffusion/cache/test_teacache_extractors.py --num-shards=$$BUILDKITE_PARALLEL_JOB_COUNT --shard-id=$$BUILDKITE_PARALLEL_JOB" - label: "Simple · Engine&Entrypoints Test" agent_pool: mi300_1 @@ -69,6 +82,27 @@ steps: - group: ":card_index_dividers: Diffusion Test" steps: + # Keep real FlashAttention execution out of the CPU-marked Simple lane. + # AITER may need to build several kernels on a cold worker, so run one + # pytest worker with job-local build directories and a bounded timeout. + - label: "ROCm · FlashAttention/AITER GPU Coverage" + agent_pool: mi300_1 + depends_on: amd-build + mirror_hardwares: [amdproduction] + grade: NonBlocking + timeout_in_minutes: 60 + commands: + - export VLLM_ROCM_USE_AITER=1 + - export AITER_JIT_DIR="/tmp/vllm-omni-aiter-$$BUILDKITE_JOB_ID" + - export TORCH_EXTENSIONS_DIR="/tmp/vllm-omni-torch-extensions-$$BUILDKITE_JOB_ID" + - mkdir -p "$$AITER_JIT_DIR" "$$TORCH_EXTENSIONS_DIR" + - >- + timeout --signal=TERM --kill-after=2m 55m + pytest -s -v -n 1 + tests/diffusion/attention/ + -m 'core_model and rocm and MI325 and cards_1' + --run-level "core_model" + - label: "Diffusion · Batch Test" agent_pool: mi300_1 depends_on: amd-build @@ -299,6 +333,12 @@ steps: depends_on: amd-build mirror_hardwares: [amdproduction] grade: Blocking + # A ROCm hardware hang aborts the interpreter with 134. Let Buildkite + # create one fresh pod instead of retrying on the poisoned GPU process. + retry: + automatic: + - exit_status: 134 + limit: 1 commands: - pytest -s -v tests/e2e/online_serving/test_cosyvoice3_tts_expansion.py -m "slow" --run-level "core_model" diff --git a/.buildkite/amd/test-template-amd-omni.j2 b/.buildkite/amd/test-template-amd-omni.j2 index e2042b96a..11a4086b6 100644 --- a/.buildkite/amd/test-template-amd-omni.j2 +++ b/.buildkite/amd/test-template-amd-omni.j2 @@ -156,6 +156,14 @@ steps: {% for path in step.artifact_paths %} - "{{ path }}" {% endfor %} +{% endif %} +{% if step.retry %} + retry: + automatic: +{% for retry_rule in step.retry.automatic %} + - exit_status: {{ retry_rule.exit_status }} + limit: {{ retry_rule.limit }} +{% endfor %} {% endif %} {% if step.timeout_in_minutes %} timeout_in_minutes: {{ step.timeout_in_minutes }} @@ -224,6 +232,14 @@ steps: {% for path in step.artifact_paths %} - "{{ path }}" {% endfor %} +{% endif %} +{% if step.retry %} + retry: + automatic: +{% for retry_rule in step.retry.automatic %} + - exit_status: {{ retry_rule.exit_status }} + limit: {{ retry_rule.limit }} +{% endfor %} {% endif %} {% if step.timeout_in_minutes %} timeout_in_minutes: {{ step.timeout_in_minutes }} diff --git a/.buildkite/cuda/test-ready.yml b/.buildkite/cuda/test-ready.yml index 67f03dbb6..53b9bc4d0 100644 --- a/.buildkite/cuda/test-ready.yml +++ b/.buildkite/cuda/test-ready.yml @@ -38,6 +38,12 @@ steps: depends_on: upload-ready-pipeline steps: + - label: "Diffusion · FlashAttention Test" + timeout_in_minutes: 20 + commands: + - timeout 15m pytest -s -v tests/diffusion/attention/ -m 'core_model and cuda and L4 and cards_1' --run-level "core_model" + mirror_hardwares: l4_1 + - label: "Diffusion · Offloader Test" commands: - timeout 40m pytest -s -v tests/diffusion/offloader -m "core_model and cuda" --run-level "core_model" diff --git a/tests/buildkite/test_amd_pipeline.py b/tests/buildkite/test_amd_pipeline.py index c2c45f5ef..fac4f8c29 100644 --- a/tests/buildkite/test_amd_pipeline.py +++ b/tests/buildkite/test_amd_pipeline.py @@ -11,6 +11,8 @@ pytestmark = [pytest.mark.core_model, pytest.mark.cpu] AMD_MERGE_PIPELINE = Path(".buildkite/amd/test-amd-merge.yml") AMD_NIGHTLY_PIPELINE = Path(".buildkite/amd/test-amd-nightly.yml") +AMD_READY_PIPELINE = Path(".buildkite/amd/test-amd-ready.yml") +AMD_TEMPLATE = Path(".buildkite/amd/test-template-amd-omni.j2") def _find_step(label: str, pipeline_path: Path = AMD_MERGE_PIPELINE) -> dict: @@ -53,3 +55,25 @@ def test_qwen3_accuracy_defers_artifact_path_expansion() -> None: assert '"$${BUILDKITE_BUILD_CHECKOUT_PATH:?}"' in staging_command assert '"$$artifact_dir"' in staging_command assert step["artifact_paths"] == ["tests/e2e/accuracy/qwen3_omni/results/qwen_omni_acc/*.json"] + + +def test_ready_diffusion_cpu_suite_is_sharded() -> None: + step = _find_step("Simple · Diffusion Test · Shard %N/%t", AMD_READY_PIPELINE) + pytest_command = next(command for command in step["commands"] if "pytest" in command) + + assert step["parallelism"] == 4 + assert step["timeout_in_minutes"] == 45 + assert "--num-shards=$$BUILDKITE_PARALLEL_JOB_COUNT" in pytest_command + assert "--shard-id=$$BUILDKITE_PARALLEL_JOB" in pytest_command + + +def test_cosyvoice_gpu_abort_gets_one_fresh_job_retry() -> None: + step = _find_step("CosyVoice3-TTS E2E Test", AMD_READY_PIPELINE) + + assert step["retry"] == {"automatic": [{"exit_status": 134, "limit": 1}]} + + template = AMD_TEMPLATE.read_text(encoding="utf-8") + # Both grouped and top-level AMD steps must preserve an explicit retry + # policy when the source suite is rendered into the uploaded pipeline. + assert template.count("{% if step.retry %}") == 2 + assert template.count("{% for retry_rule in step.retry.automatic %}") == 2 diff --git a/tests/diffusion/attention/test_flash_attn.py b/tests/diffusion/attention/test_flash_attn.py index 183bbd94c..5dbd8d794 100644 --- a/tests/diffusion/attention/test_flash_attn.py +++ b/tests/diffusion/attention/test_flash_attn.py @@ -16,13 +16,14 @@ from unittest.mock import Mock import pytest import torch +from tests.helpers.mark import hardware_test from vllm_omni.diffusion.attention.backends.abstract import AttentionMetadata from vllm_omni.diffusion.attention.backends.flash_attn import FlashAttentionImpl from vllm_omni.diffusion.attention.backends.sdpa import SDPAImpl from vllm_omni.diffusion.attention.backends.utils import fa # noqa: E402 from vllm_omni.platforms import current_omni_platform -pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu] +pytestmark = [pytest.mark.core_model, pytest.mark.diffusion] is_gpu = current_omni_platform.is_cuda_alike() or current_omni_platform.is_xpu() HAS_FLASH_ATTN = fa.HAS_FLASH_ATTN @@ -42,10 +43,12 @@ flash_attn_func = fa.flash_attn_func # noqa: N813 (9, "4", frozenset((2, 3, 4)), 4), ], ) +@pytest.mark.cpu def test_versioned_flash_attention_selection(device_major, requested, supported, expected): assert fa._choose_vllm_flash_attn_version(device_major, requested, supported) == expected +@pytest.mark.cpu def test_versioned_flash_attention_selection_rejects_invalid_or_unavailable_version(): with pytest.raises(ValueError, match="must be 2, 3, or 4"): fa._choose_vllm_flash_attn_version(9, "5", frozenset((2, 3, 4))) @@ -92,7 +95,8 @@ def pad_tensor(tensor: torch.Tensor, target_seq_len: int, pad_value: float = 0.0 return torch.cat([tensor, padding], dim=1) -@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires CUDA or XPU") +@hardware_test(res={"cuda": "L4", "rocm": "MI325"}, num_cards=1) +@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires an accelerator") def test_padding_equivalence(): """ Case 1: Test that padded and unpadded inputs produce similar outputs. @@ -185,7 +189,8 @@ def test_padding_equivalence(): print("✓ Case 1 PASSED: Padded and unpadded outputs are very close!") -@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires CUDA or XPU") +@hardware_test(res={"cuda": "L4", "rocm": "MI325"}, num_cards=1) +@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires an accelerator") def test_fa_vs_sdpa(): """ Case 2: Compare FlashAttention and SDPA backends with padding. @@ -302,7 +307,8 @@ def test_fa_vs_sdpa(): print("✓ Case 2 PASSED: FA and SDPA outputs are very close!") -@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires CUDA or XPU") +@hardware_test(res={"cuda": "L4", "rocm": "MI325"}, num_cards=1) +@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires an accelerator") def test_flash_attn_func_preferred_over_varlen(): """Test flash_attn_func availability and basic forward call.""" if not HAS_FLASH_ATTN: @@ -332,7 +338,8 @@ def test_flash_attn_func_preferred_over_varlen(): print("✓ flash_attn_func forward works correctly!") -@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires CUDA or XPU") +@hardware_test(res={"cuda": "L4", "rocm": "MI325"}, num_cards=1) +@pytest.mark.skipif(not is_gpu, reason="FlashAttention requires an accelerator") @pytest.mark.parametrize("k_len", [40, 256]) def test_cross_attn_key_padding_vs_sdpa(k_len): """ @@ -390,6 +397,7 @@ def test_cross_attn_key_padding_vs_sdpa(k_len): print("✓ Case 3 PASSED: FA and SDPA cross-attention outputs are very close!") +@pytest.mark.cpu def test_varlen_masked_routing_by_role(monkeypatch): """The unpad route is picked by role, not Q/K length equality; runs without a GPU.""" calls = [] @@ -424,6 +432,7 @@ def test_varlen_masked_routing_by_role(monkeypatch): assert cu_seqlens_k.tolist() == [0, 2, 5] +@pytest.mark.cpu def test_piecewise_flash_attn_uses_varlen_fallback(monkeypatch): calls = [] @@ -454,6 +463,7 @@ def test_piecewise_flash_attn_uses_varlen_fallback(monkeypatch): assert calls[0]["softmax_scale"] == 0.5 +@pytest.mark.cpu def test_packed_varlen_metadata_bypasses_mask_unpadding(monkeypatch): calls = [] @@ -486,6 +496,7 @@ def test_packed_varlen_metadata_bypasses_mask_unpadding(monkeypatch): assert calls[0][3]["max_seqlen_q"] == 6 +@pytest.mark.cpu def test_packed_varlen_metadata_must_be_complete(monkeypatch): monkeypatch.setattr(fa, "HAS_FLASH_ATTN", True) impl = FlashAttentionImpl(num_heads=2, head_size=4, softmax_scale=0.5, causal=False) @@ -542,6 +553,7 @@ def _fake_torch_npu(monkeypatch, *, npu_fusion_attention=None): # --- Test group A: boundary resolution (_resolve_packed_seq_npu) ------------- +@pytest.mark.cpu def test_resolve_packed_seq_accepts_real_plus_pad_contract(): impl = _npu_impl() q = torch.randn(1, 8, 2, 4) @@ -551,6 +563,7 @@ def test_resolve_packed_seq_accepts_real_plus_pad_contract(): assert impl._resolve_packed_seq_npu(q, q, extra) == ([5, 8], [5, 8]) +@pytest.mark.cpu def test_resolve_packed_seq_single_document_no_padding(): impl = _npu_impl() q = torch.randn(1, 8, 2, 4) @@ -574,6 +587,7 @@ def test_resolve_packed_seq_single_document_no_padding(): "pad_longer_than_real", ], ) +@pytest.mark.cpu def test_resolve_packed_seq_rejects_malformed_metadata(case): """Any metadata outside the exact [real, pad] contract returns None so the caller falls back to the masked path.""" @@ -630,6 +644,7 @@ def _npu_impl_with_mocked_paths() -> tuple[FlashAttentionImpl, torch.Tensor]: return impl, sentinel +@pytest.mark.cpu def test_npu_env_unset_uses_varlen(monkeypatch): monkeypatch.delenv("MINDIE_SD_FA_TYPE", raising=False) _fake_mindiesd(monkeypatch) @@ -642,6 +657,7 @@ def test_npu_env_unset_uses_varlen(monkeypatch): impl._forward_prefix_kv_slice_npu.assert_not_called() +@pytest.mark.cpu def test_npu_env_laser_uses_slice(monkeypatch): monkeypatch.setenv("MINDIE_SD_FA_TYPE", "ascend_laser_attention") _fake_mindiesd(monkeypatch) @@ -655,6 +671,7 @@ def test_npu_env_laser_uses_slice(monkeypatch): @pytest.mark.parametrize("fa_type", ["prompt_flash_attn", "fused_attn_score", "ascend_laser_attenton", "garbage"]) +@pytest.mark.cpu def test_npu_env_non_laser_value_falls_back_to_varlen(monkeypatch, fa_type): """Locks in the CURRENT dispatch behavior (PR #5891). @@ -675,6 +692,7 @@ def test_npu_env_non_laser_value_falls_back_to_varlen(monkeypatch, fa_type): impl._forward_prefix_kv_slice_npu.assert_not_called() +@pytest.mark.cpu def test_npu_varlen_opt_in_unset_takes_mask_path(monkeypatch): """Models that do not set ``npu_attn_varlen`` (e.g. Wan/Cosmos) keep using the existing masked attention_forward path; the new branches are skipped.""" @@ -702,6 +720,7 @@ def test_npu_varlen_opt_in_unset_takes_mask_path(monkeypatch): ("query_length", "key_length", "expected_inner_precise"), [(4, 4, 0), (2, 4, 0), (4, 2, 2)], ) +@pytest.mark.cpu def test_npu_causal_uses_native_right_down_mode( monkeypatch, query_length, @@ -746,6 +765,7 @@ def test_npu_causal_uses_native_right_down_mode( assert out is expected_out +@pytest.mark.cpu def test_npu_causal_composes_explicit_keep_mask(monkeypatch): expected_out = torch.randn(1, 4, 2, 4) fusion_attention = Mock(return_value=(expected_out, None, None, None, 0, 0, 0)) @@ -782,6 +802,7 @@ def test_npu_causal_composes_explicit_keep_mask(monkeypatch): assert out is expected_out +@pytest.mark.cpu def test_npu_noncausal_without_explicit_mask_stays_unmasked(monkeypatch): captured: dict = {} @@ -800,6 +821,7 @@ def test_npu_noncausal_without_explicit_mask_stays_unmasked(monkeypatch): # --- Test group D: laser input pre-scaling in _forward_prefix_kv_slice_npu -- +@pytest.mark.cpu def test_prefix_kv_slice_applies_laser_input_scaling(monkeypatch): monkeypatch.setenv("MINDIE_SD_FA_TYPE", "ascend_laser_attention") captured: dict = {} @@ -838,6 +860,7 @@ def test_prefix_kv_slice_applies_laser_input_scaling(monkeypatch): torch.testing.assert_close(out, torch.ones(1, 8, 2, 4) * 256.0) +@pytest.mark.cpu def test_prefix_kv_slice_no_scaling_without_factor(monkeypatch): monkeypatch.setenv("MINDIE_SD_FA_TYPE", "ascend_laser_attention") captured: dict = {} diff --git a/tests/diffusion/models/magi2/test_native_compile_cuda.py b/tests/diffusion/models/magi2/test_native_compile_cuda.py index 1db394750..f6f87f0d1 100644 --- a/tests/diffusion/models/magi2/test_native_compile_cuda.py +++ b/tests/diffusion/models/magi2/test_native_compile_cuda.py @@ -14,12 +14,13 @@ from tests.diffusion.models.magi2.test_native_packing import ( ) from tests.helpers.mark import hardware_marks from vllm_omni.diffusion.models.magi2.sampler_magi2 import CFGConfig +from vllm_omni.platforms import current_omni_platform pytestmark = [ pytest.mark.diffusion, pytest.mark.core_model, *hardware_marks(res={"cuda": "L4"}, num_cards=1), - pytest.mark.skipif(not torch.cuda.is_available(), reason="requires CUDA"), + pytest.mark.skipif(not current_omni_platform.is_cuda(), reason="requires CUDA"), ] diff --git a/tests/e2e/offline_inference/test_qwen3_omni.py b/tests/e2e/offline_inference/test_qwen3_omni.py index f5937265c..b33d693ef 100644 --- a/tests/e2e/offline_inference/test_qwen3_omni.py +++ b/tests/e2e/offline_inference/test_qwen3_omni.py @@ -118,7 +118,9 @@ def test_structured_multistage_config_reaches_runtime(omni_runner, offline_clien { "temperature": 0.0, "top_p": 1.0, - "top_k": -1, + # SamplingParams normalizes the disabled greedy-sampling sentinel + # from the deploy YAML (top_k=-1) to its runtime value (top_k=0). + "top_k": 0, "max_tokens": 65536, "repetition_penalty": 1.1, }, diff --git a/tests/model_executor/models/cosyvoice3/test_cosyvoice3_components.py b/tests/model_executor/models/cosyvoice3/test_cosyvoice3_components.py index 74fc5059b..46255110c 100644 --- a/tests/model_executor/models/cosyvoice3/test_cosyvoice3_components.py +++ b/tests/model_executor/models/cosyvoice3/test_cosyvoice3_components.py @@ -10,7 +10,6 @@ import pytest import torch import torch.nn as nn -from tests.helpers.mark import hardware_test from vllm_omni.diffusion.config import set_current_diffusion_config from vllm_omni.diffusion.data import AttentionConfig from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.hifigan import ( @@ -732,114 +731,3 @@ def test_code2wav_streaming_batch_pads_codec_tokens_and_preserves_lengths(): assert torch.equal(call["token_lens"], torch.tensor([3, 5], dtype=torch.int32)) assert results[0][0].shape[-1] == 4 assert results[1][0].shape[-1] == 8 - - -@pytest.mark.core_model -@hardware_test(res={"cuda": "L4"}, num_cards=1) -def test_code2wav_streaming_batch_matches_ragged_flow_numerics(monkeypatch): - """A padded flow batch must match individual flow calls on valid mels.""" - from omegaconf import DictConfig - - from vllm_omni.diffusion.models.cosyvoice3_audio.cosyvoice3_dit import DiT - from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.cfm import ( - CausalConditionalCFM, - CausalMaskedDiffWithDiT, - ) - from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.layers import PreLookaheadLayer - from vllm_omni.model_executor.models.cosyvoice3.cosyvoice3_code2wav import CosyVoice3Code2Wav - - torch.manual_seed(0) - estimator = DiT( - dim=32, - depth=1, - heads=4, - dim_head=8, - dropout=0.0, - ff_mult=2, - mel_dim=80, - mu_dim=80, - spk_dim=80, - out_channels=80, - ) - decoder = CausalConditionalCFM( - in_channels=80, - cfm_params=DictConfig( - { - "sigma_min": 1e-6, - "solver": "euler", - "t_scheduler": "cosine", - "training_cfg_rate": 0.2, - "inference_cfg_rate": 0.7, - } - ), - n_spks=1, - spk_emb_dim=80, - estimator=estimator, - ) - flow_model = ( - CausalMaskedDiffWithDiT( - input_size=80, - output_size=80, - spk_embed_dim=192, - vocab_size=64, - input_frame_rate=25, - only_mask_loss=True, - token_mel_ratio=2, - pre_lookahead_len=1, - pre_lookahead_layer=PreLookaheadLayer(in_channels=80, channels=80, pre_lookahead_len=1), - decoder=decoder, - ) - .to(device="cuda", dtype=torch.bfloat16) - .eval() - ) - - model = object.__new__(CosyVoice3Code2Wav) - nn.Module.__init__(model) - model.flow_model = flow_model - - def return_mel(self, feat, *, cache_state=None, finalize=False): - return feat, None - - model._stream_hift_from_feat = types.MethodType(return_mel, model) - - original_randn = torch.randn - - def length_consistent_randn(*size, **kwargs): - shape = tuple(size[0]) if len(size) == 1 and isinstance(size[0], (tuple, list)) else tuple(size) - if len(shape) == 3 and shape[1] == 80: - device = kwargs.get("device") - dtype = kwargs.get("dtype", torch.float32) - channels = torch.arange(shape[1], device=device, dtype=torch.float32).view(1, -1, 1) - positions = torch.arange(shape[2], device=device, dtype=torch.float32).view(1, 1, -1) - noise = torch.sin(channels * 0.17 + positions * 0.31) - return noise.expand(shape[0], -1, -1).to(dtype=dtype).clone() - return original_randn(*size, **kwargs) - - monkeypatch.setattr(torch, "randn", length_consistent_randn) - common = { - "prompt_token": torch.tensor([[7, 8]], dtype=torch.int32), - "prompt_feat": torch.linspace(-0.5, 0.5, 4 * 80).reshape(1, 4, 80), - "embedding": torch.linspace(-1.0, 1.0, 192).reshape(1, 192), - "finalize": False, - } - items = [ - {**common, "token": torch.tensor([[1, 2, 3]], dtype=torch.int32)}, - {**common, "token": torch.tensor([[1, 2, 3, 4, 5]], dtype=torch.int32)}, - ] - - batched = model.forward_streaming_batch(items, n_timesteps=2) - individual = [ - model.forward_streaming( - token=item["token"], - prompt_token=item["prompt_token"], - prompt_feat=item["prompt_feat"], - embedding=item["embedding"], - n_timesteps=2, - ) - for item in items - ] - - for (batched_mel, _), (individual_mel, _) in zip(batched, individual): - assert batched_mel.shape == individual_mel.shape - rel_mean = (batched_mel - individual_mel).abs().mean() / individual_mel.abs().mean().clamp_min(1e-6) - assert rel_mean.item() < 0.05 diff --git a/tests/model_executor/models/cosyvoice3/test_cosyvoice3_components_cuda.py b/tests/model_executor/models/cosyvoice3/test_cosyvoice3_components_cuda.py new file mode 100644 index 000000000..aff89f852 --- /dev/null +++ b/tests/model_executor/models/cosyvoice3/test_cosyvoice3_components_cuda.py @@ -0,0 +1,127 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project +"""CUDA-only CosyVoice3 component tests.""" + +import types + +import pytest +import torch +import torch.nn as nn + +from tests.helpers.mark import hardware_test +from vllm_omni.platforms import current_omni_platform + +pytestmark = [ + pytest.mark.core_model, + pytest.mark.skipif(not current_omni_platform.is_cuda(), reason="requires CUDA"), +] + + +@hardware_test(res={"cuda": "L4"}, num_cards=1) +def test_code2wav_streaming_batch_matches_ragged_flow_numerics(monkeypatch): + """A padded flow batch must match individual flow calls on valid mels.""" + from omegaconf import DictConfig + + from vllm_omni.diffusion.models.cosyvoice3_audio.cosyvoice3_dit import DiT + from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.cfm import ( + CausalConditionalCFM, + CausalMaskedDiffWithDiT, + ) + from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.layers import PreLookaheadLayer + from vllm_omni.model_executor.models.cosyvoice3.cosyvoice3_code2wav import CosyVoice3Code2Wav + + torch.manual_seed(0) + estimator = DiT( + dim=32, + depth=1, + heads=4, + dim_head=8, + dropout=0.0, + ff_mult=2, + mel_dim=80, + mu_dim=80, + spk_dim=80, + out_channels=80, + ) + decoder = CausalConditionalCFM( + in_channels=80, + cfm_params=DictConfig( + { + "sigma_min": 1e-6, + "solver": "euler", + "t_scheduler": "cosine", + "training_cfg_rate": 0.2, + "inference_cfg_rate": 0.7, + } + ), + n_spks=1, + spk_emb_dim=80, + estimator=estimator, + ) + flow_model = ( + CausalMaskedDiffWithDiT( + input_size=80, + output_size=80, + spk_embed_dim=192, + vocab_size=64, + input_frame_rate=25, + only_mask_loss=True, + token_mel_ratio=2, + pre_lookahead_len=1, + pre_lookahead_layer=PreLookaheadLayer(in_channels=80, channels=80, pre_lookahead_len=1), + decoder=decoder, + ) + .to(device="cuda", dtype=torch.bfloat16) + .eval() + ) + + model = object.__new__(CosyVoice3Code2Wav) + nn.Module.__init__(model) + model.flow_model = flow_model + + def return_mel(self, feat, *, cache_state=None, finalize=False): + return feat, None + + model._stream_hift_from_feat = types.MethodType(return_mel, model) + + original_randn = torch.randn + + def length_consistent_randn(*size, **kwargs): + shape = tuple(size[0]) if len(size) == 1 and isinstance(size[0], (tuple, list)) else tuple(size) + if len(shape) == 3 and shape[1] == 80: + device = kwargs.get("device") + dtype = kwargs.get("dtype", torch.float32) + channels = torch.arange(shape[1], device=device, dtype=torch.float32).view(1, -1, 1) + positions = torch.arange(shape[2], device=device, dtype=torch.float32).view(1, 1, -1) + noise = torch.sin(channels * 0.17 + positions * 0.31) + return noise.expand(shape[0], -1, -1).to(dtype=dtype).clone() + return original_randn(*size, **kwargs) + + monkeypatch.setattr(torch, "randn", length_consistent_randn) + common = { + "prompt_token": torch.tensor([[7, 8]], dtype=torch.int32), + "prompt_feat": torch.linspace(-0.5, 0.5, 4 * 80).reshape(1, 4, 80), + "embedding": torch.linspace(-1.0, 1.0, 192).reshape(1, 192), + "finalize": False, + } + items = [ + {**common, "token": torch.tensor([[1, 2, 3]], dtype=torch.int32)}, + {**common, "token": torch.tensor([[1, 2, 3, 4, 5]], dtype=torch.int32)}, + ] + + batched = model.forward_streaming_batch(items, n_timesteps=2) + individual = [ + model.forward_streaming( + token=item["token"], + prompt_token=item["prompt_token"], + prompt_feat=item["prompt_feat"], + embedding=item["embedding"], + n_timesteps=2, + ) + for item in items + ] + + for (batched_mel, _), (individual_mel, _) in zip(batched, individual): + assert batched_mel.shape == individual_mel.shape + rel_mean = (batched_mel - individual_mel).abs().mean() / individual_mel.abs().mean().clamp_min(1e-6) + assert rel_mean.item() < 0.05 diff --git a/tests/model_executor/models/cosyvoice3/test_cosyvoice3_incremental_hift.py b/tests/model_executor/models/cosyvoice3/test_cosyvoice3_incremental_hift.py index 1e8eff599..91b322864 100644 --- a/tests/model_executor/models/cosyvoice3/test_cosyvoice3_incremental_hift.py +++ b/tests/model_executor/models/cosyvoice3/test_cosyvoice3_incremental_hift.py @@ -31,6 +31,7 @@ from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.hifigan import ( _wrapped_slice, ) from vllm_omni.model_executor.models.cosyvoice3.cosyvoice3_code2wav import CosyVoice3Code2Wav +from vllm_omni.platforms import current_omni_platform pytestmark = [pytest.mark.core_model, pytest.mark.cpu] @@ -334,6 +335,10 @@ def test_incremental_hift_matches_reference_for_voiced_f0(config): @pytest.mark.parametrize("config", CONFIGS) @pytest.mark.parametrize("first_len,step_len", [(10, 6), (10, 3), (20, 3), (10, 1)]) +@pytest.mark.skipif( + current_omni_platform.is_rocm(), + reason="exhaustive CPU reference matrix exceeds the AMD CI time budget", +) def test_incremental_hift_matches_reference_for_voiced_f0_small_chunks(config, first_len, step_len): """Same as test_incremental_hift_matches_reference_for_voiced_f0, but with small, sub-receptive-field chunk sizes (down to 1 mel frame) instead of the uniform diff --git a/tests/model_executor/models/qwen3_omni/test_qwen3_omni_embed.py b/tests/model_executor/models/qwen3_omni/test_qwen3_omni_embed.py index d041eace0..ec6e653c5 100644 --- a/tests/model_executor/models/qwen3_omni/test_qwen3_omni_embed.py +++ b/tests/model_executor/models/qwen3_omni/test_qwen3_omni_embed.py @@ -21,8 +21,13 @@ from benchmarks.qwen3_omni.embedding_harness import ( expected_outputs, make_thinker, ) +from vllm_omni.platforms import current_omni_platform -pytestmark = [pytest.mark.core_model, pytest.mark.cuda] +pytestmark = [ + pytest.mark.core_model, + pytest.mark.cuda, + pytest.mark.skipif(not current_omni_platform.is_cuda(), reason="requires NVIDIA CUDA"), +] _SHAPE = ModelShape( vocab_size=64,