Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cu130 2.13 route: needs glibc 2.35 and a GIL-enabled 3.13; aarch64 re…
…pairs keep only 2.10+

New installs on a host whose glibc is older than the kernel wheels' floor,
or on a free-threaded interpreter (no cp313t torch 2.13), stay on the
default range. Existing installs keep their release as before. A repair on
aarch64 no longer pins a resident torch 2.9, which has no matching
torchvision / torchaudio on the cu130 index.
  • Loading branch information
danielhanchen committed Oct 12, 2026
commit 22a760b928bf63120ce84a302bd1ce32af8044a4
14 changes: 13 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6135,12 +6135,23 @@ _torch_release_in_window() {
echo "no"
}

# "yes" when $1 is the cu130 index on Linux/WSL x86_64 with a Python 3.13 venv: the only route the torch 2.13/2.14 prebuilt wheels cover.
# "yes" when $1 is the cu130 index on Linux/WSL x86_64 or aarch64 with a Python 3.13 venv: the only route the torch 2.13/2.14 prebuilt wheels cover.
_cu130_torch213_route() {
[ "$(_cu130_torch213_platform "$1")" = "yes" ] || { echo "no"; return; }
[ "$(_cu130_torch213_host_ok)" = "yes" ] || { echo "no"; return; }
_pypi_unsloth_admits_torch "2.13.0"
}

# "yes" when a NEW install here can use the 2.13/2.14 kernel wheels: a GIL-enabled interpreter (torch
# 2.13 has no cp313t wheel) and glibc 2.35+ (the floor the wheels are built and checked against).
# Only gates the new-install choice; an existing 2.13/2.14 is kept regardless.
_cu130_torch213_host_ok() {
_cth_gil=$("$VENV_DIR/bin/python" -c "import sysconfig; print('gil-disabled' if sysconfig.get_config_var('Py_GIL_DISABLED') else 'gil-enabled')" 2>/dev/null || echo "")
[ "$_cth_gil" = "gil-enabled" ] || { echo "no"; return; }
_cth_glibc=$(_uv_glibc_minor) || { echo "no"; return; }
[ "$_cth_glibc" -ge 35 ] 2>/dev/null && echo "yes" || echo "no"
}

# The local half of the route, with no network: it alone decides the preservation window, so a
# PyPI outage on a re-run can never shrink it and downgrade an existing 2.13/2.14 install.
_cu130_torch213_platform() {
Expand Down Expand Up @@ -7264,6 +7275,7 @@ if [ "$SKIP_TORCH" = false ] && [ "$(_cu130_torch213_platform "$TORCH_INDEX_URL"
# The PyPI check reads unsloth's metadata, so a --package other than unsloth keeps the default.
if [ "$(printf '%s' "$PACKAGE_NAME" | tr '[:upper:]' '[:lower:]')" = "unsloth" ] \
&& { [ "$_EXISTING_INSTALL" = false ] || [ "${UNSLOTH_TORCH_UPGRADE:-0}" = "1" ]; } \
&& [ "$(_cu130_torch213_host_ok)" = "yes" ] \
&& [ "$(_pypi_unsloth_admits_torch "2.13.0")" = "yes" ]; then
_CU130_NEW_INSTALL_ROUTE=true
fi
Expand Down
17 changes: 17 additions & 0 deletions studio/backend/tests/test_cu130_repair_torch_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ def test_no_keepable_release_repairs_to_the_default_range(monkeypatch, mod, resi
assert mod._cuda_repair_torch_specs(CU130, default) is default


@pytest.mark.parametrize("machine", ["aarch64", "arm64"])
def test_aarch64_torch_2_9_repairs_to_the_default_range(monkeypatch, mod, machine):
# cu130 serves aarch64 torch 2.9 but no torchvision 0.24 / torchaudio 2.9 for it.
_route(monkeypatch, mod, torch = "2.9.1", machine = machine)
for default in (mod._CUDA_TORCH_PKG_SPEC, mod._TORCH_FLAVOR_REPAIR_PKG_SPEC):
assert mod._cuda_repair_torch_specs(CU130, default) is default


def test_x86_64_torch_2_9_is_kept(monkeypatch, mod):
_route(monkeypatch, mod, torch = "2.9.1")
assert mod._cuda_repair_torch_specs(CU130, mod._CUDA_TORCH_PKG_SPEC) == (
"torch==2.9.1",
"torchvision==0.24.*",
"torchaudio==2.9.*",
)


@pytest.mark.parametrize(
"index_url, kwargs",
[
Expand Down
10 changes: 9 additions & 1 deletion studio/install_python_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ def _torch_index_leaf(url: str) -> str:
_CU130_FIRST_TORCH_MINOR = 9 # download.pytorch.org/whl/cu130 starts at torch 2.9.0


def _cu130_first_torch_minor() -> int:
"""The oldest minor cu130 serves the whole trio for: aarch64 has torch 2.9 but no
torchvision 0.24 / torchaudio 2.9, so it starts at 2.10."""
if sys.platform.startswith("linux") and platform.machine().lower() in ("aarch64", "arm64"):
return 10
return _CU130_FIRST_TORCH_MINOR


def _is_cu130_route_machine() -> bool:
"""Linux x86_64 or aarch64, or Windows x64 on an x64 machine. An emulated x64 Python on Windows
on ARM is excluded: install.ps1 keys its torch 2.13 route on the machine as well as the interpreter."""
Expand Down Expand Up @@ -609,7 +617,7 @@ def _cuda_repair_torch_specs(
release = _resident_torch_release()
if release is not None:
minor = int(release.split(".")[1])
if _CU130_FIRST_TORCH_MINOR <= minor < _CU130_PRESERVE_TORCH_CEILING_MINOR:
if _cu130_first_torch_minor() <= minor < _CU130_PRESERVE_TORCH_CEILING_MINOR:
# torchaudio 2.11 is the last release (stable ABI), so newer minors pair with it.
audio_minor = min(minor, 11)
return (
Expand Down
27 changes: 24 additions & 3 deletions tests/sh/test_cu130_torch213_route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INSTALL_SH="${1:-$SCRIPT_DIR/../../install.sh}"
_FUNC_FILE=$(mktemp)
{
for fn in _mirror_uv_project_config _mirror_configured _run_bounded _pypi_unsloth_admits_torch _torch_index_url_leaf _cu130_torch213_route _cu130_torch213_platform _torchaudio_for_torch_minor _torch_release_in_window _previous_torch_pin _dir_has_entries; do
for fn in _mirror_uv_project_config _mirror_configured _run_bounded _pypi_unsloth_admits_torch _torch_index_url_leaf _cu130_torch213_route _cu130_torch213_platform _cu130_torch213_host_ok _torchaudio_for_torch_minor _torch_release_in_window _previous_torch_pin _dir_has_entries; do
sed -n "/^${fn}()/,/^}/p" "$INSTALL_SH"
echo ""
done
Expand All @@ -23,11 +23,15 @@ unset UNSLOTH_TORCH_UPGRADE

VENV_DIR=$(mktemp -d)
mkdir -p "$VENV_DIR/bin"
# Answers the version probe (-c) with $1 and runs anything else (the PyPI gate) on a real python.
# Answers the GIL probe with $2 (default gil-enabled), the version probe (-c) with $1, and runs
# anything else (the PyPI gate) on a real python.
_stub_python() {
printf '#!/bin/sh\nif [ "$1" = "-c" ]; then echo %s; else exec python3 "$@"; fi\n' "$1" > "$VENV_DIR/bin/python"
printf '#!/bin/sh\ncase "$2" in *Py_GIL_DISABLED*) echo %s; exit 0 ;; esac\nif [ "$1" = "-c" ]; then echo %s; else exec python3 "$@"; fi\n' "${2:-gil-enabled}" "$1" > "$VENV_DIR/bin/python"
chmod +x "$VENV_DIR/bin/python"
}
# The host's glibc minor; empty = not a readable glibc (musl).
GLIBC_MINOR=35
_uv_glibc_minor() { [ -n "$GLIBC_MINOR" ] || return 1; echo "$GLIBC_MINOR"; }
CU130="https://download.pytorch.org/whl/cu130"
_pypi_fixture() {
printf '{"info": {"requires_dist": ["numpy", "%s", "torchvision"]}}' "$1" > "$VENV_DIR/pypi.json"
Expand Down Expand Up @@ -57,6 +61,23 @@ for py in 3.11 3.12 3.14; do
_stub_python "$py"
assert_eq "Python $py never (cp313 wheels only)" "no" "$(_cu130_torch213_route "$CU130")"
done
_stub_python 3.13 gil-disabled
assert_eq "free-threaded 3.13 never (no cp313t torch 2.13)" "no" "$(_cu130_torch213_route "$CU130")"
assert_eq "free-threaded 3.13 keeps the preservation window" "yes" "$(_cu130_torch213_platform "$CU130")"
_stub_python 3.13
for minor in 28 31 34; do
GLIBC_MINOR=$minor
for arch in x86_64 aarch64; do
_ARCH=$arch
assert_eq "glibc 2.$minor $arch never (wheels need 2.35)" "no" "$(_cu130_torch213_route "$CU130")"
assert_eq "glibc 2.$minor $arch keeps the preservation window" "yes" "$(_cu130_torch213_platform "$CU130")"
done
done
GLIBC_MINOR=""
assert_eq "musl / unreadable glibc never" "no" "$(_cu130_torch213_route "$CU130")"
GLIBC_MINOR=39
assert_eq "glibc 2.39 aarch64" "yes" "$(_cu130_torch213_route "$CU130")"
GLIBC_MINOR=35; _ARCH=x86_64
rm -f "$VENV_DIR/bin/python"
assert_eq "no venv python never" "no" "$(_cu130_torch213_route "$CU130")"

Expand Down