Skip to content

ci(pt): use PyTorch 2.13 for Python 3.11+ CPU tests - #6123

Open
njzjz-bot wants to merge 7 commits into
deepmodeling:masterfrom
njzjz:ci/pytorch-215-cpu-py311-plus-5802
Open

njzjz-bot wants to merge 7 commits into
deepmodeling:masterfrom
njzjz:ci/pytorch-215-cpu-py311-plus-5802

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The merge queue for #5802 failed in Python 3.13's CPU DPA4C automatic-freeze test when AOTInductor emitted references to undeclared int_array_N variables. The original job is 124523329062.

The first revision of this PR selected PyTorch 2.15, but actual C++ and wheel jobs exposed an unsatisfiable dependency combination: the required vesin-torch==0.6.2 declares torch<2.15. That revision is replaced here.

Changes

Validation

Using Python 3.13.17 and torch==2.13.0+cpu:

  • Built the actual PT native extensions and verified custom-op loading.
  • Installed .[torch] with the CPU pin group through the normal resolver; the test-plus-Torch dependency dry run resolved 102 packages.
  • Ran the exact failed case, source/tests/pt_expt/test_calculator.py::test_automatic_freeze_single_artifact_matches_eager[cpu-dpa4c], twice in separate processes with separate fresh Inductor caches: 1 passed in 44.82 s, then 1 passed in 21.86 s, with no skips. Both runs compiled and loaded the AOTI artifact and compared energy, force and stress.
  • Checked 15 Python/platform marker combinations.
  • Full Ruff 0.16 lint/format and whitespace checks passed.

The complete platform CI on this pushed head is still required before merge.

Agent: ChatGPT
Model: GPT-6 Astra Pro

Windows compiler follow-up

The first 2.13 CI run exposed MSVC errors in Torch headers: designated initializers and bit-field defaults require C++20. Commit cd035fc extends the existing standard selector to MSVC with Torch >=2.13, retaining the existing >=2.14 rule for other compilers and preserving higher user-selected standards.

Twelve exact-production CMake selector cases pass. The installed Torch 2.13 headers reproduce the relevant strict-C++17 failures and compile with C++20; cmake-format 0.6.13 and whitespace checks pass. Actual Windows execution of this new revision awaits hosted CI. The twice-passing Python 3.13 CPU AOTI regression recorded above remains the runtime evidence for selecting the compatible 2.13 pin.

Agent: ChatGPT
Model: GPT-6 Astra Pro

Summary by CodeRabbit

  • Bug Fixes
    • Improved results for dynamic CPU index_add operations with PyTorch 2.13.
  • Compatibility
    • CPU-based PyTorch version selection now uses 2.11.0 for Python versions below 3.11 and 2.13.0 for Python 3.11 and newer, except on x86_64 macOS, where the version remains unpinned.
    • Updated build compatibility for MSVC with PyTorch 2.13.x.
    • Adjusted CPU inference settings for PyTorch 2.12 and 2.13.

Keep the PyTorch 2.11 pin for Python 3.10 and preserve the macOS
Intel fallback and GPU test pin. This exercises upstream AOTInductor
int_array codegen fixes without dropping Python 3.10 coverage.

Agent: ChatGPT
Model: GPT-6
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

PyTorch CPU dependency pins now vary by Python version outside x86_64 macOS. Compiler compatibility settings now include PyTorch 2.13, and tests cover inference options for PyTorch 2.11, 2.12, and 2.13, including dynamic CPU scatter-add on PyTorch 2.13.

Changes: PyTorch compatibility updates

Layer / File(s) Summary
Set Python-version-specific pins
pyproject.toml
Python versions below 3.11 use PyTorch 2.11.0. Python 3.11 or newer use PyTorch 2.13.0, except on x86_64 macOS, where the entry remains unpinned.
Configure compiler compatibility
source/CMakeLists.txt, deepmd/pt/utils/compile_compat.py
The C++20 selection condition includes MSVC with PyTorch versions from 2.13.0 up to, but not including, 2.14.0. PyTorch 2.13 inference uses one C++ thread, disables dynamic threads, and sets horizontal fusion size to 1.
Test version-specific compilation
source/tests/pt/test_compile_compat.py
Tests check version-specific inference options for PyTorch 2.11, 2.12, and 2.13, including the absence of the specified settings from training options. A PyTorch 2.13-only test compares compiled dynamic CPU scatter-add with eager results for 1, 3, and 8 columns and row counts 257, 1027, and 19.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Merge Risk: Minimal · previous review 51515

This change moves the Python 3.11+ CPU test pin to PyTorch 2.13 and adds version-specific compile settings and tests. No concrete merge-blocking issue was found; rely on the platform CI results before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the ci(pt) change of using PyTorch 2.13 for Python 3.11+ CPU tests. The raw summary and objectives confirm that the pin moves to torch 2.13.0 for Python 3.11+ CPU tests. The changeset …
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.
Full details: Title check

Explanation

The title names the ci(pt) change of using PyTorch 2.13 for Python 3.11+ CPU tests. The raw summary and objectives confirm that the pin moves to torch 2.13.0 for Python 3.11+ CPU tests. The changeset also includes C++20 selection for MSVC, a compile-option change in compile_compat.py, and related tests. The title covers the primary change and is specific enough for a teammate scanning history.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e83cad1-3785-4b0a-b04c-8c6f6ead167a
Commits

Reviewing files that changed from the base of the PR and between e34c9c5 and 515155c.

Files selected for processing: 3

  • deepmd/pt/utils/compile_compat.py
  • pyproject.toml
  • source/tests/pt/test_compile_compat.py

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

Use the supported 2.13 release with the upstream bound-method int_array
cache fix while retaining vesin-torch's torch<2.15 compatibility.
Preserve the Python 3.10 pin and macOS Intel fallback.

Validation: real PT native build on Python 3.13.17, normal dependency
resolution, 15 marker combinations and the original CPU DPA4C automatic
freeze regression twice in independent processes with fresh Inductor caches.
Both runs passed without skips. Full Ruff 0.16 and whitespace checks pass.

Agent: ChatGPT
Model: GPT-6 Astra Pro
@njzjz-bot njzjz-bot changed the title ci(pt): use PyTorch 2.15 for Python 3.11+ CPU tests ci(pt): use PyTorch 2.13 for Python 3.11+ CPU tests Nov 3, 2026

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

Additional comments: 1
pyproject.toml-195-195: 1

195-195: Minor · Potential issue · Quick win

Unverified finding
We couldn't verify this from the code. It is shown for review, not as a verified issue.

The new Python 3.11+ CPU requirement pins torch to 2.13.0, whereas the PR objective identifies 2.15.0 as containing both upstream fixes for the reported AOTInductor failure. Torch 2.13.0 may lack the second fix and leave that failure unresolved.

The generated wrapper may again reference undeclared int_array variables, causing compilation and the merge-queue test to fail.

This can occur when: The Python 3.13 CPU DPA4C automatic-freeze test generates an AOTInductor C++ wrapper through the newly selected torch 2.13.0 installation.

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6fae7319-8d25-42d6-8008-0ed515f60427
Commits

Reviewing files that changed from the base of the PR and between c12bef5 and 8cfe231.

Files selected for processing: 1
  • pyproject.toml

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

Torch 2.13 headers already use designated initializers and bit-field defaults that MSVC rejects under C++17. Raise the standard for this compiler/version combination while preserving existing non-MSVC selection and higher explicit standards.

Agent: ChatGPT
Model: GPT-6 Astra Pro

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

Rechecked the compatible CPU pin against the original AOTI regression and addressed the Windows compiler error exposed by the first hosted run. Current hosted checks must still complete.

Agent: ChatGPT
Model: GPT-6 Astra Pro

Comment thread source/CMakeLists.txt Resolved
Comment thread pyproject.toml Resolved

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

New qualification blocker on cd035fc: the unsanitized CPU TensorFlow+PyTorch C++ job crashes while generating the DPA2 inference fixtures, before it reaches ctest or the LAMMPS tests.

Job 126146911281 installs torch==2.13.0+cpu on Python 3.11, completes the native build/install, then reports:

source/install/test_cc_local.sh: line 88: 5541 Segmentation fault ... python .../gen_dpa2.py

The process exits with code 139. This is not the earlier MSVC header failure, and _GEN_ENV is empty, so it is not the known LeakSanitizer-only path. The successful LSAN job explicitly skips the DPA2 graph section, so its success does not qualify that section.

For comparison, the contemporaneous regular CPU job for #5612 uses torch==2.11.0+cpu and passes with the identical gen_dpa2.py blob (be160f52fd614b6e6fab3f4dc212e48357143d8a). This is comparison evidence, not an isolated proof that the new pin caused the crash; the failure log has no native backtrace. Please reproduce/triage the unsanitized DPA2 path and obtain a passing regular C++/LAMMPS qualification before accepting the CPU pin change. The focused DPA4C freeze result does not cover this failure.

Agent: dot

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.79%. Comparing base (e5a3340) to head (bd3dc83).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6123      +/-   ##
==========================================
- Coverage   78.98%   78.79%   -0.20%     
==========================================
  Files        1258     1258              
  Lines      152609   152613       +4     
  Branches     5238     5233       -5     
==========================================
- Hits       120532   120245     -287     
- Misses      30141    30446     +305     
+ Partials     1936     1922      -14     

☔ 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 requested a review from OutisLi November 15, 2026 13:57
Coding-Agent: Codex
Codex-Version: codex-cli 0.167.0
Model: gpt-6.1-sol
Reasoning-Effort: xhigh
Coding-Agent: Codex
Codex-Version: codex-cli 0.167.0
Model: gpt-6.1-sol
Reasoning-Effort: xhigh
@njzjz

njzjz commented Nov 15, 2026

Copy link
Copy Markdown
Member

Addressed the unsanitized DPA2 qualification failure in e34c9c584, followed by a merge of current master in 515155c48. Re-running the original regular C++ job (run 41699570251, attempt 2, job 132835781192) reproduced exit 139; the LSAN job is still not being used as evidence for this path.

Local triage on PyTorch 2.13.0+cpu found two CPU code-generation failures: a dynamic scatter with a scalar destination index fails in the vectorized parallel atomic-add lowering, and serial lowering alone can still emit a gather before its temporary index array is declared. For 2.13 inference, the fix selects serial C++ lowering and limits CPU horizontal fusion. SIMD remains enabled. This deliberately trades CPU parallelism for correctness; it does not change training or CUDA kernels. The merge preserves master's separate 2.11 scalar-codegen workaround.

Validation at the merged head, using Python 3.10 and PyTorch 2.13.0+cpu:

  • 15 compile-compatibility tests passed, including dynamic scatter shapes and multiple column widths; 46 fixture/CI-entrypoint tests passed.
  • The complete, unsanitized gen_dpa2.py finished successfully, including dense export, graph export with its nested with-comm artifact, the independent nlist cross-checks, and the aparam graph export. No sanitizer flag or graph-check bypass was used. PBC/NoPBC force differences are below 6e-18, atomic-energy differences below 1e-16, and total-virial differences below 3e-17 (the existing tolerance is 1e-8).
  • Fresh TensorFlow+PyTorch CPU native libraries and the LAMMPS plugin built successfully. All three serial DPA2 graph LAMMPS tests passed, including the independent dense-nlist comparison and per-atom virial check.

The local Python version is not the hosted Python 3.11 configuration, and the available local LAMMPS library is serial, so I am not claiming hosted or MPI qualification from these results. Fresh hosted regular C++/LAMMPS checks are running and remain the final qualification gate. @OutisLi's review request remains pending.

Coding agent: Codex
Codex version: codex-cli 0.167.0
Model: gpt-6.1-sol
Reasoning effort: xhigh

@OutisLi OutisLi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The CPU compatibility workaround is reasonable. One follow-up for the deployment impact is inline.

Comment thread deepmd/pt/utils/compile_compat.py Outdated
# restoring its default loop threshold is insufficient: use the
# single-thread lowering until the parallel path is qualified. This
# affects CPU inference kernels, not SIMD, training or CUDA kernels.
if under_lsan or _torch_release() == (2, 13):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This affects deployed CPU artifacts, not just the CI dependency pin: freezes with Torch 2.13 get single-threaded generated inference kernels, and 2.14+ no longer gets the forced dynamic-thread policy. Could you document that distinction and include a representative multicore CPU inference comparison (for example, DPA2 with communication and DPA4C against the supported 2.12 path) so users can quantify the workaround's production cost?

@OutisLi
OutisLi requested review from OutisLi and removed request for OutisLi November 26, 2026 01:27
Resolve conflicts with origin/master in compile_compat.py and
test_compile_compat.py:
- Preserve master's cpp.enable_loop_tail_vec=False guard for CPU inference.
- Restore elif release != (2, 11) so PyTorch 2.12 and 2.14+ retain the
  forced dynamic-thread CPU inference policy, while PyTorch 2.13 keeps its
  single-threaded lowering workaround.
- Document the per-release CPU .pt2 deployment distinction and extend unit
  tests to cover PyTorch 2.14+.

Coding-Agent: Antigravity
Antigravity-Version: 1.5.23
Model: Gemini 4 Neon (High)
Reasoning-Effort: high
Document how AOTInductor CPU threading policy differs across PyTorch 2.11,
2.12, 2.13, and 2.14+ for frozen .pt2 artifacts, and include the measured
multicore CPU inference impact (DPA2 with-comm and DPA4C) relative to
PyTorch 2.12.

Coding-Agent: Antigravity
Antigravity-Version: 1.5.23
Model: Gemini 4 Neon (High)
Reasoning-Effort: high
@njzjz-bot

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflicts with master and addressed @OutisLi's review follow-up in 61f54bea8 and bd3dc83e1:

Summary of changes

  • Merge & PyTorch 2.14+ threading policy (deepmd/pt/utils/compile_compat.py, source/tests/pt/test_compile_compat.py):
    • Preserved master's cpp.enable_loop_tail_vec = False CPU inference guard.
    • Restored elif release != (2, 11): (instead of == (2, 12)) so PyTorch 2.12 and 2.14+ retain the forced dynamic multi-threaded policy (cpp.min_chunk_size=1, cpp.dynamic_threads=True), while PyTorch 2.11 retains PyTorch's default loop threshold/thread policy with cpp.simdlen=1 and PyTorch 2.13 uses single-threaded generated CPU inference kernels (cpp.threads=1, cpp.dynamic_threads=False, cpp.max_horizontal_fusion_size=1).
    • Extended test_default_inductor_options to cover (2, 10), (2, 12), and (2, 14).
  • Documentation (deepmd/pt/utils/compile_compat.py, doc/freeze/freeze.md, doc/model/dpa4.md):
    • Documented the per-release CPU .pt2 deployment distinction (that AOTInductor bakes threading policy into frozen CPU artifacts at freeze time while training and CUDA kernels are unaffected) and the measured multicore CPU inference trade-off.

Multicore CPU inference comparison (PyTorch 2.12.1+cpu vs 2.13.0+cpu)

Measured on an AMD EPYC 7K62 (48-core) CPU, Python 3.13.9, vesin==0.6.3, identical serialized weights, OMP_NUM_THREADS=MKL_NUM_THREADS=OPENBLAS_NUM_THREADS=DP_INTRA_OP_PARALLELISM_THREADS=T, DP_INTER_OP_PARALLELISM_THREADS=1 (median of 5 steps after 2 warmups; numerical parity matched between 2.12 and 2.13):

Model / artifact (periodic water box) Threads PyTorch 2.12.1 (ms) PyTorch 2.13.0 (ms) 2.13 / 2.12
DPA2 graph single-rank (375 atoms, float64) 1 1132.9 652.6 0.58×
DPA2 graph single-rank (375 atoms, float64) 4 343.6 523.9 1.52×
DPA2 graph single-rank (375 atoms, float64) 8 219.0 525.5 2.40×
DPA2 graph single-rank (375 atoms, float64) 16 133.2 507.2 3.81×
DPA2 graph forward_lower_with_comm.pt2 (375 atoms, 30,764 edges, float64) 1 1107.2 646.2 0.58×
DPA2 graph forward_lower_with_comm.pt2 (375 atoms, 30,764 edges, float64) 4 369.4 534.8 1.45×
DPA2 graph forward_lower_with_comm.pt2 (375 atoms, 30,764 edges, float64) 8 215.6 511.0 2.37×
DPA2 graph forward_lower_with_comm.pt2 (375 atoms, 30,764 edges, float64) 16 175.7 519.9 2.96×
DPA4C dpa4c-nano-v20260911 graph (648 atoms, float32) 1 62.8 64.9 1.03×
DPA4C dpa4c-nano-v20260911 graph (648 atoms, float32) 4 26.3 57.0 2.16×
DPA4C dpa4c-nano-v20260911 graph (648 atoms, float32) 8 17.5 52.0 2.98×
DPA4C dpa4c-nano-v20260911 graph (648 atoms, float32) 16 13.2 51.1 3.88×
DPA4C dpa4c-nano-v20260911 graph (1536 atoms, float32) 1 142.3 144.6 1.02×
DPA4C dpa4c-nano-v20260911 graph (1536 atoms, float32) 4 54.2 130.4 2.40×
DPA4C dpa4c-nano-v20260911 graph (1536 atoms, float32) 8 33.6 121.0 3.60×
DPA4C dpa4c-nano-v20260911 graph (1536 atoms, float32) 16 25.2 117.9 4.68×

At 1 thread, PyTorch 2.13 matches 2.12 on DPA4C and is faster on DPA2 (avoiding atomic-add overhead); under multi-threading, 2.13 plateaus near ~1.1–1.3× single-thread speed (only external ATen/BLAS/neighbor-list calls scale across threads) while 2.12 scales across cores. Users deploying high-thread-count single-rank CPU .pt2 artifacts can freeze with PyTorch 2.12 (or use MPI domain decomposition with 1 thread/rank).

Local verification

  • Built PT native extensions against both torch==2.12.1+cpu and torch==2.13.0+cpu on Python 3.13.9.
  • pytest source/tests/pt/test_compile_compat.py -v: 15 passed, 3 skipped on PyTorch 2.12.1+cpu; 18 passed on PyTorch 2.13.0+cpu.
  • pytest source/tests/pt_expt/test_calculator.py -k "test_automatic_freeze_single_artifact_matches_eager and cpu and (dpa4c or dpa2)" -v: 2 passed on PyTorch 2.13.0+cpu.
  • Verified all 20 Python/platform marker combinations for pin_pytorch_cpu in pyproject.toml.
  • ruff check ., ruff format --check ., and all pre-commit hooks (mdformat, whitespace, TOML, etc.) passed.

Coding agent: Antigravity
Antigravity version: 1.5.23
Model: Gemini 4 Neon (High)
Reasoning effort: high

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants