Skip to content

Automate PyPI releases with prebuilt CUDA wheels - #122

Merged
ZedongPeng merged 3 commits into
MIT-Lu-Lab:mainfrom
ZedongPeng:pypi-wheels
Nov 30, 2026
Merged

ZedongPeng merged 3 commits into
MIT-Lu-Lab:mainfrom
ZedongPeng:pypi-wheels

Conversation

@ZedongPeng

@ZedongPeng ZedongPeng commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #121

Summary

Automate PyPI releases with a GitHub Actions workflow (.github/workflows/wheels.yml). Until now, PyPI only had sdists of cupdlpx, so every pip install compiled cuPDLPx locally and needed a CUDA toolkit.

With this PR:

  • Publishing a GitHub release publishes to PyPI. The workflow builds the wheels and the sdist, tests them, checks the version, and uploads through PyPI trusted publishing, so no API token is stored in the repository. Publishing waits for approval in the pypi environment.
  • A manual run publishes to TestPyPI, so a release can be tried before it goes out.
  • Every pull request that touches the build builds and tests the wheels, so packaging breakage shows up before release.
  • Users get prebuilt wheels for Linux x86_64 and aarch64, CPython 3.11–3.15. pip install cupdlpx then needs only an NVIDIA driver.

Shipping prebuilt CUDA binaries needs a few supporting changes:

  • cupdlpx is built with CUDA 13 and gets the CUDA libraries from the cuda-toolkit pip packages (>=13.0,<14). This range lets it share an environment with PyTorch and other CUDA 13 packages. It requires an R580+ driver and compute capability 7.5+.
  • cupdlpx-cu12 is an optional CUDA 12 backend, installed with pip install "cupdlpx[cu12]", for drivers that only support CUDA 12.4–12.x and GPUs with compute capability 5.0–7.2. The import name is always cupdlpx, and the backend is chosen automatically at import.
  • A CUDA 13.3+ build now chooses cusparseSpMVOp or cusparseSpMV at run time, because the CUDA 13 runtime in a user's environment may be older than 13.3.
  • The version is bumped to 0.4.1. The existing v0.4.0 GitHub release points to d17f53e, which has no wheel workflow, so 0.4.0 can no longer be published from this pipeline.

Release workflow (.github/workflows/wheels.yml)

Trigger What runs
Pull request touching the build cp312 wheels for both packages and both architectures, integration tests, sdist
Manual run (workflow_dispatch) All wheels (cp311–cp315) and the sdist, then upload to TestPyPI
GitHub release published All wheels and the sdist, version checks, then upload to PyPI after approval
  • wheels: cibuildwheel on manylinux_2_28, a 2×2 matrix (x86_64 / aarch64 × CUDA 13.5 / 12.9). CUDA comes from NVIDIA's RHEL 8 repo. auditwheel excludes the CUDA libraries.
  • integration (one job per architecture):
    • Checks that both wheels resolve together with torch.
    • Checks backend selection, including the case where CUDA 12 cuSPARSE is loaded first.
    • Runs test/test_loader.py.
    • Imports both backends against the oldest supported runtimes (CUDA 13.0 and 12.4).
  • sdist: on release, checks that the pyproject, CMake and tag versions match and that neither project already has that version on PyPI.
  • Publishing:
    • Trusted publishing, behind the testpypi / pypi environments.
    • Publishing waits for the wheels, integration and sdist jobs.
    • A failed upload can be retried with "Re-run failed jobs": PyPI accepts an identical file again and rejects a different file with the same name.

Backend selection (python/cupdlpx/_core.py)

import cupdlpx loads the first usable backend, CUDA 13 first, then CUDA 12. It checks three things:

  • Driver version. Read with cuDriverGetVersion. CUDA 13 needs a 13.0+ driver; CUDA 12 needs 12.4+.
  • Compute capability of CUDA device 0. cuPDLPx always runs on device 0. The capability comes from NVML, so CUDA is not initialized at import and forked child processes can still use the GPU.
    • Devices that NVML cannot access because of permissions are skipped, since CUDA cannot see them either (e.g. Slurm cgroups).
    • On a node whose visible GPUs differ in compute capability, a short subprocess queries device 0 through the Driver API. It respects CUDA_VISIBLE_DEVICES and CUDA_DEVICE_ORDER.
  • cuSPARSE already loaded in the process. CUDA 12 and CUDA 13 both ship libcusparse.so.12, so a copy loaded by another package (e.g. PyTorch) takes priority. The loader reads its version from /proc/self/maps and cusparseGetProperty, then rejects a backend from the other CUDA generation (< 12.6 is CUDA 12, ≥ 12.6 is CUDA 13) or one older than its minimum. It rescans before each candidate.

When a backend is selected, its pip CUDA libraries are preloaded with RTLD_LOCAL. CUPDLPX_BACKEND=cu13|cu12|source forces a choice; a forced backend skips the driver and GPU checks but still gets the cuSPARSE check. If no backend fits, the ImportError lists the reason for each backend and the install command.

Runtime SpMV backend (src/spmv_backend.cu)

A build against cuSPARSE ≥ 12.8.1 (CUDA 13.3+) now chooses the SpMV backend at run time instead of compile time:

  • It uses cusparseSpMVOp when the loaded cuSPARSE is ≥ 12.8.1, and cusparseSpMV otherwise (e.g. the CUDA 13.0–13.2 runtime that PyTorch pins).
  • The SpMVOp entry points are declared weak. CPython loads extensions with RTLD_NOW, so strong references would fail at import on an older cuSPARSE.
  • Builds without SpMVOp and HIP builds are unchanged.

Packaging and build

  • python/metadata_provider.py (scikit-build-core dynamic metadata): adds the cuda-toolkit dependency only for wheel builds (CUPDLPX_WHEEL_CUDA), and adds the cu12 extra pinned to the same version.
  • python/cupdlpx_cu12/pyproject.toml: builds the same sources into the cupdlpx_cu12 package, depending on nvidia-*-cu12 (≥ 12.4).
  • CMake:
    • PSLP is built static for the Python module.
    • The RPATH points at the pip CUDA library directories.
    • A generated _build_info.py records the package version, CUDA version, cuSPARSE version and pip CUDA major.
    • Only the python install component goes into the wheel.
    • Configuring without a CUDA toolkit now fails with a clear message.
  • The sdist includes only .py files from python/, so bytecode caches are no longer packaged.
  • requires-python is now >=3.11.

Testing

Local wheels (CUDA 13.3 and 12.9 builds), H100 with driver 595 (CUDA 13.2):

Scenario Backend SpMV Result
CUDA 13.3 pip runtime cu13 SpMVOp OPTIMAL
CUDA 13.0 pip runtime (cuSPARSE 12.6.3) cu13 SpMV OPTIMAL
CUPDLPX_BACKEND=cu12 cu12 SpMV OPTIMAL
CUDA 12 cuSPARSE loaded first (RTLD_GLOBAL) cu12 SpMV OPTIMAL
CUDA 13.0 cuSPARSE loaded first, 13.3 runtime installed cu13 (single cuSPARSE copy) SpMV OPTIMAL
  • pytest test/ (142 tests, including 22 new loader tests) passes for CUDA 13.3 auto, forced cu12, and CUDA 13.0 auto.
  • On a driver 12.4 node, the loader falls back to cu12.
  • pip install --dry-run resolves together with PyPI torch 2.15 (which pins cuda-toolkit==13.2.2) and with torch cu128.
  • spmv_backend.cu compiles with CUDA 12.4, 12.9, 13.1 and 13.3.

Not verified yet:

  • The workflow itself has not run on GitHub.
  • CUDA 13.5 builds, aarch64, real pre-Turing GPUs, and mixed-GPU nodes are untested.
  • CI wheels still need a manual GPU run before release.

Setup needed before publishing

  1. On PyPI and on TestPyPI:
    • Add a trusted publisher to cupdlpx: owner MIT-Lu-Lab, repository cuPDLPx, workflow wheels.yml, environment pypi (testpypi on TestPyPI).
    • Add a pending publisher with the same settings for cupdlpx-cu12.
  2. Create the GitHub environments pypi (with required reviewers) and testpypi.
  3. After merging, run the workflow manually to publish to TestPyPI and test the install. Then create release v0.4.1 to publish to PyPI.

Build manylinux wheels for Linux x86_64 and aarch64 with cibuildwheel and
publish them with trusted publishing: TestPyPI on manual dispatch, PyPI on
release.

- cupdlpx is built with CUDA 13 and loads the CUDA runtime from the
  cuda-toolkit pip packages (>=13.0,<14), so it can share an environment
  with PyTorch and other CUDA 13 packages.
- cupdlpx-cu12 is an optional CUDA 12 backend installed with
  cupdlpx[cu12] for drivers older than R580 and GPUs older than Turing.
- import cupdlpx picks a backend from the driver version, GPU 0 and any
  cuSPARSE already loaded in the process; CUPDLPX_BACKEND forces one.
- A build with cuSPARSE 12.8.1+ headers now chooses cusparseSpMVOp or
  cusparseSpMV at run time from the loaded cuSPARSE version.
- Bump the version to 0.4.1.
Keep the dynamic metadata provider and the cupdlpx-cu12 project next to the
Python package, and include only Python sources from python/ in the sdist so
bytecode caches are not packaged.
Use python/ as the dynamic metadata provider path and python/cupdlpx_cu12 as
the cupdlpx-cu12 package directory, and include only Python sources from
python/ in the sdist so bytecode caches are not packaged.
@ZedongPeng ZedongPeng changed the title Publish prebuilt wheels to PyPI Automate PyPI releases with prebuilt CUDA wheels Nov 30, 2026
@ZedongPeng
ZedongPeng merged commit 2638585 into MIT-Lu-Lab:main Nov 30, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pypi release not keeping pace with github release

1 participant