Skip to content

build: bypass Torch CUDA discovery without nvcc#5558

Queued
njzjz-bot wants to merge 2 commits into
deepmodeling:masterfrom
njzjz-bothub:openclaw/bypass-torch-cuda-check
Queued

build: bypass Torch CUDA discovery without nvcc#5558
njzjz-bot wants to merge 2 commits into
deepmodeling:masterfrom
njzjz-bothub:openclaw/bypass-torch-cuda-check

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a DEEPMD_BYPASS_TORCH_CUDA_CHECK CMake option, enabled by default.
  • When DeePMD-kit is not building CUDA support and nvcc is unavailable, predefine an imported torch::cudart target before find_package(Torch).
  • Document the new CMake option.

Motivation

CUDA-enabled PyTorch wheels can force CMake CUDA toolkit discovery from TorchConfig.cmake, even for CPU-only DeePMD-kit PyTorch builds. This mirrors the workaround used in deepmd-gnn so CPU-only builds do not require a local CUDA compiler.

Tests

  • uvx pre-commit run --files source/CMakeLists.txt doc/install/install-from-source.md
  • cmake -S source -B /tmp/deepmd-kit-cmake-bypass-test -DENABLE_PYTORCH=ON -DBUILD_CPP_IF=OFF -DBUILD_PY_IF=ON -DCMAKE_PREFIX_PATH=/tmp/deepmd-kit-fake-torch -DUSE_CUDA_TOOLKIT=OFF -DCMAKE_BUILD_TYPE=Release
  • Verified the same fake Torch configuration fails with -DDEEPMD_BYPASS_TORCH_CUDA_CHECK=OFF, confirming the shim is what unblocks find_package(Torch).

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)

Summary by CodeRabbit

  • Documentation

    • Added an installation guide entry documenting a new configuration option that controls PyTorch CUDA toolkit discovery behavior.
  • New Features

    • Introduced a configuration option to better support CPU-only builds by bypassing PyTorch’s CUDA toolkit discovery when CUDA is unavailable.

Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
@dosubot dosubot Bot added the build label Jun 19, 2026
@github-actions github-actions Bot added the Docs label Jun 19, 2026
@coderabbitai

coderabbitai Bot commented Jun 19, 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: 211707cd-3264-45c1-9b02-2f9e89af6194

📥 Commits

Reviewing files that changed from the base of the PR and between 97ed2e7 and ed36315.

📒 Files selected for processing (2)
  • doc/install/install-from-source.md
  • source/CMakeLists.txt
✅ Files skipped from review due to trivial changes (1)
  • doc/install/install-from-source.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/CMakeLists.txt

📝 Walkthrough

Walkthrough

A new CMake boolean option DEEPMD_BYPASS_TORCH_CUDA_CHECK (default ON) is added to source/CMakeLists.txt. When enabled and CUDA support is not being built, it searches for nvcc; if not found and torch::cudart is absent, it creates a stub INTERFACE IMPORTED library target to prevent PyTorch's CUDA toolkit discovery from failing. The option is also documented in the installation guide.

Changes

PyTorch CUDA bypass option

Layer / File(s) Summary
CMake option declaration and torch::cudart stub
source/CMakeLists.txt
Declares DEEPMD_BYPASS_TORCH_CUDA_CHECK option (default ON) at the beginning of the file, then conditionally defines torch::cudart as an INTERFACE IMPORTED target when USE_CUDA_TOOLKIT is false, PyTorch is enabled, and nvcc cannot be found.
Installation guide documentation
doc/install/install-from-source.md
Adds a table entry for DEEPMD_BYPASS_TORCH_CUDA_CHECK describing its type (BOOL), default value (ON), and the behavior it controls: bypassing PyTorch CUDA toolkit discovery when a local CUDA compiler is unavailable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • wanghan-iapcm
🚥 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 and concisely summarizes the main change: introducing a mechanism to bypass PyTorch's CUDA discovery when nvcc is unavailable.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@njzjz njzjz requested a review from wanghan-iapcm June 19, 2026 16:16
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.14%. Comparing base (1050e46) to head (ed36315).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5558      +/-   ##
==========================================
- Coverage   82.16%   82.14%   -0.03%     
==========================================
  Files         896      900       +4     
  Lines      102643   104140    +1497     
  Branches     4340     4474     +134     
==========================================
+ Hits        84341    85550    +1209     
- Misses      16965    17180     +215     
- Partials     1337     1410      +73     

☔ 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.

Comment thread source/CMakeLists.txt Outdated
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)

@njzjz njzjz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

— Opus 4.8

@njzjz njzjz closed this Jun 22, 2026
@njzjz njzjz reopened this Jun 22, 2026
@njzjz njzjz requested a review from wanghan-iapcm June 22, 2026 18:42
@wanghan-iapcm wanghan-iapcm enabled auto-merge June 23, 2026 02:37
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Jun 23, 2026
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