From 03642ab4caecc099b3784c2307ae173303c48832 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 30 Nov 2026 15:47:11 -0500 Subject: [PATCH] ci: select the nightly-pytorch tests with a torch marker The nightly-pytorch job ran a fixed list of files (tests/test_utils.py and tests/example_tests/), so the PyTorch tests in tests/test_utils_dlpack.py, added later, never ran anywhere. Register a "torch" marker in cuda_core/pytest.ini and apply it to every test that needs PyTorch: the five torch_module tests in test_utils_dlpack.py, two tests in test_utils.py, and the torch entries of its shared parametrize lists (through a small _torch_param helper). The nightly-pytorch job now runs `-m "torch or samples" tests/`, so a new torch test only needs the marker to be picked up. Closes #3594. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test-wheel-linux.yml | 2 +- .github/workflows/test-wheel-windows.yml | 2 +- cuda_core/pytest.ini | 1 + cuda_core/tests/test_utils.py | 35 ++++++++++++++---------- cuda_core/tests/test_utils_dlpack.py | 5 ++++ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test-wheel-linux.yml b/.github/workflows/test-wheel-linux.yml index 156827cc61c4..769466f26e19 100644 --- a/.github/workflows/test-wheel-linux.yml +++ b/.github/workflows/test-wheel-linux.yml @@ -456,7 +456,7 @@ jobs: if: ${{ inputs.test-mode == 'nightly-pytorch' }} run: | pushd cuda_core - pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" tests/test_utils.py tests/example_tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py" + pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" -m "torch or samples" tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py" popd - name: Checkout numba-cuda tests at matching tag diff --git a/.github/workflows/test-wheel-windows.yml b/.github/workflows/test-wheel-windows.yml index 63d50178e6ad..442c25793444 100644 --- a/.github/workflows/test-wheel-windows.yml +++ b/.github/workflows/test-wheel-windows.yml @@ -447,7 +447,7 @@ jobs: shell: bash --noprofile --norc -xeuo pipefail {0} run: | pushd cuda_core - pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" tests/test_utils.py tests/example_tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py" + pytest -rsxXfE -v --exclude-warning-annotations --junitxml "${GITHUB_WORKSPACE}/test-results/junit-pytorch-interop.xml" -m "torch or samples" tests/ | python "${GITHUB_WORKSPACE}/.ci-control/ci/tools/fold_pytest_sections.py" popd - name: Checkout numba-cuda tests at matching tag diff --git a/cuda_core/pytest.ini b/cuda_core/pytest.ini index 6c510783748a..53b0dfe8f213 100644 --- a/cuda_core/pytest.ini +++ b/cuda_core/pytest.ini @@ -21,6 +21,7 @@ filterwarnings = error::helpers.memory.BaselineMemoryResourceReleasedWarning markers = samples: tests for cuda.core standalone samples + torch: test needs PyTorch; the nightly-pytorch CI job selects tests by this marker # Keep this authorship marker registry in sync across all pytest config roots. # Search for "agent_authored(model)" before editing. agent_authored(model): agent-authored test not yet materially human-reviewed diff --git a/cuda_core/tests/test_utils.py b/cuda_core/tests/test_utils.py index 1e961e173ed0..7243f0c3bb4a 100644 --- a/cuda_core/tests/test_utils.py +++ b/cuda_core/tests/test_utils.py @@ -118,6 +118,11 @@ def _arr_dtype(arr): return arr.dtype +def _torch_param(*values, id): + """A pytest.param that needs PyTorch, so the nightly-pytorch CI job selects it.""" + return pytest.param(*values, id=id, marks=pytest.mark.torch) + + def _cpu_array_samples(): samples = [ np.empty(3, dtype=np.int32), @@ -132,16 +137,16 @@ def _cpu_array_samples(): ] if torch is not None: samples += [ - pytest.param(torch.arange(12, dtype=torch.float32), id="torch-1d"), - pytest.param(torch.arange(24, dtype=torch.float32).reshape(2, 3, 4), id="torch-nd"), - pytest.param(torch.tensor(42.0), id="torch-scalar"), - pytest.param(torch.empty(0, dtype=torch.float32), id="torch-empty"), - pytest.param( + _torch_param(torch.arange(12, dtype=torch.float32), id="torch-1d"), + _torch_param(torch.arange(24, dtype=torch.float32).reshape(2, 3, 4), id="torch-nd"), + _torch_param(torch.tensor(42.0), id="torch-scalar"), + _torch_param(torch.empty(0, dtype=torch.float32), id="torch-empty"), + _torch_param( torch.arange(12, dtype=torch.float32).reshape(3, 4).t(), id="torch-non-contiguous", ), - pytest.param(torch.arange(100, dtype=torch.int64)[10:20], id="torch-sliced"), - pytest.param( + _torch_param(torch.arange(100, dtype=torch.int64)[10:20], id="torch-sliced"), + _torch_param( torch.arange(60, dtype=torch.float32).reshape(6, 10)[1:4, 2:7], id="torch-sliced-2d", ), @@ -206,25 +211,25 @@ def gpu_array_samples(): ] if torch is not None: samples += [ - pytest.param(torch.arange(12, dtype=torch.float32, device="cuda"), True, id="torch-1d"), - pytest.param( + _torch_param(torch.arange(12, dtype=torch.float32, device="cuda"), True, id="torch-1d"), + _torch_param( torch.arange(24, dtype=torch.float32, device="cuda").reshape(2, 3, 4), True, id="torch-nd", ), - pytest.param(torch.tensor(42.0, dtype=torch.float32, device="cuda"), False, id="torch-scalar"), - pytest.param(torch.empty(0, dtype=torch.float32, device="cuda"), False, id="torch-empty"), - pytest.param( + _torch_param(torch.tensor(42.0, dtype=torch.float32, device="cuda"), False, id="torch-scalar"), + _torch_param(torch.empty(0, dtype=torch.float32, device="cuda"), False, id="torch-empty"), + _torch_param( torch.arange(12, dtype=torch.float32, device="cuda").reshape(3, 4).t(), True, id="torch-non-contiguous", ), - pytest.param( + _torch_param( torch.arange(100, dtype=torch.int64, device="cuda")[10:20], True, id="torch-sliced", ), - pytest.param( + _torch_param( torch.arange(60, dtype=torch.float32, device="cuda").reshape(6, 10)[1:4, 2:7], True, id="torch-sliced-2d", @@ -762,6 +767,7 @@ def test_ml_dtypes_bfloat16_dlpack(init_cuda, slices): ) @pytest.mark.skipif(ml_dtypes is None, reason="ml_dtypes is not installed") @pytest.mark.skipif(torch is None, reason="PyTorch is not installed") +@pytest.mark.torch def test_ml_dtypes_bfloat16_torch_dlpack(init_cuda, slices): a = torch.tensor([1, 2, 3, 4, 5, 6], dtype=torch.bfloat16, device="cuda").reshape(2, 3)[slices] smv = StridedMemoryView.from_dlpack(a, stream_ptr=0) @@ -975,6 +981,7 @@ def test_array_interface_mask_rejected(): ), ], ) +@pytest.mark.torch def test_torch_tensor_bridge_dtypes(init_cuda, dtype): """Verify that dtype mapping via the tensor bridge matches torch's own dtype.""" torch_dtype = getattr(torch, dtype) diff --git a/cuda_core/tests/test_utils_dlpack.py b/cuda_core/tests/test_utils_dlpack.py index 3f26919080a8..b8555a0ad36e 100644 --- a/cuda_core/tests/test_utils_dlpack.py +++ b/cuda_core/tests/test_utils_dlpack.py @@ -366,6 +366,7 @@ def torch_module(): @pytest.mark.parametrize("module", ["application_adapter", "torch_adapter", "torch.adapters", "torchvision.adapters"]) @pytest.mark.parametrize("has_data_ptr", [False, True]) @pytest.mark.agent_authored(model="gpt-6") +@pytest.mark.torch def test_protocol_adapter_uses_protocol_on_first_and_cached_import(entry, module, has_data_ptr, torch_module): """Non-Tensor adapters retain their protocol routing on repeated imports.""" @@ -401,6 +402,7 @@ def array_interface(self): @pytest.mark.parametrize("entry", ["from_dlpack", "from_any_interface"]) @pytest.mark.parametrize("legacy_dlpack", [False, True]) @pytest.mark.agent_authored(model="gpt-6") +@pytest.mark.torch def test_class_proxy_is_not_a_native_tensor(entry, legacy_dlpack, torch_module): """A proxy advertising Tensor through __class__ still uses its DLPack protocol.""" from cuda_python_test_helpers.subprocess_runner import run_python_snippet @@ -447,6 +449,7 @@ def __dlpack__(self, **kwargs): [(None, False), ("torch_custom", False), ("application_tensor", False), ("application_tensor", True)], ) @pytest.mark.agent_authored(model="gpt-6") +@pytest.mark.torch def test_real_tensor_and_subclasses_keep_existing_routes(entry, module, legacy_dlpack, torch_module): """Real Tensors and subclasses preserve their data and existing import routes.""" torch = torch_module @@ -476,6 +479,7 @@ def dlpack(self, **kwargs): @pytest.mark.parametrize("entry", ["from_cuda_array_interface", "from_any_interface"]) @pytest.mark.parametrize("module", ["application_cuda", "torch_cuda_adapter", "torchvision.adapters"]) @pytest.mark.agent_authored(model="gpt-6") +@pytest.mark.torch def test_cuda_adapter_uses_real_device_storage(init_cuda, entry, module, torch_module): """Torch-looking CAI adapters import real device storage through their protocol.""" source = np.arange(4, dtype=np.int32) @@ -589,6 +593,7 @@ def __array_interface__(self): @pytest.mark.agent_authored(model="gpt-6") +@pytest.mark.torch def test_torch_tensor_type_lookup_is_cached(torch_module): """Distinct candidate types reuse Torch metadata after a protocol-only import.""" from cuda_python_test_helpers.subprocess_runner import run_python_snippet