diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 3be7655117..ed41ab430e 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -421,7 +421,13 @@ function (define_gpu_extension_target GPU_MOD_NAME) set(GPU_WITH_SOABI) endif() - if (GPU_USE_SABI) + run_python(IS_FREETHREADED_PYTHON + "import sysconfig; print(1 if sysconfig.get_config_var(\"Py_GIL_DISABLED\") else 0)" + "Failed to determine whether interpreter is free-threaded") + + # Free-threaded Python doesn't yet support the stable ABI (see PEP 803/809), + # so avoid using the stable ABI under free-threading only. + if (GPU_USE_SABI AND NOT IS_FREETHREADED_PYTHON) Python_add_library(${GPU_MOD_NAME} MODULE USE_SABI ${GPU_USE_SABI} ${GPU_WITH_SOABI} "${GPU_SOURCES}") else() Python_add_library(${GPU_MOD_NAME} MODULE ${GPU_WITH_SOABI} "${GPU_SOURCES}") diff --git a/setup.py b/setup.py index 00d482604c..d2479f600f 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ import os import re import ast +import sysconfig from collections import namedtuple from pathlib import Path from typing import Dict @@ -79,10 +80,14 @@ def _is_hip() -> bool: or VLLM_TARGET_DEVICE == "rocm") and torch.version.hip is not None +def is_freethreaded(): + return bool(sysconfig.get_config_var("Py_GIL_DISABLED")) + + class CMakeExtension(Extension): def __init__(self, name: str, cmake_lists_dir: str = '.', **kwa) -> None: - super().__init__(name, sources=[], py_limited_api=True, **kwa) + super().__init__(name, sources=[], py_limited_api=not is_freethreaded(), **kwa) self.cmake_lists_dir = os.path.abspath(cmake_lists_dir)