Skip to content

Commit 1525a79

Browse files
authored
fix(pt): fix CMake compatibility with PyTorch 2.8 (#4891)
Fix #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 -->
1 parent dc99ba2 commit 1525a79

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

source/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,15 @@ if(ENABLE_PYTORCH AND NOT DEEPMD_C_ROOT)
373373
else()
374374
# Maybe in macos/windows
375375
if(NOT DEFINED OP_CXX_ABI)
376-
set(OP_CXX_ABI 0)
376+
if(UNIX
377+
AND NOT APPLE
378+
AND Torch_VERSION VERSION_GREATER_EQUAL "2.8.0")
379+
# https://github.com/deepmodeling/deepmd-kit/issues/4877
380+
# torch.compiled_with_cxx11_abi in PyTorch 2.8 always return True
381+
set(OP_CXX_ABI 1)
382+
else()
383+
set(OP_CXX_ABI 0)
384+
endif()
377385
endif()
378386
set(OP_CXX_ABI_PT "${OP_CXX_ABI}")
379387
endif()

0 commit comments

Comments
 (0)