Merged
[fix] Skip incompatible Triton-Ascend smoke tests in pytest #1321
hanboyouAdd on 17 days ago
[fix] Skip incompatible Triton-Ascend smoke tests in pytest #1321
Merged
Total: 7 files changed+153-16
| @@ -11,22 +11,10 @@ set -euo pipefail | |||
| 11 | 11 | ||
| 12 | source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh" | 12 | source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh" |
| 13 | 13 | ||
| 14 | -# Tests that the 2026-09-29 CI image cannot run yet. They are deselected here | 14 | +# Version-scoped Triton skips are applied by tests/smoke_tests/conftest.py. |
| 15 | -# instead of patched in the repo; drop a deselect once its toolchain issue is | ||
| 16 | -# fixed. | ||
| 17 | -# * tests/smoke_tests/ops/test_mhc_triton.py (26 cases): triton-ascend | ||
| 18 | -# hardcodes -std=c++17 when it builds its NPU host stub / precompiled | ||
| 19 | -# header, while torch >= 2.14 refuses anything below C++20 | ||
| 20 | -# (ATen/ATen.h:5), so every Triton kernel launch fails to compile. | ||
| 21 | -# * test_qwen3_5_npu_runtime.py::test_merged_gdn_forward_backward uses the | ||
| 22 | -# same Triton host-stub compiler and fails with the same C++17/C++20 error. | ||
| 23 | -SMOKE_DESELECT=( | ||
| 24 | - --deselect tests/smoke_tests/ops/test_mhc_triton.py | ||
| 25 | - --deselect tests/smoke_tests/ops/test_qwen3_5_npu_runtime.py::test_merged_gdn_forward_backward | ||
| 26 | -) | ||
| 27 | 15 | ||
| 28 | SMOKE_TESTS_START="$(date +%s)" | 16 | SMOKE_TESTS_START="$(date +%s)" |
| 29 | -"${PYTHON_BIN}" -m pytest -v --tb=short "${SMOKE_DESELECT[@]}" tests/smoke_tests | 17 | +"${PYTHON_BIN}" -m pytest -v --tb=short -rs tests/smoke_tests "$@" |
| 30 | SMOKE_TESTS_END="$(date +%s)" | 18 | SMOKE_TESTS_END="$(date +%s)" |
| 31 | 19 | ||
| 32 | echo "tests.smoke_tests finished in $((SMOKE_TESTS_END - SMOKE_TESTS_START))s" | 20 | echo "tests.smoke_tests finished in $((SMOKE_TESTS_END - SMOKE_TESTS_START))s" |
| @@ -29,6 +29,7 @@ pythonpath = ["."] | |||
| 29 | markers = [ | 29 | markers = [ |
| 30 | "cpu: CPU-only unit test", | 30 | "cpu: CPU-only unit test", |
| 31 | "smoke: NPU smoke test", | 31 | "smoke: NPU smoke test", |
| 32 | + "triton_ascend: NPU smoke case requiring the Triton-Ascend Torch launcher", | ||
| 32 | "static: source and declaration contract test", | 33 | "static: source and declaration contract test", |
| 33 | "tooling: repository tooling or skill self-test; excluded from product UT coverage", | 34 | "tooling: repository tooling or skill self-test; excluded from product UT coverage", |
| 34 | ] | 35 | ] |
| @@ -4,12 +4,21 @@ | |||
| 4 | # LICENSE file in the root directory of this source tree. | 4 | # LICENSE file in the root directory of this source tree. |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -"""Shared pytest fixtures for the smoke tests under tests/smoke_tests.""" | 7 | +"""Shared pytest options and fixtures for smoke tests.""" |
| 8 | 8 | ||
| 9 | import pytest | 9 | import pytest |
| 10 | import torch | 10 | import torch |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | +def pytest_addoption(parser): | ||
| 14 | + parser.addoption( | ||
| 15 | + "--run-unsupported-triton", | ||
| 16 | + action="store_true", | ||
| 17 | + default=False, | ||
| 18 | + help="Run Triton smoke cases despite the known Torch >= 2.14 C++17/C++20 launcher incompatibility.", | ||
| 19 | + ) | ||
| 20 | + | ||
| 21 | + | ||
| 13 | @pytest.fixture(scope="session") | 22 | @pytest.fixture(scope="session") |
| 14 | def npu_available(): | 23 | def npu_available(): |
| 15 | """Return whether a real NPU runtime is available.""" | 24 | """Return whether a real NPU runtime is available.""" |
| @@ -0,0 +1,52 @@ | |||
| 1 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. | ||
| 2 | +# | ||
| 3 | +# This source code is licensed under the BSD-style license found in the | ||
| 4 | +# LICENSE file in the root directory of this source tree. | ||
| 5 | + | ||
| 6 | +"""Keep known Triton launcher incompatibilities visible in every smoke entry point.""" | ||
| 7 | + | ||
| 8 | +from importlib import metadata | ||
| 9 | +from pathlib import Path | ||
| 10 | + | ||
| 11 | +import pytest | ||
| 12 | +from packaging.version import InvalidVersion, Version | ||
| 13 | + | ||
| 14 | +_CPP17_TRITON_RELEASES = frozenset({"3.2.1", "3.2.2", "3.2.2.post2", "3.6.0", "3.6.0.post2"}) | ||
| 15 | +_SMOKE_ROOT = Path(__file__).resolve().parent | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +def _triton_launcher_skip_reason(): | ||
| 19 | + try: | ||
| 20 | + torch_version = metadata.version("torch") | ||
| 21 | + triton_version = metadata.version("triton-ascend") | ||
| 22 | + torch_release = Version(torch_version).release | ||
| 23 | + triton_release = Version(triton_version) | ||
| 24 | + except (metadata.PackageNotFoundError, InvalidVersion): | ||
| 25 | + return None | ||
| 26 | + | ||
| 27 | + # These published releases were inspected directly. Unknown releases and | ||
| 28 | + # custom local builds must run normally so a new regression is not hidden. | ||
| 29 | + if ( | ||
| 30 | + torch_release < (2, 14) | ||
| 31 | + or triton_release.local is not None | ||
| 32 | + or triton_release.public not in _CPP17_TRITON_RELEASES | ||
| 33 | + ): | ||
| 34 | + return None | ||
| 35 | + | ||
| 36 | + return ( | ||
| 37 | + f"Triton-Ascend {triton_version} uses C++17 launcher compilation, but Torch {torch_version} requires C++20 " | ||
| 38 | + "(https://github.com/triton-lang/triton-ascend/issues/1411); " | ||
| 39 | + "use --run-unsupported-triton when validating a compiler fix" | ||
| 40 | + ) | ||
| 41 | + | ||
| 42 | + | ||
| 43 | +def pytest_collection_modifyitems(config, items): | ||
| 44 | + if config.getoption("--run-unsupported-triton", default=False): | ||
| 45 | + return | ||
| 46 | + reason = _triton_launcher_skip_reason() | ||
| 47 | + if reason is None: | ||
| 48 | + return | ||
| 49 | + skip = pytest.mark.skip(reason=reason) | ||
| 50 | + for item in items: | ||
| 51 | + if Path(item.path).resolve().is_relative_to(_SMOKE_ROOT) and item.get_closest_marker("triton_ascend"): | ||
| 52 | + item.add_marker(skip) | ||
| @@ -50,7 +50,7 @@ from torchtitan_npu.override.deepseek_v4.mhc.triton import ( | |||
| 50 | TritonHcPre, | 50 | TritonHcPre, |
| 51 | ) | 51 | ) |
| 52 | 52 | ||
| 53 | -pytestmark = pytest.mark.smoke | 53 | +pytestmark = [pytest.mark.smoke, pytest.mark.triton_ascend] |
| 54 | 54 | ||
| 55 | _BATCH = 1 | 55 | _BATCH = 1 |
| 56 | _SEQ_LEN = 96 | 56 | _SEQ_LEN = 96 |
| @@ -12,6 +12,7 @@ pytestmark = [ | |||
| 12 | ] | 12 | ] |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | +@pytest.mark.triton_ascend | ||
| 15 | def test_merged_gdn_forward_backward(): | 16 | def test_merged_gdn_forward_backward(): |
| 16 | from torchtitan_npu.ops.triton.gdn import gated_delta_rule | 17 | from torchtitan_npu.ops.triton.gdn import gated_delta_rule |
| 17 | 18 | ||
| @@ -0,0 +1,86 @@ | |||
| 1 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. | ||
| 2 | +# | ||
| 3 | +# This source code is licensed under the BSD-style license found in the | ||
| 4 | +# LICENSE file in the root directory of this source tree. | ||
| 5 | + | ||
| 6 | +"""Check pytest selection using CPU stand-ins, without executing NPU kernels.""" | ||
| 7 | + | ||
| 8 | +import os | ||
| 9 | +import shutil | ||
| 10 | +import subprocess | ||
| 11 | +import sys | ||
| 12 | +from pathlib import Path | ||
| 13 | + | ||
| 14 | +import pytest | ||
| 15 | + | ||
| 16 | +pytestmark = pytest.mark.tooling | ||
| 17 | +_REPO = Path(__file__).resolve().parents[3] | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +def _run_smoke(tmp_path, arguments, *, torch_version="2.14.0+cpu", triton_version="3.2.1"): | ||
| 21 | + for relative in ("tests/conftest.py", "tests/smoke_tests/conftest.py"): | ||
| 22 | + destination = tmp_path / relative | ||
| 23 | + destination.parent.mkdir(parents=True, exist_ok=True) | ||
| 24 | + shutil.copyfile(_REPO / relative, destination) | ||
| 25 | + (tmp_path / "pytest.ini").write_text("[pytest]\nmarkers =\n triton_ascend: Triton launcher case\n") | ||
| 26 | + (tmp_path / "tests/smoke_tests/test_selection.py").write_text( | ||
| 27 | + "import pytest\n@pytest.mark.triton_ascend\ndef test_triton():\n pass\ndef test_other():\n pass\n" | ||
| 28 | + ) | ||
| 29 | + distributions = tmp_path / "distributions" | ||
| 30 | + for name, version in (("torch", torch_version), ("triton-ascend", triton_version)): | ||
| 31 | + info = distributions / f"{name.replace('-', '_')}-{version}.dist-info" | ||
| 32 | + info.mkdir(parents=True) | ||
| 33 | + (info / "METADATA").write_text(f"Metadata-Version: 2.1\nName: {name}\nVersion: {version}\n\n") | ||
| 34 | + environment = dict( | ||
| 35 | + os.environ, | ||
| 36 | + PYTHONPATH=str(distributions), | ||
| 37 | + PYTEST_ADDOPTS="", | ||
| 38 | + PYTEST_DISABLE_PLUGIN_AUTOLOAD="1", | ||
| 39 | + TORCH_DEVICE_BACKEND_AUTOLOAD="0", | ||
| 40 | + OMP_NUM_THREADS="1", | ||
| 41 | + ) | ||
| 42 | + environment.pop("PYTHONHOME", None) | ||
| 43 | + return subprocess.run( | ||
| 44 | + [sys.executable, "-m", "pytest", "-q", "-rs", *arguments], | ||
| 45 | + cwd=tmp_path, | ||
| 46 | + env=environment, | ||
| 47 | + capture_output=True, | ||
| 48 | + text=True, | ||
| 49 | + timeout=30, | ||
| 50 | + ) | ||
| 51 | + | ||
| 52 | + | ||
| 53 | +@pytest.mark.parametrize( | ||
| 54 | + ("torch_version", "triton_version", "should_skip"), | ||
| 55 | + [ | ||
| 56 | + pytest.param("2.14.0+cpu", "3.2.1", True, id="torch214"), | ||
| 57 | + pytest.param("2.14.1", "3.2.1", True, id="torch214patch"), | ||
| 58 | + pytest.param("2.15.0", "3.6.0.post2", True, id="torch215"), | ||
| 59 | + pytest.param("2.14.0.dev20260920+cpu", "3.2.1", True, id="torch214dev"), | ||
| 60 | + pytest.param("2.13.0", "3.2.1", False, id="oldertorch"), | ||
| 61 | + pytest.param("2.15.0", "3.6.1", False, id="unlistedtriton"), | ||
| 62 | + pytest.param("2.15.0", "3.2.1+patched", False, id="localbuild"), | ||
| 63 | + ], | ||
| 64 | +) | ||
| 65 | +def test_known_cpp17_releases_skip_on_torch214_and_newer(tmp_path, torch_version, triton_version, should_skip): | ||
| 66 | + result = _run_smoke(tmp_path, ["tests"], torch_version=torch_version, triton_version=triton_version) | ||
| 67 | + | ||
| 68 | + assert result.returncode == 0, result.stdout + result.stderr | ||
| 69 | + assert ("1 passed, 1 skipped" if should_skip else "2 passed") in result.stdout | ||
| 70 | + if should_skip: | ||
| 71 | + assert "uses C++17" in result.stdout and torch_version in result.stdout | ||
| 72 | + | ||
| 73 | + | ||
| 74 | +@pytest.mark.parametrize("path", ["tests", "tests/smoke_tests"], ids=["parent", "smoke"]) | ||
| 75 | +def test_override_is_available_from_test_entrypoints(tmp_path, path): | ||
| 76 | + result = _run_smoke(tmp_path, [path, "-m", "triton_ascend", "--run-unsupported-triton"]) | ||
| 77 | + | ||
| 78 | + assert result.returncode == 0, result.stdout + result.stderr | ||
| 79 | + assert "1 passed" in result.stdout and "1 deselected" in result.stdout | ||
| 80 | + | ||
| 81 | + | ||
| 82 | +def test_bare_pytest_keeps_default_skip_when_option_is_not_registered(tmp_path): | ||
| 83 | + result = _run_smoke(tmp_path, []) | ||
| 84 | + | ||
| 85 | + assert result.returncode == 0, result.stdout + result.stderr | ||
| 86 | + assert "1 passed, 1 skipped" in result.stdout | ||