Skip to content

Commit 67553b4

Browse files
committed
[CI/Build]: make it possible to build with a free-threaded interpreter
For Python 3.13/3.14, free-threaded Python does not support using the Limited C API and the Stable ABI. Without this change, the build ends with: ``` In file included from /path/to/vllm/csrc/core/registration.h:3, from /path/to/vllm/csrc/cpu/torch_bindings.cpp:3: /..../include/python3.14t/Python.h:51:4: error: #error "The limited API is not currently supported in the free-threaded build" ``` Signed-off-by: Ralf Gommers <[email protected]>
1 parent d84d8f4 commit 67553b4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cmake/utils.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,13 @@ function (define_extension_target MOD_NAME)
495495
set(SOABI_KEYWORD "")
496496
endif()
497497

498-
if (ARG_USE_SABI)
498+
run_python(IS_FREETHREADED_PYTHON
499+
"import sysconfig; is_free = bool(sysconfig.get_config_var(\"Py_GIL_DISABLED\")); print(f'{1 if is_free else 0}')"
500+
"Failed to determine whether interpreter is free-threaded")
501+
502+
# Free-threaded Python doesn't yet support the stable ABI (see PEP 803/809),
503+
# so avoid using the stable ABI under free-threading only.
504+
if (ARG_USE_SABI AND NOT IS_FREETHREADED_PYTHON)
499505
Python_add_library(${MOD_NAME} MODULE USE_SABI ${ARG_USE_SABI} ${SOABI_KEYWORD} "${ARG_SOURCES}")
500506
else()
501507
Python_add_library(${MOD_NAME} MODULE ${SOABI_KEYWORD} "${ARG_SOURCES}")

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import shutil
1111
import subprocess
1212
import sys
13+
import sysconfig
1314
from pathlib import Path
1415
from shutil import which
1516

@@ -74,9 +75,13 @@ def is_ninja_available() -> bool:
7475
return which("ninja") is not None
7576

7677

78+
def is_freethreaded():
79+
return bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
80+
81+
7782
class CMakeExtension(Extension):
7883
def __init__(self, name: str, cmake_lists_dir: str = ".", **kwa) -> None:
79-
super().__init__(name, sources=[], py_limited_api=True, **kwa)
84+
super().__init__(name, sources=[], py_limited_api=not is_freethreaded(), **kwa)
8085
self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)
8186

8287

0 commit comments

Comments
 (0)