From a4d2481588d08a449ca2eeea1b93eb82b0f88d79 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 14 Aug 2025 23:57:22 +0800 Subject: [PATCH] fix(pt): fix CMake compatibility with PyTorch 2.8 Fix #4877. --- source/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 7e0f180e26..2c13a5a367 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -373,7 +373,15 @@ if(ENABLE_PYTORCH AND NOT DEEPMD_C_ROOT) else() # Maybe in macos/windows if(NOT DEFINED OP_CXX_ABI) - set(OP_CXX_ABI 0) + 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() endif() set(OP_CXX_ABI_PT "${OP_CXX_ABI}") endif()