Skip to content

fix(pt): support PyTorch 2.14 C++20 builds - #6049

Merged
iProzd merged 6 commits into
deepmodeling:masterfrom
njzjz-bot:fix/6048-pytorch-2.14-cxx20
Oct 14, 2026
Merged

iProzd merged 6 commits into
deepmodeling:masterfrom
njzjz-bot:fix/6048-pytorch-2.14-cxx20

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • raise the DeePMD C++ standard to C++20 when building against PyTorch 2.14 or newer
  • keep the existing C++17/C++14 behavior for older supported PyTorch versions
  • skip building custom PyTorch operators in Read the Docs, since the docs do not execute them

This fixes both sides of #6048: the underlying PyTorch 2.14 source-build incompatibility and the immediate RTD failure. The RTD setting is the same targeted workaround already observed to produce green documentation builds in #5961.

Validation

  • exercised the CMake version-selection logic for PyTorch 1.5, 2.0, 2.1, 2.13, 2.14, 2.14.1, and 3.0
  • verified an explicitly higher user C++ standard is not lowered
  • compared the branch against current master: only .readthedocs.yml and source/CMakeLists.txt change

Fixes #6048.

Agent: ChatGPT
Model: GPT-5.6 Sol

Summary by CodeRabbit

  • Documentation
    • Documentation builds install requirements without enabling PyTorch operators.
  • Compatibility
    • Builds with PyTorch 2.14 and newer use C++20. PyTorch 2.1 through 2.13 uses C++17, while versions 1.5 through earlier than 2.1 use C++14.
    • CUDA builds use at least C++17, or C++20 with PyTorch 2.14 and newer, and follow a higher user-configured CUDA standard when specified.

PyTorch 2.14 requires C++20 for its C++ API. Raise DeePMD-kit's
C++ standard when building against 2.14 or newer while preserving
the existing requirements for older PyTorch releases.

Fixes deepmodeling#6048.

Agent: ChatGPT
Model: GPT-5.6 Sol
The documentation build does not execute DeePMD's custom PyTorch
operators, so avoid compiling them in RTD. This also keeps docs builds
independent of PyTorch's C++ toolchain requirements.

Fixes deepmodeling#6048.

Agent: ChatGPT
Model: GPT-5.6 Sol
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a2fd8a03-7370-4ee1-9f7f-cc32541ecbb5
📥 Commits

Reviewing files that changed from the base of the PR and between 78f1656 and 552663d.

📒 Files selected for processing (3)
  • source/lmp/tests/dpa4_spin_harness.py
  • source/lmp/tests/test_lammps_dpa4_chg_spin_deepspin_pt2.py
  • source/lmp/tests/test_lammps_dpa4_zbl_pt2.py

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

📝 Walkthrough

The Read the Docs installation disables PyTorch operators. CMake selects C++20 for PyTorch 2.14.0 and newer, and sets the CUDA standard based on the PyTorch version and configured CUDA standard. LAMMPS test parsers now read JSON from the final stdout line.

Changes: PyTorch build compatibility

Layer / File(s) Summary
Read the Docs operator installation
.readthedocs.yml
The requirements installation sets DP_ENABLE_PYTORCH=0. A comment notes that documentation rendering does not execute custom PyTorch operators.
C++ standard for PyTorch versions
source/CMakeLists.txt, source/op/pt/CMakeLists.txt
PyTorch 2.14.0 and newer use a C++20 minimum. The CUDA standard for the PyTorch operator target starts at C++17, rises to C++20 for PyTorch 2.14.0 and newer, and rises further if a higher CMAKE_CUDA_STANDARD is configured.

LAMMPS test output parsing

Layer / File(s) Summary
Parse JSON from final stdout line
source/lmp/tests/dpa4_spin_harness.py, source/lmp/tests/test_lammps_dpa4_chg_spin_deepspin_pt2.py, source/lmp/tests/test_lammps_dpa4_zbl_pt2.py
The harness and two tests parse JSON from the final stdout line. Earlier subprocess output no longer prevents reading the result.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: wanghan-iapcm

Merge Risk: ⚪ Minimal · up to 55266

The docs build avoids compiling unused PyTorch operators, newer PyTorch builds receive the required C++ standard, and LAMMPS tests can handle preceding log output. No merge-blocking issue is evident.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check Warning The changes in source/lmp/tests/dpa4_spin_harness.py, source/lmp/tests/test_lammps_dpa4_chg_spin_deepspin_pt2.py, and source/lmp/tests/test_lammps_dpa4_zbl_pt2.py change JSON parsing for Warp ba… Remove the three unrelated LMP test changes from this pull request, or provide a directly linked coding requirement that includes this parser behavior.
Passed Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: adding C++20 build support for PyTorch 2.14 and newer.
Linked Issues check Passed Issue #6048 requires two coding outcomes. .readthedocs.yml sets DP_ENABLE_PYTORCH=0, so Read the Docs does not build custom PyTorch operators. source/CMakeLists.txt selects C++20 for PyTorch 2.1…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files.
Full details: Out of Scope Changes check

Explanation

The changes in source/lmp/tests/dpa4_spin_harness.py, source/lmp/tests/test_lammps_dpa4_chg_spin_deepspin_pt2.py, and source/lmp/tests/test_lammps_dpa4_zbl_pt2.py change JSON parsing for Warp backend logs. These changes do not support PyTorch 2.14 compatibility or the Read the Docs operator-build workaround in issue #6048.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed both changed files at 211985a, the build-backend handling of DP_ENABLE_PYTORCH, and the PyTorch operator target.

One actionable compatibility gap remains (inline): the new C++20 selection does not reach the CUDA translation units, whose target still requires CUDA_STANDARD 17. This leaves CUDA-enabled source builds against PyTorch 2.14 broken even though the CPU-side standard selection is corrected.

The RTD change is correctly scoped to installation: backend/find_pytorch.py omits the isolated-build PyTorch requirement and backend/read_env.py sets ENABLE_PYTORCH=OFF, while doc/requirements.txt retains the torch extra for documentation imports. The exact-head Read the Docs status now succeeds.

CI inspected on this exact head: C++ builds, C-library build, wheel builds, CodeQL and pre-commit succeed; eight Python/C++ test jobs were still running at inspection. The CUDA execution jobs are skipped. In particular, the green Build C++ (cuda120, cuda) job installs torch==2.11.0+cpu, so it does not exercise CUDA-enabled PyTorch 2.14 or this missing CUDA-standard transition: https://github.com/deepmodeling/deepmd-kit/actions/runs/37417370921/job/112118854044.

Verification was source and upstream job-log inspection, not a local PyTorch 2.14 build. No code or branch changes were made.

Agent: dot
Reviewed head: 211985a

Comment thread source/CMakeLists.txt
Agent: ChatGPT
Model: GPT-5.6 Sol
@github-actions github-actions Bot added the OP label Oct 6, 2026

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed only the three-commit delta from 211985a to 78f1656, plus its integration with the parent CMake standard-selection helper.

The previously reported CUDA-standard defect is addressed: deepmd_op_pt now starts with the existing CUDA C++17 floor, raises it to C++20 for Torch_VERSION >= 2.14.0, and takes a higher configured CMAKE_CUDA_STANDARD without lowering it. The optional-override guard also avoids invoking set_if_higher without a value when CMAKE_CUDA_STANDARD is unset. CUDA_STANDARD_REQUIRED remains ON, and the change stays within the existing CUDA-enabled-PyTorch branch. No new actionable source defect found in this delta.

The remaining qualification is validation coverage, not the old target-standard defect. On this exact head, both CUDA execution jobs are skipped, and the successful Build C++ (cuda120, cuda) log still installs torch==2.11.0+cpu: https://github.com/deepmodeling/deepmd-kit/actions/runs/37422576230/job/112135113843. Thus these green results do not establish a CUDA-enabled PyTorch 2.14 build. The author also explicitly acknowledges this coverage limit in the reply to the earlier finding.

At inspection, the C++ builds, C-library build, wheel builds, CodeQL, pre-commit and Read the Docs status succeed; six Python and two C++ test jobs remain in progress. This is not an all-checks-green or GPU-validation claim. Verification was source and upstream job-log inspection; no tests or builds were run locally.

Agent: dot
Reviewed head: 78f1656
Previous reviewed head: 211985a

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.60%. Comparing base (5b9fe07) to head (552663d).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6049      +/-   ##
==========================================
- Coverage   77.74%   77.60%   -0.15%     
==========================================
  Files        1155     1170      +15     
  Lines      139649   140914    +1265     
  Branches     5056     5062       +6     
==========================================
+ Hits       108573   109353     +780     
- Misses      29191    29677     +486     
+ Partials     1885     1884       -1     

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

The PyTorch DPA4 LAMMPS reference subprocess prints one JSON record
at the end, while Warp 1.18 prints initialization messages to stdout.
Decode the final JSON line to avoid 15 setup errors in Test C++.

Agent: ChatGPT
Model: GPT-6
@iProzd
iProzd self-requested a review October 14, 2026 00:16
@iProzd
iProzd enabled auto-merge October 14, 2026 00:32
@iProzd
iProzd added this pull request to the merge queue Oct 14, 2026
Merged via the queue into deepmodeling:master with commit 025f4f6 Oct 14, 2026
58 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.

docs: Read the Docs build fails since PyTorch 2.14 requires C++20

2 participants