Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: torch 2.13 for new Linux aarch64 cu130 Python 3.13 installs, existing installs keep their torch (#13380)

Daniel Han55ff88ac0052
diff --git a/install.sh b/install.sh
index 77dba3ad87e..0be845cae6e 100755
--- a/install.sh
+++ b/install.sh
@@ -6135,18 +6135,27 @@ _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"
}
+# New installs only: torch 2.13 has no cp313t wheel, and the kernel wheels need glibc 2.35.
+_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() {
[ "$(_torch_index_url_leaf "$1")" = "cu130" ] || { echo "no"; return; }
case "$OS" in linux|wsl) ;; *) echo "no"; return ;; esac
- case "$_ARCH" in x86_64|amd64) ;; *) echo "no"; return ;; esac
+ case "$_ARCH" in x86_64|amd64|aarch64|arm64) ;; *) echo "no"; return ;; esac
_ctr_py=$("$VENV_DIR/bin/python" -c "import sys; print('%d.%d' % sys.version_info[:2])" 2>/dev/null || echo "")
[ "$_ctr_py" = "3.13" ] && echo "yes" || echo "no"
}
@@ -7263,6 +7272,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
diff --git a/studio/backend/tests/test_cu130_repair_torch_specs.py b/studio/backend/tests/test_cu130_repair_torch_specs.py
index 6c9aaa3fd1a..91c1679cb5e 100644
--- a/studio/backend/tests/test_cu130_repair_torch_specs.py
+++ b/studio/backend/tests/test_cu130_repair_torch_specs.py
@@ -55,7 +55,14 @@ def _route(
("2.14.0", ("torch==2.14.0", "torchvision==0.29.*", "torchaudio==2.11.*")),
],
)
[email protected]("host", [{"platform": "linux"}, {"platform": "win32", "machine": "AMD64"}])
+ "host",
+ [
+ {"platform": "linux"},
+ {"platform": "linux", "machine": "aarch64"},
+ {"platform": "win32", "machine": "AMD64"},
+ ],
+)
def test_a_resident_release_is_kept(monkeypatch, mod, resident, expected, host):
_route(monkeypatch, mod, torch = resident, **host)
assert mod._cuda_repair_torch_specs(CU130, mod._CUDA_TORCH_PKG_SPEC) == expected
@@ -71,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
[email protected]("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",
[
@@ -83,7 +107,8 @@ def test_no_keepable_release_repairs_to_the_default_range(monkeypatch, mod, resi
(CU130, {"platform": "win32", "machine": "AMD64", "woa": True}),
(CU130, {"platform": "win32", "machine": "AMD64", "py": (3, 12)}),
(CU130, {"platform": "darwin"}),
- (CU130, {"machine": "aarch64"}),
+ (CU130, {"machine": "armv7l"}),
+ (CU130, {"platform": "darwin", "machine": "arm64"}),
(CU130, {"py": (3, 12)}),
(CU130, {"py": (3, 11)}),
(None, {}),
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index 2318bdf623e..9553e32d93a 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -568,13 +568,21 @@ _CU130_PRESERVE_TORCH_CEILING_MINOR = 15
_CU130_FIRST_TORCH_MINOR = 9 # download.pytorch.org/whl/cu130 starts at torch 2.9.0
-def _is_native_x86_64() -> bool:
- """Linux x86_64, 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."""
- if platform.machine().lower() not in ("x86_64", "amd64"):
- return False
+def _cu130_first_torch_minor() -> int:
+ """cu130 has no aarch64 torchvision 0.24 / torchaudio 2.9, so aarch64 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."""
+ machine = platform.machine().lower()
if sys.platform.startswith("linux"):
- return True
+ return machine in ("x86_64", "amd64", "aarch64", "arm64")
+ if machine not in ("x86_64", "amd64"):
+ return False
return sys.platform == "win32" and not _is_windows_arm64()
@@ -582,7 +590,7 @@ def _is_cu130_torch213_route(index_url: str | None) -> bool:
return (
bool(index_url)
and _torch_index_leaf(index_url) == "cu130"
- and _is_native_x86_64()
+ and _is_cu130_route_machine()
and sys.version_info[:2] == (3, 13)
)
@@ -608,7 +616,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 (
diff --git a/tests/sh/test_cu130_torch213_route.sh b/tests/sh/test_cu130_torch213_route.sh
index dfbed61ecfc..c9751679a78 100644
--- a/tests/sh/test_cu130_torch213_route.sh
+++ b/tests/sh/test_cu130_torch213_route.sh
@@ -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
@@ -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"
@@ -35,7 +39,7 @@ _pypi_fixture() {
}
_pypi_fixture "torch<2.15.0,>=2.4.0"
-echo "=== route: only cu130 + Linux/WSL + x86_64 + Python 3.13 ==="
+echo "=== route: only cu130 + Linux/WSL + x86_64/aarch64 + Python 3.13 ==="
_stub_python 3.13
OS=linux; _ARCH=x86_64
assert_eq "linux x86_64 cu130 py3.13" "yes" "$(_cu130_torch213_route "$CU130")"
@@ -49,12 +53,31 @@ done
OS=macos
assert_eq "macOS never" "no" "$(_cu130_torch213_route "$CU130")"
OS=linux; _ARCH=aarch64
-assert_eq "aarch64 never (no wheels)" "no" "$(_cu130_torch213_route "$CU130")"
+assert_eq "linux aarch64 cu130 py3.13" "yes" "$(_cu130_torch213_route "$CU130")"
+_ARCH=armv7l
+assert_eq "32-bit ARM never" "no" "$(_cu130_torch213_route "$CU130")"
_ARCH=x86_64
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")"