From 797b2a7de6b413404ffbecc33bf8644f299a42bf Mon Sep 17 00:00:00 2001 From: Pablo Carmona Gonzalez Date: Fri, 6 Feb 2026 16:35:15 +0100 Subject: [PATCH 1/5] fix: improve Python executable detection and error handling in CMake Signed-off-by: Pablo Carmona Gonzalez --- cmake/dependencies.cmake | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 19ae97e2..35bfbd47 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -81,12 +81,26 @@ find_package(Python3 COMPONENTS Interpreter Development.Module) include_directories(${Python3_INCLUDE_DIRS}) # order matters (before pybind) set(ignoreMe "${Python3_EXECUTABLE}${Python3_FIND_REGISTRY}${Python3_INCLUDE_DIR}${Python3_NumPy_INCLUDE_DIRS}${Python3_ROOT_DIR}${Python_INCLUDE_DIR}${Python_NumPy_INCLUDE_DIRS}") +set(RPU_PYTHON_EXECUTABLE "${Python3_EXECUTABLE}") + +if(NOT RPU_PYTHON_EXECUTABLE AND DEFINED PYTHON_EXECUTABLE AND NOT "${PYTHON_EXECUTABLE}" STREQUAL "") + # Keep compatibility with legacy FindPython variables if provided by callers. + set(RPU_PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}") +endif() + +if(NOT RPU_PYTHON_EXECUTABLE) + message(FATAL_ERROR "Could not determine a Python executable for CMake helper commands.") +endif() # Find pybind11Config.cmake -execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pybind11; print(pybind11.get_cmake_dir())" +execute_process(COMMAND "${RPU_PYTHON_EXECUTABLE}" -c "import pybind11; print(pybind11.get_cmake_dir())" + RESULT_VARIABLE PYBIND11_CMAKE_DIR_RESULT OUTPUT_VARIABLE CUSTOM_PYTHON_PYBIND11_PATH OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET) + ERROR_VARIABLE PYBIND11_CMAKE_DIR_ERROR) +if(NOT PYBIND11_CMAKE_DIR_RESULT EQUAL 0 OR CUSTOM_PYTHON_PYBIND11_PATH STREQUAL "") + message(FATAL_ERROR "Failed to query pybind11 CMake dir with ${RPU_PYTHON_EXECUTABLE}: ${PYBIND11_CMAKE_DIR_ERROR}") +endif() set(pybind11_DIR ${CUSTOM_PYTHON_PYBIND11_PATH}) find_package(pybind11 CONFIG REQUIRED) @@ -99,11 +113,18 @@ link_directories(${TORCH_LIB_DIR}) if (CMAKE_COMPILER_IS_GNUCXX) # check for pytorch's ABI - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import torch; print('1' if torch._C._GLIBCXX_USE_CXX11_ABI else '0')" + execute_process(COMMAND "${RPU_PYTHON_EXECUTABLE}" -c "import torch; print('1' if torch._C._GLIBCXX_USE_CXX11_ABI else '0')" + RESULT_VARIABLE TORCH_GNU_ABI_RESULT OUTPUT_VARIABLE OUTPUT_GNU_ABI OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET) - add_compile_definitions("_GLIBCXX_USE_CXX11_ABI=${OUTPUT_GNU_ABI}") + ERROR_VARIABLE TORCH_GNU_ABI_ERROR) + if(NOT TORCH_GNU_ABI_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to query torch CXX11 ABI with ${RPU_PYTHON_EXECUTABLE}: ${TORCH_GNU_ABI_ERROR}") + endif() + if(NOT OUTPUT_GNU_ABI MATCHES "^[01]$") + message(FATAL_ERROR "Invalid torch CXX11 ABI value: '${OUTPUT_GNU_ABI}'. Expected 0 or 1.") + endif() + add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=${OUTPUT_GNU_ABI}) message(STATUS "Set _GLIBCXX_USE_CXX11_ABI=${OUTPUT_GNU_ABI}") endif() From 7afac753192627229284c19d1ce2ef963d0263af Mon Sep 17 00:00:00 2001 From: Pablo Carmona Gonzalez Date: Fri, 6 Feb 2026 17:10:13 +0100 Subject: [PATCH 2/5] fix: enhance ABI detection for PyTorch by prioritizing CMake config Signed-off-by: Pablo Carmona Gonzalez --- cmake/dependencies.cmake | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 35bfbd47..5844fc4e 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -112,20 +112,33 @@ include_directories(${TORCH_INCLUDE_DIRS}) link_directories(${TORCH_LIB_DIR}) if (CMAKE_COMPILER_IS_GNUCXX) - # check for pytorch's ABI - execute_process(COMMAND "${RPU_PYTHON_EXECUTABLE}" -c "import torch; print('1' if torch._C._GLIBCXX_USE_CXX11_ABI else '0')" - RESULT_VARIABLE TORCH_GNU_ABI_RESULT - OUTPUT_VARIABLE OUTPUT_GNU_ABI - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_VARIABLE TORCH_GNU_ABI_ERROR) - if(NOT TORCH_GNU_ABI_RESULT EQUAL 0) - message(FATAL_ERROR "Failed to query torch CXX11 ABI with ${RPU_PYTHON_EXECUTABLE}: ${TORCH_GNU_ABI_ERROR}") + # Prefer ABI from Torch CMake config (works even when Python build isolation + # makes `import torch` unavailable in helper subprocesses). + set(OUTPUT_GNU_ABI "") + if(DEFINED TORCH_CXX_FLAGS AND NOT "${TORCH_CXX_FLAGS}" STREQUAL "") + string(REGEX MATCH "-D_GLIBCXX_USE_CXX11_ABI=[01]" TORCH_ABI_DEFINE "${TORCH_CXX_FLAGS}") + if(NOT TORCH_ABI_DEFINE STREQUAL "") + string(REGEX REPLACE ".*=([01]).*" "\\1" OUTPUT_GNU_ABI "${TORCH_ABI_DEFINE}") + endif() endif() + + if(NOT OUTPUT_GNU_ABI MATCHES "^[01]$") + # Fallback: query torch Python runtime if ABI is not present in TORCH_CXX_FLAGS. + execute_process(COMMAND "${RPU_PYTHON_EXECUTABLE}" -c "import torch; print('1' if torch._C._GLIBCXX_USE_CXX11_ABI else '0')" + RESULT_VARIABLE TORCH_GNU_ABI_RESULT + OUTPUT_VARIABLE OUTPUT_GNU_ABI + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE TORCH_GNU_ABI_ERROR) + if(NOT TORCH_GNU_ABI_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to determine torch CXX11 ABI. TORCH_CXX_FLAGS='${TORCH_CXX_FLAGS}'. Python probe error with ${RPU_PYTHON_EXECUTABLE}: ${TORCH_GNU_ABI_ERROR}") + endif() + endif() + if(NOT OUTPUT_GNU_ABI MATCHES "^[01]$") message(FATAL_ERROR "Invalid torch CXX11 ABI value: '${OUTPUT_GNU_ABI}'. Expected 0 or 1.") endif() add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=${OUTPUT_GNU_ABI}) - message(STATUS "Set _GLIBCXX_USE_CXX11_ABI=${OUTPUT_GNU_ABI}") + message(STATUS "Set _GLIBCXX_USE_CXX11_ABI=${OUTPUT_GNU_ABI} (TORCH_CXX_FLAGS='${TORCH_CXX_FLAGS}')") endif() # Set compile definitions From d3f7c6eec29d61d7dc4fab8cc3e10e84106d08cc Mon Sep 17 00:00:00 2001 From: Pablo Carmona Gonzalez Date: Mon, 9 Feb 2026 12:06:25 +0100 Subject: [PATCH 3/5] fix: add deps to other python version builds and add torch as build dep Signed-off-by: Pablo Carmona Gonzalez --- .github/workflows/build-wheel-311.yml | 16 ++++++++++++++-- .github/workflows/build-wheel-312.yml | 16 ++++++++++++++-- pyproject.toml | 11 +++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-wheel-311.yml b/.github/workflows/build-wheel-311.yml index 9ec114c2..beff28db 100644 --- a/.github/workflows/build-wheel-311.yml +++ b/.github/workflows/build-wheel-311.yml @@ -18,8 +18,20 @@ jobs: CIBW_BUILD: cp311-manylinux_x86_64 CIBW_BEFORE_ALL: > yum install -y openblas-devel - CIBW_BEFORE_BUILD: > - pip install -e . + CIBW_BEFORE_BUILD: | + pip install \ + "cmake>=4.2.1" \ + "scikit-build>=0.18.1" \ + scikit-learn \ + "pybind11>=3.0.1" \ + "torch>=2.9.1" \ + torchvision \ + scipy \ + "requests>=2.32,<3" \ + numpy \ + protobuf \ + tqdm \ + mypy CIBW_MANYLINUX_X86_64_IMAGE: "quay.io/pypa/manylinux_2_28_x86_64" CIBW_REPAIR_WHEEL_COMMAND: > auditwheel repair -w {dest_dir} {wheel} --exclude libtorch_python.so diff --git a/.github/workflows/build-wheel-312.yml b/.github/workflows/build-wheel-312.yml index da932ebb..859e175c 100644 --- a/.github/workflows/build-wheel-312.yml +++ b/.github/workflows/build-wheel-312.yml @@ -18,8 +18,20 @@ jobs: CIBW_BUILD: cp312-manylinux_x86_64 CIBW_BEFORE_ALL: > yum install -y openblas-devel - CIBW_BEFORE_BUILD: > - pip install -e . + CIBW_BEFORE_BUILD: | + pip install \ + "cmake>=4.2.1" \ + "scikit-build>=0.18.1" \ + scikit-learn \ + "pybind11>=3.0.1" \ + "torch>=2.9.1" \ + torchvision \ + scipy \ + "requests>=2.32,<3" \ + numpy \ + protobuf \ + tqdm \ + mypy CIBW_MANYLINUX_X86_64_IMAGE: "quay.io/pypa/manylinux_2_28_x86_64" CIBW_REPAIR_WHEEL_COMMAND: > auditwheel repair -w {dest_dir} {wheel} --exclude libtorch_python.so diff --git a/pyproject.toml b/pyproject.toml index 20f22a1c..79a19bbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,12 @@ [build-system] -requires = ["setuptools", "wheel", "scikit-build >= 0.18.1", "pybind11 >= 3.0.1", "ninja"] +requires = [ + "setuptools", + "wheel", + "scikit-build >= 0.18.1", + "torch >= 2.9.1", + "pybind11 >= 3.0.1", + "ninja" +] build-backend = "setuptools.build_meta" [project] @@ -10,7 +17,7 @@ dependencies = [ "scikit-build >= 0.18.1", "scikit-learn", "pybind11 >= 3.0.1", - "torch == 2.9.1", + "torch >= 2.9.1", "torchvision", "scipy", "requests >= 2.32, <3", From 6a3202af3b89128275af182e228a757b98091268 Mon Sep 17 00:00:00 2001 From: Pablo Carmona Gonzalez Date: Mon, 9 Feb 2026 12:14:29 +0100 Subject: [PATCH 4/5] fix: add no build isolation for python builds Signed-off-by: Pablo Carmona Gonzalez --- .github/workflows/build-wheel-310.yml | 1 + pyproject.toml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-wheel-310.yml b/.github/workflows/build-wheel-310.yml index c9a097cd..9584e568 100644 --- a/.github/workflows/build-wheel-310.yml +++ b/.github/workflows/build-wheel-310.yml @@ -16,6 +16,7 @@ jobs: options: --privileged env: CIBW_BUILD: cp310-manylinux_x86_64 + CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation" CIBW_BEFORE_ALL: > yum install -y openblas-devel gcc-toolset-12 && source /opt/rh/gcc-toolset-12/enable diff --git a/pyproject.toml b/pyproject.toml index 79a19bbe..575dd82c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,6 @@ requires = [ "setuptools", "wheel", "scikit-build >= 0.18.1", - "torch >= 2.9.1", "pybind11 >= 3.0.1", "ninja" ] From 2360be1ac02a6698f7dbf69016056ff4fcf95063 Mon Sep 17 00:00:00 2001 From: Pablo Carmona Gonzalez Date: Mon, 9 Feb 2026 12:54:48 +0100 Subject: [PATCH 5/5] fix: add --no-build-isolation to 3.11 and 3.12 builds Signed-off-by: Pablo Carmona Gonzalez --- .github/workflows/build-wheel-311.yml | 1 + .github/workflows/build-wheel-312.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build-wheel-311.yml b/.github/workflows/build-wheel-311.yml index beff28db..25afbe09 100644 --- a/.github/workflows/build-wheel-311.yml +++ b/.github/workflows/build-wheel-311.yml @@ -16,6 +16,7 @@ jobs: options: --privileged env: CIBW_BUILD: cp311-manylinux_x86_64 + CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation" CIBW_BEFORE_ALL: > yum install -y openblas-devel CIBW_BEFORE_BUILD: | diff --git a/.github/workflows/build-wheel-312.yml b/.github/workflows/build-wheel-312.yml index 859e175c..a681b255 100644 --- a/.github/workflows/build-wheel-312.yml +++ b/.github/workflows/build-wheel-312.yml @@ -16,6 +16,7 @@ jobs: options: --privileged env: CIBW_BUILD: cp312-manylinux_x86_64 + CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation" CIBW_BEFORE_ALL: > yum install -y openblas-devel CIBW_BEFORE_BUILD: |