[CI]Split GPU jobs by cards_* and reject hand-written SKU marks (#6650)
Signed-off-by: wangyu <410167048@qq.com> Signed-off-by: [Your Name] <your.email@example.com>
This commit is contained in:
1 parent
c50b7de167
commit
e338f0ece3
31 files changed
+896
-402
No files matched your search
+2
-2
@@ -25,9 +25,9 @@ pytest_plugins = (
|
||||
"tests.helpers.fixtures.clean",
|
||||
"tests.helpers.fixtures.log",
|
||||
"tests.helpers.fixtures.media",
|
||||
"tests.helpers.fixtures.run_args",
|
||||
"tests.helpers.fixtures.pytest_collection",
|
||||
"tests.helpers.fixtures.pytest_run_args",
|
||||
"tests.helpers.fixtures.runtime",
|
||||
"tests.helpers.fixtures.xdist",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""Tests for DFX runner metadata field exclusion."""
|
||||
|
||||
import json
|
||||
@@ -105,7 +108,7 @@ def test_resolve_pytest_marks_hardware_dict_with_extra():
|
||||
assert "H100" in names
|
||||
assert "cuda" in names
|
||||
assert "gpu" in names
|
||||
assert "distributed_cuda" in names
|
||||
assert "cards_2" in names
|
||||
assert "full_model" in names
|
||||
assert "diffusion" in names
|
||||
assert "local_model" in names
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
"""Tests for the Sequence Parallelism (SP) framework.
|
||||
|
||||
These tests verify the SP plan mechanism and hooks work correctly without
|
||||
@@ -17,6 +17,7 @@ import pytest
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from tests.helpers.mark import hardware_marks
|
||||
from vllm_omni.diffusion.distributed.sp_plan import (
|
||||
SequenceParallelInput,
|
||||
SequenceParallelOutput,
|
||||
@@ -419,7 +420,6 @@ class TestHookRegistration:
|
||||
# =============================================================================
|
||||
|
||||
|
||||
@pytest.mark.L4
|
||||
class TestModelSpPlans:
|
||||
"""Test that model _sp_plan definitions are valid.
|
||||
|
||||
@@ -427,6 +427,8 @@ class TestModelSpPlans:
|
||||
May require GPU for model imports.
|
||||
"""
|
||||
|
||||
pytestmark = hardware_marks(res={"cuda": "L4"})
|
||||
|
||||
def test_zimage_transformer_sp_plan(self):
|
||||
"""Test ZImageTransformer2DModel _sp_plan structure.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
"""GPU e2e for PersonaPlex elastic batching (bit-exact isolation + recycle).
|
||||
|
||||
Greedy decoding makes every cross-slot leak observable as a bit difference:
|
||||
@@ -24,12 +24,17 @@ from __future__ import annotations
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from tests.helpers.mark import hardware_marks
|
||||
|
||||
torch = pytest.importorskip("torch")
|
||||
|
||||
# slow + H100 + omni routes this module into the weekly Buildkite E2E group
|
||||
# ("Omni · H100" in .buildkite/cuda/test-weekly.yml: -m "slow and H100 and
|
||||
# omni" --run-level full_model); the ready/merge CPU sweeps exclude it by mark.
|
||||
pytestmark = [pytest.mark.full_model, pytest.mark.omni, pytest.mark.slow, pytest.mark.H100]
|
||||
# slow + H100 + omni + cards_1 routes this module into weekly
|
||||
# "Omni · H100 · Single-GPU" (test-weekly.yml).
|
||||
pytestmark = [
|
||||
pytest.mark.omni,
|
||||
pytest.mark.slow,
|
||||
*hardware_marks(res={"cuda": "H100"}),
|
||||
]
|
||||
|
||||
if not torch.cuda.is_available(): # noqa: E402
|
||||
pytest.skip("needs CUDA", allow_module_level=True)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
"""Smoke test for HunyuanImage-3.0 Image-to-Text (I2T) pipeline."""
|
||||
|
||||
from collections.abc import Generator
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from PIL import Image
|
||||
|
||||
from tests.helpers.mark import hardware_test
|
||||
from tests.helpers.runtime import OmniRunner
|
||||
from tests.helpers.stage_config import get_deploy_config_path
|
||||
from vllm_omni import Omni
|
||||
@@ -44,7 +44,7 @@ EXPECTED_PREFIX_TOKEN_IDS: list[int] = [
|
||||
# Decoded form, kept only for human-readable assertion messages.
|
||||
EXPECTED_PREFIX_TEXT = "The image is a solid, uniform green color with no variations, objects, or details present. It"
|
||||
|
||||
pytestmark = [pytest.mark.full_model, pytest.mark.diffusion, pytest.mark.cuda]
|
||||
pytestmark = [pytest.mark.full_model, pytest.mark.diffusion]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@@ -57,7 +57,7 @@ def omni() -> Generator[Omni, None, None]:
|
||||
yield runner.omni
|
||||
|
||||
|
||||
@pytest.mark.skipif(torch.accelerator.device_count() < 4, reason="Need at least 4 CUDA GPUs.")
|
||||
@hardware_test(res={"cuda": "H100"}, num_cards=4)
|
||||
def test_i2t_generates_text(omni: Omni) -> None:
|
||||
"""Verify I2T output's first 20 token IDs match the HF greedy baseline."""
|
||||
# Solid-color image keeps the input self-contained and reproducible.
|
||||
|
||||
@@ -91,8 +91,8 @@ def test_krea2_cache_dit(offline_client: OfflineOmniClient) -> None:
|
||||
def test_krea2_hsdp(offline_client: OfflineOmniClient) -> None:
|
||||
"""Exercise Hybrid Sharded Data Parallel (HSDP) weight sharding on the DiT across 2 GPUs.
|
||||
|
||||
Validates the docs' HSDP-support claim for Krea 2. Scheduled on the multi-GPU (distributed_cuda)
|
||||
shard by ``num_cards=2``; skipped automatically on boxes with fewer than 2 CUDA devices.
|
||||
Validates the docs' HSDP-support claim for Krea 2. Scheduled on the multi-GPU
|
||||
shard by ``num_cards=2`` (``not cards_1``); skipped automatically on boxes with fewer than 2 CUDA devices.
|
||||
"""
|
||||
offline_client.send_diffusion_request({"model": MODEL, "prompt": PROMPT, "sampling_params": _sampling()})
|
||||
|
||||
@@ -111,7 +111,7 @@ def test_krea2_vae_patch_parallel(offline_client: OfflineOmniClient) -> None:
|
||||
"""Exercise VAE patch-parallel (decode) across 2 GPUs.
|
||||
|
||||
Validates the docs' VAE-patch-parallel (decode) support claim for Krea 2. Scheduled on the
|
||||
multi-GPU (distributed_cuda) shard by ``num_cards=2``; skipped automatically on boxes with
|
||||
multi-GPU shard by ``num_cards=2`` (``not cards_1``); skipped automatically on boxes with
|
||||
fewer than 2 CUDA devices.
|
||||
"""
|
||||
offline_client.send_diffusion_request({"model": MODEL, "prompt": PROMPT, "sampling_params": _sampling()})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
"""
|
||||
E2E expansion tests for MiMo-Audio online serving (nightly Omni · Function Test with H100).
|
||||
E2E expansion tests for MiMo-Audio online serving (nightly Omni · Function Test with H100 · Single-GPU).
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""Pytest collection-phase hooks.
|
||||
|
||||
All ``pytest_collection_modifyitems`` policies live here so their order is
|
||||
explicit. Add a named helper and call it from the hook; do not register a
|
||||
second ``pytest_collection_modifyitems`` in another plugin.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
_pin_xdist_serial(config, items)
|
||||
|
||||
|
||||
def _pin_xdist_serial(config, items):
|
||||
"""Pin unmarked tests to one xdist worker.
|
||||
|
||||
Only tests explicitly marked ``pytest.mark.xdist`` run concurrently.
|
||||
Others are pinned to a single xdist worker.
|
||||
"""
|
||||
if not config.pluginmanager.hasplugin("xdist"):
|
||||
return
|
||||
for item in items:
|
||||
if not item.get_closest_marker("xdist"):
|
||||
item.add_marker(pytest.mark.xdist_group(name="serial"))
|
||||
@@ -1,3 +1,10 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""Pytest CLI options and the fixtures that expose them."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -24,6 +24,18 @@ if TYPE_CHECKING:
|
||||
omni_fixture_lock = threading.Lock()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _normalized_hardware_marks(request: pytest.FixtureRequest):
|
||||
"""Dummy carrier for mixed-``num_cards`` ``@hardware_test`` mark normalization.
|
||||
|
||||
Pytest has no API to clone an item and only change marks. ``@hardware_test``
|
||||
therefore parametrizes this fixture (``indirect=True``) so each collected
|
||||
item gets one platform's SKU and ``cards_{n}`` without changing test
|
||||
signatures. The returned platform id is unused by test bodies.
|
||||
"""
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def omni_server_function(
|
||||
request: pytest.FixtureRequest,
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
"""
|
||||
Only tests explicitly marked ``pytest.mark.xdist`` run concurrently.
|
||||
Other test are pinned to a single xdist worker.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
if not config.pluginmanager.hasplugin("xdist"):
|
||||
return
|
||||
for item in items:
|
||||
if not item.get_closest_marker("xdist"):
|
||||
item.add_marker(pytest.mark.xdist_group(name="serial"))
|
||||
+251
-126
@@ -1,19 +1,33 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
"""Pytest marks and decorators for hardware / resource selection (CUDA, ROCm, …)."""
|
||||
"""Pytest marks and decorators for hardware / resource selection (CUDA, ROCm, …).
|
||||
|
||||
Module import is stdlib-only so ``tools/pre_commit/check_test_marks.py`` can load
|
||||
this file without pytest or vllm. Decorator helpers import pytest lazily.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from vllm.platforms import current_platform
|
||||
if TYPE_CHECKING:
|
||||
import pytest
|
||||
|
||||
# Marker description tag in ``pyproject.toml`` ``tool.pytest.ini_options.markers``.
|
||||
# Example: ``"H100: [hardware-resource] Tests that require H100 GPU"``.
|
||||
# Marker description tags in ``pyproject.toml`` ``tool.pytest.ini_options.markers``.
|
||||
# Example: ``"H100: [hardware-resource] [cuda] Tests that require H100 GPU"``.
|
||||
_HARDWARE_RESOURCE_MARKER_TAG = "[hardware-resource]"
|
||||
_HARDWARE_CARDS_MARKER_TAG = "[hardware-cards]"
|
||||
_HARDWARE_PLATFORM_MARKER_TAG = "[hardware-platform]"
|
||||
_CI_LEVEL_MARKER_TAG = "[ci-level]"
|
||||
# On ``[hardware-platform]`` lines (not SKUs): also attach ``pytest.mark.gpu``.
|
||||
_GPU_DEVICE_CLASS_TAG = "[gpu]"
|
||||
_CARDS_MARK_NAME_RE = re.compile(r"^cards_(\d+)$")
|
||||
# Indirect fixture in ``tests.helpers.fixtures.runtime``: mixed-count ``@hardware_test``
|
||||
# parametrizes it so each collected item carries one platform's SKU and ``cards_{n}``.
|
||||
HARDWARE_MARK_NORMALIZATION_FIXTURE = "_normalized_hardware_marks"
|
||||
|
||||
|
||||
def _repo_root() -> Path:
|
||||
@@ -34,23 +48,16 @@ def _load_pyproject() -> dict:
|
||||
return {}
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_hardware_mark_list() -> frozenset[str]:
|
||||
"""Return hardware SKU marker names from ``pyproject.toml``.
|
||||
|
||||
A marker is treated as a hardware resource marker when its description
|
||||
contains the ``[hardware-resource]`` tag, e.g.::
|
||||
|
||||
"H100: [hardware-resource] Tests that require H100 GPU"
|
||||
"""
|
||||
@lru_cache(maxsize=16)
|
||||
def _marker_names_with_tag(tag: str) -> frozenset[str]:
|
||||
"""Return pytest marker names whose description contains ``tag``."""
|
||||
data = _load_pyproject()
|
||||
entries = data.get("tool", {}).get("pytest", {}).get("ini_options", {}).get("markers", [])
|
||||
if not entries:
|
||||
# Fallback when TOML parsing fails: scan tagged marker lines.
|
||||
text = (_repo_root() / "pyproject.toml").read_text(encoding="utf-8")
|
||||
return frozenset(
|
||||
re.findall(
|
||||
rf'^\s*"([A-Za-z0-9_]+)\s*:\s*{re.escape(_HARDWARE_RESOURCE_MARKER_TAG)}',
|
||||
rf'^\s*"([A-Za-z0-9_]+)\s*:.*{re.escape(tag)}',
|
||||
text,
|
||||
flags=re.M,
|
||||
)
|
||||
@@ -59,7 +66,7 @@ def get_hardware_mark_list() -> frozenset[str]:
|
||||
names: set[str] = set()
|
||||
for entry in entries:
|
||||
text = str(entry)
|
||||
if _HARDWARE_RESOURCE_MARKER_TAG not in text:
|
||||
if tag not in text:
|
||||
continue
|
||||
name = text.split(":", 1)[0].strip()
|
||||
if name:
|
||||
@@ -67,138 +74,256 @@ def get_hardware_mark_list() -> frozenset[str]:
|
||||
return frozenset(names)
|
||||
|
||||
|
||||
def cuda_marks(*, res: str, num_cards: int):
|
||||
@lru_cache(maxsize=1)
|
||||
def get_hardware_mark_list() -> frozenset[str]:
|
||||
"""Return hardware SKU marker names tagged ``[hardware-resource]``."""
|
||||
return _marker_names_with_tag(_HARDWARE_RESOURCE_MARKER_TAG)
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_supported_card_counts() -> frozenset[int]:
|
||||
"""Return ``n`` for each ``cards_{n}`` marker tagged ``[hardware-cards]``."""
|
||||
counts: set[int] = set()
|
||||
for name in _marker_names_with_tag(_HARDWARE_CARDS_MARKER_TAG):
|
||||
matched = _CARDS_MARK_NAME_RE.fullmatch(name)
|
||||
if matched:
|
||||
counts.add(int(matched.group(1)))
|
||||
return frozenset(counts)
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_supported_platforms() -> frozenset[str]:
|
||||
"""Return platform marker names tagged ``[hardware-platform]``.
|
||||
|
||||
Includes ``cpu`` / ``gpu`` (device-class marks) and accelerator keys.
|
||||
``hardware_marks`` / ``hardware_test`` ``res`` dicts reject ``cpu`` / ``gpu``.
|
||||
"""
|
||||
return _marker_names_with_tag(_HARDWARE_PLATFORM_MARKER_TAG)
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_level_markers() -> frozenset[str]:
|
||||
"""Return CI level marker names tagged ``[ci-level]`` (``core_model``, ``slow``, …)."""
|
||||
return _marker_names_with_tag(_CI_LEVEL_MARKER_TAG)
|
||||
|
||||
|
||||
@lru_cache(maxsize=8)
|
||||
def _skus_for_platform(platform: str) -> frozenset[str]:
|
||||
"""SKU names tagged ``[hardware-resource]`` and ``[platform]`` (e.g. ``[cuda]``)."""
|
||||
return get_hardware_mark_list() & _marker_names_with_tag(f"[{platform}]")
|
||||
|
||||
|
||||
def _require_sku(platform: str, res: str) -> None:
|
||||
allowed = _skus_for_platform(platform)
|
||||
if res not in allowed:
|
||||
supported = ", ".join(sorted(allowed)) or f"(none tagged [hardware-resource] [{platform}])"
|
||||
raise ValueError(f"Invalid {platform} resource type: {res}. Supported: {supported}")
|
||||
|
||||
|
||||
def _cards_mark(num_cards: int) -> pytest.MarkDecorator:
|
||||
"""Return ``cards_{n}`` so collection can filter with ``-m cards_2`` (etc.).
|
||||
|
||||
Multi-card selection is ``not cards_1`` (or an explicit ``cards_2`` / ``cards_4``).
|
||||
"""
|
||||
import pytest
|
||||
|
||||
if not isinstance(num_cards, int) or isinstance(num_cards, bool) or num_cards < 1:
|
||||
raise ValueError(f"num_cards must be a positive int, got {num_cards!r}")
|
||||
if num_cards not in get_supported_card_counts():
|
||||
counts = get_supported_card_counts()
|
||||
supported = ", ".join(f"cards_{n}" for n in sorted(counts))
|
||||
supported = supported or "(none tagged [hardware-cards])"
|
||||
raise ValueError(f"num_cards={num_cards} has no registered marker. Supported: {supported}.")
|
||||
return getattr(pytest.mark, f"cards_{num_cards}")
|
||||
|
||||
|
||||
def _cuda_marks(*, res: str, num_cards: int):
|
||||
import pytest
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
_require_sku("cuda", res)
|
||||
test_resource = getattr(pytest.mark, res)
|
||||
test_platform_detail = pytest.mark.cuda
|
||||
if res == "L4":
|
||||
test_resource = pytest.mark.L4
|
||||
elif res == "H100":
|
||||
test_resource = pytest.mark.H100
|
||||
elif res == "H800":
|
||||
test_resource = pytest.mark.H800
|
||||
else:
|
||||
raise ValueError(f"Invalid CUDA resource type: {res}. Supported: L4, H100, H800")
|
||||
marks = [test_resource, test_platform_detail]
|
||||
if num_cards == 1:
|
||||
marks = [test_resource, test_platform_detail, _cards_mark(num_cards)]
|
||||
if num_cards == 1 or not current_platform.is_cuda():
|
||||
return marks
|
||||
test_distributed = pytest.mark.distributed_cuda(num_cards=num_cards)
|
||||
|
||||
if not current_platform.is_cuda():
|
||||
return marks + [test_distributed]
|
||||
test_skipif = pytest.mark.skipif(
|
||||
current_platform.device_count() < num_cards,
|
||||
reason=f"Need at least {num_cards} CUDA GPUs to run the test.",
|
||||
)
|
||||
return marks + [test_distributed, test_skipif]
|
||||
return marks + [
|
||||
pytest.mark.skipif(
|
||||
current_platform.device_count() < num_cards,
|
||||
reason=f"Need at least {num_cards} CUDA GPUs to run the test.",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def rocm_marks(*, res: str, num_cards: int):
|
||||
test_platform_detail = pytest.mark.rocm
|
||||
if res == "MI325":
|
||||
test_resource = pytest.mark.MI325
|
||||
else:
|
||||
raise ValueError(f"Invalid ROCm resource type: {res}. Supported: MI325")
|
||||
marks = [test_resource, test_platform_detail]
|
||||
if num_cards == 1:
|
||||
def _rocm_marks(*, res: str, num_cards: int):
|
||||
import pytest
|
||||
|
||||
_require_sku("rocm", res)
|
||||
return [getattr(pytest.mark, res), pytest.mark.rocm, _cards_mark(num_cards)]
|
||||
|
||||
|
||||
def _xpu_marks(*, res: str, num_cards: int):
|
||||
import pytest
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
_require_sku("xpu", res)
|
||||
marks = [getattr(pytest.mark, res), pytest.mark.xpu, _cards_mark(num_cards)]
|
||||
if num_cards == 1 or not current_platform.is_xpu():
|
||||
return marks
|
||||
test_distributed = pytest.mark.distributed_rocm(num_cards=num_cards)
|
||||
return marks + [test_distributed]
|
||||
return marks + [
|
||||
pytest.mark.skipif(
|
||||
current_platform.device_count() < num_cards,
|
||||
reason=f"Need at least {num_cards} XPUs to run the test.",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def xpu_marks(*, res: str, num_cards: int):
|
||||
test_platform_detail = pytest.mark.xpu
|
||||
if res == "B60":
|
||||
test_resource = pytest.mark.B60
|
||||
else:
|
||||
raise ValueError(f"Invalid XPU resource type: {res}. Supported: B60")
|
||||
marks = [test_resource, test_platform_detail]
|
||||
if num_cards == 1:
|
||||
return marks
|
||||
test_distributed = pytest.mark.distributed_xpu(num_cards=num_cards)
|
||||
def _musa_marks(*, res: str, num_cards: int):
|
||||
import pytest
|
||||
|
||||
if not current_platform.is_xpu():
|
||||
return marks + [test_distributed]
|
||||
test_skipif = pytest.mark.skipif(
|
||||
current_platform.device_count() < num_cards,
|
||||
reason=f"Need at least {num_cards} XPUs to run the test.",
|
||||
)
|
||||
return marks + [test_distributed, test_skipif]
|
||||
_require_sku("musa", res)
|
||||
return [getattr(pytest.mark, res), pytest.mark.musa, _cards_mark(num_cards)]
|
||||
|
||||
|
||||
def musa_marks(*, res: str, num_cards: int):
|
||||
test_platform_detail = pytest.mark.musa
|
||||
if res == "S5000":
|
||||
test_resource = pytest.mark.S5000
|
||||
else:
|
||||
raise ValueError(f"Invalid MUSA resource type: {res}. Supported: S5000")
|
||||
marks = [test_resource, test_platform_detail]
|
||||
if num_cards == 1:
|
||||
return marks
|
||||
test_distributed = pytest.mark.distributed_musa(num_cards=num_cards)
|
||||
return marks + [test_distributed]
|
||||
@lru_cache(maxsize=1)
|
||||
def _gpu_res_platforms() -> frozenset[str]:
|
||||
"""Accelerator platforms tagged ``[hardware-platform] [gpu]`` (not the ``gpu`` mark)."""
|
||||
return (get_supported_platforms() & _marker_names_with_tag(_GPU_DEVICE_CLASS_TAG)) - {"gpu"}
|
||||
|
||||
|
||||
def gpu_marks(*, res: str, num_cards: int):
|
||||
test_platform = pytest.mark.gpu
|
||||
if res in ("L4", "H100", "H800"):
|
||||
return [test_platform] + cuda_marks(res=res, num_cards=num_cards)
|
||||
if res == "MI325":
|
||||
return [test_platform] + rocm_marks(res=res, num_cards=num_cards)
|
||||
if res == "B60":
|
||||
return [test_platform] + xpu_marks(res=res, num_cards=num_cards)
|
||||
if res == "S5000":
|
||||
return [test_platform] + musa_marks(res=res, num_cards=num_cards)
|
||||
raise ValueError(f"Invalid resource type: {res}. Supported: L4, H100, H800, MI325, B60, S5000")
|
||||
def _npu_marks(*, res: str, num_cards: int):
|
||||
import pytest
|
||||
|
||||
_require_sku("npu", res)
|
||||
return [pytest.mark.npu, getattr(pytest.mark, res), _cards_mark(num_cards)]
|
||||
|
||||
|
||||
def npu_marks(*, res: str, num_cards: int):
|
||||
test_platform = pytest.mark.npu
|
||||
if res == "A2":
|
||||
test_resource = pytest.mark.A2
|
||||
elif res == "A3":
|
||||
test_resource = pytest.mark.A3
|
||||
else:
|
||||
test_resource = None
|
||||
if num_cards == 1:
|
||||
return [mark for mark in [test_platform, test_resource] if mark is not None]
|
||||
test_distributed = pytest.mark.distributed_npu(num_cards=num_cards)
|
||||
return [mark for mark in [test_platform, test_resource, test_distributed] if mark is not None]
|
||||
def _res_platforms() -> frozenset[str]:
|
||||
"""Accelerator keys allowed in ``hardware_test(res=...)`` / ``hardware_marks(res=...)``.
|
||||
|
||||
A ``[hardware-platform]`` name is a ``res`` key only if some SKU is tagged
|
||||
with that platform (``[cuda]``, ``[npu]``, …). ``cpu`` / ``gpu`` have no SKUs.
|
||||
"""
|
||||
return frozenset(p for p in get_supported_platforms() if _skus_for_platform(p))
|
||||
|
||||
|
||||
def _normalize_num_cards(res: dict[str, str], num_cards: int | dict[str, int]) -> dict[str, int]:
|
||||
allowed = _res_platforms()
|
||||
device_class = get_supported_platforms() - allowed
|
||||
for platform in res:
|
||||
if platform in device_class:
|
||||
raise ValueError(
|
||||
f"{platform!r} is not a res dict key; use pytest.mark.{platform} "
|
||||
f"or an accelerator key ({', '.join(sorted(allowed))})."
|
||||
)
|
||||
if platform not in allowed:
|
||||
supported = ", ".join(sorted(allowed)) or "(none)"
|
||||
raise ValueError(f"Unsupported platform: {platform}. res keys: {supported}.")
|
||||
if isinstance(num_cards, int) and not isinstance(num_cards, bool):
|
||||
return {platform: num_cards for platform in res}
|
||||
if not isinstance(num_cards, dict):
|
||||
raise ValueError(f"num_cards must be a positive int or dict, got {num_cards!r}")
|
||||
num_cards_dict = dict(num_cards)
|
||||
for platform in num_cards_dict:
|
||||
if platform not in res:
|
||||
raise ValueError(f"Platform '{platform}' in num_cards but not in res.")
|
||||
for platform in res:
|
||||
num_cards_dict.setdefault(platform, 1)
|
||||
return num_cards_dict
|
||||
|
||||
|
||||
def _marks_for_platform(platform: str, resource: str, num_cards: int) -> list[pytest.MarkDecorator]:
|
||||
import pytest
|
||||
|
||||
builders = {
|
||||
"cuda": _cuda_marks,
|
||||
"rocm": _rocm_marks,
|
||||
"xpu": _xpu_marks,
|
||||
"musa": _musa_marks,
|
||||
"npu": _npu_marks,
|
||||
}
|
||||
builder = builders.get(platform)
|
||||
if builder is None:
|
||||
raise ValueError(f"Unsupported platform: {platform}")
|
||||
marks = builder(res=resource, num_cards=num_cards)
|
||||
if platform in _gpu_res_platforms():
|
||||
return [pytest.mark.gpu] + marks
|
||||
return marks
|
||||
|
||||
|
||||
def _skipif_not_platform(platform: str) -> pytest.MarkDecorator:
|
||||
import pytest
|
||||
|
||||
from vllm_omni.platforms import current_omni_platform
|
||||
|
||||
checkers = {
|
||||
"cuda": current_omni_platform.is_cuda,
|
||||
"rocm": current_omni_platform.is_rocm,
|
||||
"xpu": current_omni_platform.is_xpu,
|
||||
"npu": current_omni_platform.is_npu,
|
||||
"musa": current_omni_platform.is_musa,
|
||||
}
|
||||
return pytest.mark.skipif(not checkers[platform](), reason=f"Requires {platform} platform")
|
||||
|
||||
|
||||
def _apply_marks(func, marks: list[pytest.MarkDecorator]):
|
||||
for mark in reversed(marks):
|
||||
func = mark(func)
|
||||
return func
|
||||
|
||||
|
||||
def hardware_marks(*, res: dict[str, str], num_cards: int | dict[str, int] = 1):
|
||||
for platform, _ in res.items():
|
||||
if platform not in ("cuda", "rocm", "xpu", "npu", "musa"):
|
||||
raise ValueError(f"Unsupported platform: {platform}")
|
||||
if isinstance(num_cards, int):
|
||||
num_cards_dict = {platform: num_cards for platform in res.keys()}
|
||||
else:
|
||||
num_cards_dict = num_cards
|
||||
for platform in num_cards_dict.keys():
|
||||
if platform not in res:
|
||||
raise ValueError(f"Platform '{platform}' in num_cards but not in res.")
|
||||
for platform in res.keys():
|
||||
if platform not in num_cards_dict:
|
||||
num_cards_dict[platform] = 1
|
||||
"""Return marks for a **single** pytest item.
|
||||
|
||||
Different per-platform ``num_cards`` cannot share one item: ``cards_2`` and
|
||||
``cards_4`` would both match ``-m cards_2`` / ``-m cards_4``. Use
|
||||
``@hardware_test`` (one collected variant per platform) or call this once
|
||||
per platform and attach each list to its own ``pytest.param``.
|
||||
"""
|
||||
num_cards_dict = _normalize_num_cards(res, num_cards)
|
||||
unique_counts = set(num_cards_dict.values())
|
||||
if len(res) > 1 and len(unique_counts) > 1:
|
||||
raise ValueError(
|
||||
"hardware_marks() cannot attach different per-platform num_cards to one pytest item "
|
||||
f"(got {num_cards_dict}). Use @hardware_test, which collects one variant per platform, "
|
||||
"or call hardware_marks() once per platform."
|
||||
)
|
||||
|
||||
all_marks: list[pytest.MarkDecorator] = []
|
||||
for platform, resource in res.items():
|
||||
cards = num_cards_dict[platform]
|
||||
if platform in ("cuda", "rocm", "xpu", "musa"):
|
||||
marks = gpu_marks(res=resource, num_cards=cards)
|
||||
elif platform == "npu":
|
||||
marks = npu_marks(res=resource, num_cards=cards)
|
||||
else:
|
||||
raise ValueError(f"Unsupported platform: {platform}")
|
||||
all_marks.extend(marks)
|
||||
all_marks.extend(_marks_for_platform(platform, resource, num_cards_dict[platform]))
|
||||
return all_marks
|
||||
|
||||
|
||||
def hardware_test(*, res: dict[str, str], num_cards: int | dict[str, int] = 1):
|
||||
all_marks = hardware_marks(res=res, num_cards=num_cards)
|
||||
"""Apply hardware marks; split collected items when card counts differ by platform.
|
||||
|
||||
def wrapper(f):
|
||||
func = f
|
||||
for mark in reversed(all_marks):
|
||||
func = mark(func)
|
||||
return func
|
||||
A single item cannot carry both ``cards_4`` (CUDA) and ``cards_2`` (ROCm):
|
||||
``-m "H100 and cards_4 and cuda"`` would otherwise also match
|
||||
``-m "H100 and cards_2 and cuda"``. When ``num_cards`` differs across
|
||||
platforms, this decorator parametrizes one variant per platform so each
|
||||
item only has that platform's SKU and ``cards_{n}``.
|
||||
"""
|
||||
import pytest
|
||||
|
||||
return wrapper
|
||||
num_cards_dict = _normalize_num_cards(res, num_cards)
|
||||
mixed_counts = len(res) > 1 and len(set(num_cards_dict.values())) > 1
|
||||
if not mixed_counts:
|
||||
all_marks = hardware_marks(res=res, num_cards=num_cards)
|
||||
|
||||
def apply_union_marks(f):
|
||||
return _apply_marks(f, all_marks)
|
||||
|
||||
return apply_union_marks
|
||||
|
||||
params = []
|
||||
for platform, resource in res.items():
|
||||
marks = _marks_for_platform(platform, resource, num_cards_dict[platform])
|
||||
marks.append(_skipif_not_platform(platform))
|
||||
params.append(pytest.param(platform, marks=marks, id=platform))
|
||||
|
||||
def apply_split_params(f):
|
||||
func = pytest.mark.usefixtures(HARDWARE_MARK_NORMALIZATION_FIXTURE)(f)
|
||||
return pytest.mark.parametrize(HARDWARE_MARK_NORMALIZATION_FIXTURE, params, indirect=True)(func)
|
||||
|
||||
return apply_split_params
|
||||
@@ -0,0 +1,139 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.helpers.mark import (
|
||||
_gpu_res_platforms,
|
||||
hardware_marks,
|
||||
hardware_test,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def _mark_names(marks) -> set[str]:
|
||||
return {mark.name for mark in marks}
|
||||
|
||||
|
||||
def test_gpu_platforms_come_from_pyproject_gpu_tag():
|
||||
assert "npu" not in _gpu_res_platforms()
|
||||
assert "gpu" not in _gpu_res_platforms()
|
||||
|
||||
|
||||
def test_default_num_cards_adds_cards_1():
|
||||
names = _mark_names(hardware_marks(res={"cuda": "H100"}))
|
||||
assert "cards_1" in names
|
||||
assert "H100" in names
|
||||
assert "cards_2" not in names
|
||||
|
||||
|
||||
def test_h100_two_cards_is_selectable_with_cards_2():
|
||||
names = _mark_names(hardware_marks(res={"cuda": "H100"}, num_cards=2))
|
||||
assert names >= {"H100", "cuda", "gpu", "cards_2"}
|
||||
assert "cards_1" not in names
|
||||
assert "cards_4" not in names
|
||||
|
||||
|
||||
def test_h100_four_cards_is_selectable_with_cards_4():
|
||||
names = _mark_names(hardware_marks(res={"cuda": "H100"}, num_cards=4))
|
||||
assert "cards_4" in names
|
||||
assert "cards_2" not in names
|
||||
|
||||
|
||||
def test_npu_card_count_mark_is_independent_of_sku():
|
||||
names = _mark_names(hardware_marks(res={"npu": "A2"}, num_cards=4))
|
||||
assert "cards_4" in names
|
||||
assert "npu" in names
|
||||
assert "gpu" not in names
|
||||
|
||||
|
||||
def test_hardware_marks_rejects_mixed_counts_on_one_item():
|
||||
with pytest.raises(ValueError, match="different per-platform num_cards"):
|
||||
hardware_marks(
|
||||
res={"cuda": "H100", "rocm": "MI325"},
|
||||
num_cards={"cuda": 4, "rocm": 2},
|
||||
)
|
||||
|
||||
|
||||
def test_same_count_multi_platform_stays_one_item():
|
||||
names = _mark_names(hardware_marks(res={"cuda": "H100", "rocm": "MI325"}, num_cards=2))
|
||||
assert names >= {"H100", "cuda", "MI325", "rocm", "cards_2"}
|
||||
|
||||
@hardware_test(res={"cuda": "H100", "rocm": "MI325"}, num_cards=2)
|
||||
def _probe():
|
||||
return None
|
||||
|
||||
names = {mark.name for mark in _probe.pytestmark}
|
||||
assert "parametrize" not in names
|
||||
assert "cards_2" in names
|
||||
assert "H100" in names
|
||||
assert "MI325" in names
|
||||
|
||||
|
||||
def test_hardware_test_decorator_applies_cards_mark():
|
||||
@hardware_test(res={"cuda": "H100"}, num_cards=2)
|
||||
def _probe():
|
||||
return None
|
||||
|
||||
names = {mark.name for mark in _probe.pytestmark}
|
||||
assert "cards_2" in names
|
||||
assert "H100" in names
|
||||
|
||||
|
||||
def _hardware_platform_params(func):
|
||||
marks = func.pytestmark if isinstance(func.pytestmark, list) else [func.pytestmark]
|
||||
for mark in marks:
|
||||
if mark.name != "parametrize":
|
||||
continue
|
||||
argnames = mark.args[0]
|
||||
if argnames == "_normalized_hardware_marks":
|
||||
return mark.args[1]
|
||||
raise AssertionError("expected @hardware_test to parametrize _normalized_hardware_marks")
|
||||
|
||||
|
||||
def test_mixed_card_counts_split_so_cuda_filter_does_not_see_rocm_count():
|
||||
@hardware_test(res={"cuda": "H100", "rocm": "MI325"}, num_cards={"cuda": 4, "rocm": 2})
|
||||
def _probe():
|
||||
return None
|
||||
|
||||
variants = {param.id: {mark.name for mark in param.marks} for param in _hardware_platform_params(_probe)}
|
||||
cuda_names = variants["cuda"]
|
||||
rocm_names = variants["rocm"]
|
||||
|
||||
assert cuda_names >= {"H100", "cuda", "cards_4"}
|
||||
assert "cards_2" not in cuda_names
|
||||
assert "rocm" not in cuda_names
|
||||
assert "MI325" not in cuda_names
|
||||
|
||||
assert rocm_names >= {"MI325", "rocm", "cards_2"}
|
||||
assert "cards_4" not in rocm_names
|
||||
assert "cuda" not in rocm_names
|
||||
assert "H100" not in rocm_names
|
||||
|
||||
|
||||
def test_unsupported_card_count_raises():
|
||||
with pytest.raises(ValueError, match="num_cards=16"):
|
||||
hardware_marks(res={"cuda": "H100"}, num_cards=16)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform", ["cpu", "gpu"])
|
||||
def test_res_rejects_cpu_and_gpu(platform):
|
||||
with pytest.raises(ValueError, match="not a res dict key"):
|
||||
hardware_marks(res={platform: "H100"})
|
||||
|
||||
|
||||
def test_npu_rejects_unsupported_sku():
|
||||
with pytest.raises(ValueError, match="Invalid npu resource type"):
|
||||
hardware_marks(res={"npu": "A100"})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sku", ["H200", "B200", "H800"])
|
||||
def test_cuda_registered_skus_attach_sku_and_cards(sku):
|
||||
names = _mark_names(hardware_marks(res={"cuda": sku}, num_cards=2))
|
||||
assert names >= {sku, "cuda", "gpu", "cards_2"}
|
||||
|
||||
|
||||
def test_cuda_rejects_sku_from_another_platform():
|
||||
with pytest.raises(ValueError, match="Invalid cuda resource type"):
|
||||
hardware_marks(res={"cuda": "MI325"})
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
"""
|
||||
Tests for CUDA Graph acoustic transformer wrapper numerical equivalence.
|
||||
|
||||
@@ -18,11 +18,12 @@ import pytest
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from tests.helpers.mark import hardware_marks
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA required"),
|
||||
pytest.mark.core_model,
|
||||
pytest.mark.cuda,
|
||||
pytest.mark.L4,
|
||||
*hardware_marks(res={"cuda": "L4"}),
|
||||
]
|
||||
|
||||
DEVICE = torch.device("cuda:0")
|
||||
|
||||
Reference in new issue
Block a user