Skip to content

ci: select the nightly-pytorch tests with a torch marker - #3666

Open
mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:issue3594
Open

mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:issue3594

Conversation

@mdboom

@mdboom mdboom commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Closes #3594. Part of #2077.

Summary

The nightly-pytorch job selected its tests by file name (tests/test_utils.py tests/example_tests/), so the PyTorch tests in tests/test_utils_dlpack.py (#3499: 5 tests, 43 cases) were never collected there, and they skip everywhere else because PyTorch isn't installed. This PR selects by what the tests need instead:

 cuda_core/pytest.ini
+    torch: test needs PyTorch; the nightly-pytorch CI job selects tests by this marker

 .github/workflows/test-wheel-{linux,windows}.yml  (nightly-pytorch)
-    pytest ... tests/test_utils.py tests/example_tests/
+    pytest ... -m "torch or samples" tests/

Tests marked torch:

  • test_utils_dlpack.py: the five tests that use the torch_module fixture.
  • test_utils.py: test_ml_dtypes_bfloat16_torch_dlpack, test_torch_tensor_bridge_dtypes, and the torch entries of the shared CPU/GPU parametrize lists, through a small _torch_param(...) helper so the numpy/CuPy/Numba cases of the same tests stay unmarked.

Notes:

  • samples is the existing marker on test_sample, so the job still runs the samples.
  • pytest.ini already has norecursedirs = cython, so collecting tests/ doesn't touch the Cython tests this job doesn't build.
  • The job no longer runs the non-torch tests in test_utils.py or the sample-harness unit tests; those run in standard CI.
  • test_protocol_import_does_not_load_torch and test_protocol_import_keeps_unrelated_torch_module_lazy are intentionally unmarked: they check that torch is not imported and run in standard CI.
  • CI: install the packages never-run samples need in the nightly-pytorch job #3578 also changes what this job installs; with marker selection, the two changes don't conflict.

Evidence

Locally (PyTorch 2.14.1+cu130, CUDA available, cuda.core built from main):

  • -m torch selects 106 cases: 63 in test_utils.py, 43 in test_utils_dlpack.py. 99 pass; 7 skip only because CuPy isn't installed locally (the nightly job installs it via test-cu13).
  • -m "torch or samples" selects 150 cases (adds the 44 test_sample cases).
  • The only torch-named cases left unmarked are the two "doesn't load torch" tests above.

Confirming in CI: this job only runs in the nightly workflow (PyTorch 2.9.1 and 2.15.0, Linux and Windows), so it has to be started by hand (needs write access to NVIDIA/cuda-python):

  1. Wait for this PR's CI workflow run to finish successfully and note its run ID (.../actions/runs/<run-id>).

  2. Start the nightly workflow on this PR's mirror branch with that run ID:

    gh workflow run ci-nightly.yml --repo NVIDIA/cuda-python --ref pull-request/<PR number> -f run-id=<run-id>
    
  3. In the nightly-pytorch jobs (Linux and Windows), confirm the five test_utils_dlpack.py tests PASSED, for example:

    gh run view <nightly run id> --repo NVIDIA/cuda-python --log | grep -E "test_utils_dlpack.py::test_(protocol_adapter_uses_protocol_on_first_and_cached_import|real_tensor_and_subclasses_keep_existing_routes|cuda_adapter_uses_real_device_storage|class_proxy_is_not_a_native_tensor|torch_tensor_type_lookup_is_cached)"
    

Merge Danger

Door: two-way.

Blast Radius: the nightly-pytorch job's test selection, plus marker-only changes in two test files (standard CI runs the same tests as before).

Reviewers: please feel free to push commits directly to this PR to improve it.

🤖 Generated with Claude Code

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 NVIDIA#3594.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdboom mdboom added this to the CI milestone Nov 30, 2026
@mdboom mdboom added CI/CD CI/CD infrastructure test Improvements or additions to tests cuda.core Everything related to the cuda.core module labels Nov 30, 2026
@mdboom mdboom self-assigned this Nov 30, 2026
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • Tests
    • Nightly PyTorch interop test runs on Linux and Windows now select tests marked for PyTorch or sample cases across the test suite.
    • PyTorch-dependent tests and sample cases are labeled consistently for these runs.
    • Test execution continues to produce JUnit reports and folded output.

The nightly Linux and Windows PyTorch jobs now discover tests under tests/ using the torch or samples markers. PyTorch-dependent cases in test_utils.py and test_utils_dlpack.py now carry the torch marker.

Changes: Nightly PyTorch test selection

Layer / File(s) Summary
Mark PyTorch-dependent tests
cuda_core/pytest.ini, cuda_core/tests/test_utils.py, cuda_core/tests/test_utils_dlpack.py
The marker registry declares torch. PyTorch-dependent parameters and tests use that marker.
Select marked tests in nightly jobs
.github/workflows/test-wheel-linux.yml, .github/workflows/test-wheel-windows.yml
Both jobs discover tests across tests/ and select tests marked torch or samples.

Assessment against linked issues

Objective Addressed Explanation
Run the PyTorch-dependent tests in test_utils_dlpack.py in the nightly-pytorch jobs (3594) ✅

Possibly related issues

  • Issue 3578: The nightly job’s marker selection includes samples, matching the issue’s concern about sample tests selected by that job.
  • Issue 3597: The new torch marker makes PyTorch-dependent tests selectable by the nightly job, addressing the cited test-discovery gap.

Suggested reviewers: leofang, rwgk

Change: Other · Severity of issue fixed: Low

Merge Risk: Moderate · up to 03642

The nightly PyTorch jobs can report success without running the DLPack tests this change targets, if the tests checkout predates the new markers. The selection change is otherwise small and reversible. Make the step fail when the target tests are not selected, or keep the tests checkout compatible with the workflow, before relying on the nightly result.

Security architecture risk: Minimal · up to 03642

The change updates test selection in the existing Linux and Windows nightly jobs. Its demonstrated effect is on test coverage, not on production behavior or access permissions.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Finishing Touches
Fix failing CI checks

  • Create a new PR

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fb1fc2a and 03642ab.

Files selected for processing: 5

  • .github/workflows/test-wheel-linux.yml
  • .github/workflows/test-wheel-windows.yml
  • cuda_core/pytest.ini
  • cuda_core/tests/test_utils.py
  • cuda_core/tests/test_utils_dlpack.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 6 remain after this review.

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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Functional Correctness · Heavy lift

important: Nightly PyTorch runs can pass without the DLPack tests.

The nightly-pytorch step runs the workflow file from the nightly run's ref. It checks out tests at inputs.sha, which is the head of the latest successful main CI run. If that tests revision predates the torch marks, -m "torch or samples" omits all five DLPack tests. The step still passes when a sample test is selected and passes. The same applies to the Windows step.

The nightly workflow can start from a PR branch or from a main commit that is newer than the pinned tests revision. In both cases the workflow file and the tests can come from different revisions.

The nightly-pytorch step must not pass when the DLPack tests are not selected. Choose a mechanism that guarantees this for any tests revision the nightly run can check out.

@mdboom
mdboom requested review from leofang and rluo8 November 30, 2026 20:55
@github-actions

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD CI/CD infrastructure cuda.core Everything related to the cuda.core module test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI: nightly-pytorch does not run the torch tests in cuda_core/tests/test_utils_dlpack.py

1 participant