Skip to content

Conversation

@njzjz
Copy link
Member

@njzjz njzjz commented Aug 14, 2025

Fix #4877.

Summary by CodeRabbit

  • Bug Fixes
    • Improved build compatibility with PyTorch 2.8+ on UNIX-like systems (excluding macOS) by aligning the default ABI selection with PyTorch’s behavior. This reduces potential linker/runtime issues when building against newer PyTorch versions. Behavior on other platforms and with older PyTorch remains unchanged. No runtime functionality changes for end users.

@njzjz njzjz closed this Aug 15, 2025
@njzjz njzjz reopened this Aug 15, 2025
@codecov
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.29%. Comparing base (accc331) to head (a4d2481).
⚠️ Report is 73 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4891      +/-   ##
==========================================
- Coverage   84.29%   84.29%   -0.01%     
==========================================
  Files         702      702              
  Lines       68664    68665       +1     
  Branches     3572     3572              
==========================================
  Hits        57883    57883              
- Misses       9641     9642       +1     
  Partials     1140     1140              

☔ View full report in Codecov by Sentry.
📢 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 ready for review August 15, 2025 09:28
@njzjz njzjz requested review from caic99 and Copilot August 15, 2025 09:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes CMake compatibility with PyTorch 2.8 by addressing an issue where torch.compiled_with_cxx11_abi always returns True in PyTorch 2.8, which affects the correct setting of the C++ ABI flag.

  • Adds platform-specific logic to handle PyTorch 2.8+ compatibility
  • Sets OP_CXX_ABI to 1 for Unix (non-macOS) systems when using PyTorch 2.8 or later

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

📝 Walkthrough

Walkthrough

Updates CMake logic in source/CMakeLists.txt to set OP_CXX_ABI based on platform and Torch version: on UNIX (non-Apple) with Torch_VERSION >= 2.8.0, default OP_CXX_ABI=1; otherwise 0. Applies within ENABLE_PYTORCH and not DEEPMD_C_ROOT when OP_CXX_ABI is undefined. OP_CXX_ABI_PT mirrors OP_CXX_ABI.

Changes

Cohort / File(s) Summary
Build system (CMake) adjustments
source/CMakeLists.txt
Conditional defaulting of OP_CXX_ABI based on UNIX and Torch_VERSION>=2.8; OP_CXX_ABI_PT set from OP_CXX_ABI; applies only when ENABLE_PYTORCH is on and DEEPMD_C_ROOT is not set, and OP_CXX_ABI is undefined.

Sequence Diagram(s)

sequenceDiagram
    participant CMake
    participant Env as Platform/Env
    participant Torch as Torch_VERSION

    CMake->>Env: Check UNIX and APPLE flags
    CMake->>Torch: Read Torch_VERSION
    alt OP_CXX_ABI not predefined AND ENABLE_PYTORCH AND NOT DEEPMD_C_ROOT
        alt UNIX and not Apple and Torch_VERSION >= 2.8.0
            CMake->>CMake: set(OP_CXX_ABI 1)
        else
            CMake->>CMake: set(OP_CXX_ABI 0)
        end
        CMake->>CMake: set(OP_CXX_ABI_PT ${OP_CXX_ABI})
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Resolve runtime error by aligning CXX11_ABI with PyTorch (ABI=1) [#4877]
Ensure rebuilt/packaged artifacts use same ABI as PyTorch wheels [#4877] No packaging/CI changes visible.
Validate build configuration/toolchain alignment (gcc/libstdc++/Python) [#4877] No toolchain validation or checks added.
Provide reproducible build/install steps or CI adjustments [#4877] No docs/CI modifications present.

Possibly related PRs

Suggested labels

Core, OP, C++

Suggested reviewers

  • wanghan-iapcm
  • caic99
  • iProzd

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
source/CMakeLists.txt (3)

376-385: Ensure the macro is defined when inferring OP_CXX_ABI without TORCH_CXX_FLAGS (Linux only)

When TORCH_CXX_FLAGS doesn’t advertise _GLIBCXX_USE_CXX11_ABI (common with newer PyTorch), you infer OP_CXX_ABI but do not add the corresponding compile definition. It’s usually fine when OP_CXX_ABI=1 (default for GCC>=5), but explicitly defining the macro on UNIX (non-Apple) improves robustness and consistency, including edge cases.

Apply this diff inside the existing if(NOT DEFINED OP_CXX_ABI) block:

       if(UNIX
          AND NOT APPLE
          AND Torch_VERSION VERSION_GREATER_EQUAL "2.8.0")
         # https://github.com/deepmodeling/deepmd-kit/issues/4877
         # torch.compiled_with_cxx11_abi in PyTorch 2.8 always return True
         set(OP_CXX_ABI 1)
       else()
         set(OP_CXX_ABI 0)
       endif()
+      # On Linux, explicitly define the ABI macro for consistency when TORCH_CXX_FLAGS is silent
+      if(UNIX AND NOT APPLE)
+        add_definitions(-D_GLIBCXX_USE_CXX11_ABI=${OP_CXX_ABI})
+      endif()

376-384: Add a status log to make ABI selection transparent in configure logs

A short message helps users diagnose ABI mismatches quickly from CMake output.

You can add this after selecting OP_CXX_ABI (still within the if(NOT DEFINED OP_CXX_ABI) block):

       else()
         set(OP_CXX_ABI 0)
       endif()
+      message(STATUS "OP_CXX_ABI inferred (PyTorch): ${OP_CXX_ABI}")

1-2: Silence CMP0144 warning by setting policy explicitly

CI shows a CMP0144 warning. Set the policy to NEW early to adopt the modern behavior for find_package and root variables.

Insert after cmake_minimum_required:

 cmake_minimum_required(VERSION 3.16)
+if(POLICY CMP0144)
+  cmake_policy(SET CMP0144 NEW)
+endif()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e73bbff and a4d2481.

📒 Files selected for processing (1)
  • source/CMakeLists.txt (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Build and upload to PyPI
source/CMakeLists.txt

[warning] 302-302: CMP0144 is not set: find_package uses upper-case _ROOT variables. Policy details can be found via cmake --help-policy CMP0144.

🔇 Additional comments (1)
source/CMakeLists.txt (1)

376-384: PyTorch 2.8+ on Linux defaulting to CXX11 ABI=1 — LGTM

This conditional sets OP_CXX_ABI=1 for UNIX (non-Apple) when Torch_VERSION >= 2.8.0, aligning with the reported behavior of PyTorch 2.8 wheels using the new C++11 ABI. This should resolve the runtime mismatch highlighted in #4877.

@njzjz njzjz added this pull request to the merge queue Aug 18, 2025
Merged via the queue into deepmodeling:devel with commit 1525a79 Aug 18, 2025
73 of 105 checks passed
@njzjz njzjz deleted the fix-pt-28 branch August 18, 2025 08:59
ChiahsinChu pushed a commit to ChiahsinChu/deepmd-kit that referenced this pull request Dec 17, 2025
Fix deepmodeling#4877.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- Bug Fixes
- Improved build compatibility with PyTorch 2.8+ on UNIX-like systems
(excluding macOS) by aligning the default ABI selection with PyTorch’s
behavior. This reduces potential linker/runtime issues when building
against newer PyTorch versions. Behavior on other platforms and with
older PyTorch remains unchanged. No runtime functionality changes for
end users.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

[BUG] RuntimeError: This deepmd-kit package was compiled with CXX11_ABI_FLAG=0

2 participants