Skip to content

ci(package-c): build pytorch plugin without bundled runtime#5706

Merged
wanghan-iapcm merged 2 commits into
deepmodeling:masterfrom
njzjz:ci/package-c-pytorch-runtime-external
Jul 5, 2026
Merged

ci(package-c): build pytorch plugin without bundled runtime#5706
wanghan-iapcm merged 2 commits into
deepmodeling:masterfrom
njzjz:ci/package-c-pytorch-runtime-external

Conversation

@njzjz

@njzjz njzjz commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

  • build the C package in the manylinux_2_28 CUDA 12.9 image and install TensorFlow/PyTorch from dependency groups
  • package the PyTorch backend plugin while excluding libtorch/CUDA runtime libraries from the tarball
  • add package README/download_libtorch.sh guidance and update C package tests for external PyTorch runtime
  • avoid CUDA 12.9 CCCL failures from -arch=all by using all-major as the CUDA 12.9 default

Tests

  • ruff check .
  • ruff format .
  • git diff --check
  • sh -n source/install/package_c.sh
  • bash -n source/install/docker_package_c.sh
  • bash -n source/install/docker_test_package_c.sh
  • fork CI on bbcd58d: Build C library, Build C++, Build/upload to PyPI, CodeQL, Test C++, and Test Python all passed

Fork CI: https://github.com/njzjz/deepmd-kit/actions/runs/28547373402

Summary by CodeRabbit

  • New Features
    • Expanded C library packaging and installation to support PyTorch in addition to TensorFlow and JAX.
    • When PyTorch is enabled, the package can generate a matching libtorch download helper and runtime setup guidance.
  • Bug Fixes
    • Added stronger packaging verification to ensure required shared libraries are present and to prevent accidental bundling of PyTorch/CUDA runtime libraries.
  • Documentation
    • Updated C library installation docs with PyTorch version/compatibility guidance and runtime environment setup (including LD_LIBRARY_PATH).

Copilot AI review requested due to automatic review settings July 1, 2026 22:11
@dosubot dosubot Bot added the build label Jul 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 965ac2bd-7b78-4817-a4a2-e4b91c9b9175

📥 Commits

Reviewing files that changed from the base of the PR and between bbcd58d and 5a6ded6.

📒 Files selected for processing (2)
  • source/install/package_c.sh
  • source/lib/src/gpu/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/install/package_c.sh

📝 Walkthrough

Walkthrough

This PR updates the C library packaging pipeline for PyTorch runtime handling, adds container and CI checks around the packaged tarball, revises the installation guide, and changes the CUDA architecture default selection.

Changes

PyTorch-aware packaging pipeline

Layer / File(s) Summary
Runtime dependency filtering
source/api_c/CMakeLists.txt
Adds cached pre- and post-exclude regex variables, rebuilds the runtime library list, passes the computed values into the install script, and installs resolved runtime dependencies and packaged targets into the C library output tree.
Package script and libtorch helper generation
source/install/package_c.sh
Updates path handling, probes Python and CUDA runtime inputs, parameterizes the CMake invocation, derives a PyTorch download URL when needed, and generates the README and download_libtorch.sh helper inside the staged C library archive.
Docker packaging container
source/install/docker_package_c.sh
Switches to a configurable manylinux CUDA image, passes PyTorch and TensorFlow dependency settings into the container, and installs dependencies with uv before invoking package_c.sh.
Docker test runtime checks
source/install/docker_test_package_c.sh
Uses a manylinux 2.28 image, builds and runs the C examples, and optionally validates bundled PyTorch runtime loading with ldd and ctypes.CDLL when CHECK_PYTORCH_RUNTIME is set.
CI validation and installation docs
.github/workflows/package_c.yml, doc/install/install-from-c-library.md
Adds PyTorch runtime exclusion regexes, enables PyTorch packaging, verifies tarball contents, records a download URL note, turns on runtime checks, and updates the install guide for PyTorch backend support and libtorch helper usage.

CUDA architecture default

Layer / File(s) Summary
CUDA toolkit version-based architecture default
source/lib/src/gpu/CMakeLists.txt
Moves CUDA toolkit discovery before architecture defaulting and sets the default architecture to all-major for CUDA toolkit versions 12.9 through below 14.0, otherwise all.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested reviewers: wanghan-iapcm, iProzd

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: packaging the PyTorch C plugin without bundling its runtime libraries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@source/install/package_c.sh`:
- Around line 119-215: The PyTorch runtime URL derivation in package_c.sh can
fail silently when ENABLE_PYTORCH is true but PYTHON_BIN is missing or the torch
version heuristic does not produce a supported URL. Add a clear warning or
diagnostic in the URL-generation block before the README and
download_libtorch.sh generation is skipped, using the existing
PYTORCH_RUNTIME_DOWNLOAD_URL, ENABLE_PYTORCH, and PYTHON_BIN checks to explain
why no PyTorch runtime package was emitted. Keep the warning tied to the same
install-script flow so local/manual runs surface the missing libtorch packaging
immediately.
- Around line 122-138: The libtorch URL generation in the torch version handling
logic is stripping nightly `.devYYYYMMDD` data by splitting on `.dev`, so fix
the version parsing in the package_c script to preserve the full nightly version
string when building the download URL. Update the `version`/`variant` extraction
path around the `torch.__version__` and `torch.version.cuda` handling so nightly
builds keep their `.dev` suffix while still producing the correct `cpu` or `cu*`
libtorch archive name.

In `@source/lib/src/gpu/CMakeLists.txt`:
- Around line 9-17: The CUDA architecture fallback in CMakeLists.txt is too
narrow because the `all-major` branch in the `find_package(CUDAToolkit)` /
`CMAKE_CUDA_ARCHITECTURES` logic stops at CUDA 12.x. Update the version check so
the `all-major` fallback also applies to CUDA 13.x, keeping the existing
`CUDAToolkit_VERSION` guard and the `set(CMAKE_CUDA_ARCHITECTURES ...)` logic in
place while extending the upper bound appropriately.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3872c764-c654-40a6-9a12-928f465e34ab

📥 Commits

Reviewing files that changed from the base of the PR and between 42de67e and bbcd58d.

📒 Files selected for processing (7)
  • .github/workflows/package_c.yml
  • doc/install/install-from-c-library.md
  • source/api_c/CMakeLists.txt
  • source/install/docker_package_c.sh
  • source/install/docker_test_package_c.sh
  • source/install/package_c.sh
  • source/lib/src/gpu/CMakeLists.txt

Comment thread source/install/package_c.sh
Comment thread source/install/package_c.sh
Comment thread source/lib/src/gpu/CMakeLists.txt
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.15%. Comparing base (ee30956) to head (5a6ded6).
⚠️ Report is 20 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5706      +/-   ##
==========================================
- Coverage   81.20%   81.15%   -0.05%     
==========================================
  Files         978      990      +12     
  Lines      108858   111018    +2160     
  Branches     4139     4237      +98     
==========================================
+ Hits        88393    90101    +1708     
- Misses      18946    19390     +444     
- Partials     1519     1527       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@njzjz njzjz marked this pull request as draft July 2, 2026 05:38
@njzjz njzjz marked this pull request as ready for review July 5, 2026 12:50
@dosubot dosubot Bot added the enhancement label Jul 5, 2026
@njzjz njzjz requested a review from wanghan-iapcm July 5, 2026 13:05
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Jul 5, 2026
Merged via the queue into deepmodeling:master with commit 8de6596 Jul 5, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants