Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ or if you want the latest version from the `main` branch:
```bash
pip install "kernels[benchmark] @ git+https://github.com/huggingface/kernels#subdirectory=kernels"
```

> [!IMPORTANT]
> We strongly recommend not using a free-threaded Python build yet.
These builds are not only experimental, but do not support the stable ABI
on Python versions before 3.15. Kernels are compiled with the stable ABI
to support a wide range of Python versions.
31 changes: 31 additions & 0 deletions kernels/src/kernels/variants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
import platform
import re
import sys
import sysconfig
import warnings
from dataclasses import dataclass
from pathlib import Path
from typing import ClassVar
Expand Down Expand Up @@ -316,6 +319,12 @@ def _resolve_variant_for_system(
return applicable, trace


def _is_unsupported_free_threaded_build() -> bool:
"""Check if the Python interpreter is a free-threaded build that does not
support ABI3."""
return sys.version_info < (3, 15) and bool(sysconfig.get_config_var("Py_GIL_DISABLED"))


def _check_variants(
variants: list[Variant],
selected_backend: Backend,
Expand All @@ -326,9 +335,31 @@ def _check_variants(
tvm_ffi_version: Version | None,
) -> list[Decision]:
"""Return only the variants applicable to the current system."""
is_unsupported_free_threaded = _is_unsupported_free_threaded_build()
# Prefilter all arch kernels on free-threaded Python pre-3.15, since
# they do not support the stable ABI.
if is_unsupported_free_threaded:
warnings.warn(
"Arch kernels use the stable ABI, which is not supported on free-threaded "
"Python before version 3.15. Arch kernels will not be used. Consider using "
"a non-free-threaded interpreter, or upgrade to Python 3.15+.",
UserWarning,
stacklevel=2,
)
variants = [v for v in variants if not isinstance(v, ArchVariant)]

result: list[Decision] = []
for v in variants:
if isinstance(v, ArchVariant):
if is_unsupported_free_threaded:
result.append(
VariantRejected(
variant=v,
reason="arch kernel not supported on free-threaded Python <3.15",
)
)
continue

# Skip non-matching CPU or OS.
if v.arch.platform != cpu:
result.append(
Expand Down
Loading