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
install.sh: existing Apple Silicon homes keep their torch on a plain …
…re-run again

Reverts the below-2.13 move from #20038: an existing home moves to the new-install torch only on a fresh install or a repair (Desktop's Repair sets UNSLOTH_TORCH_UPGRADE=1). The macOS staging workflow now checks that a re-run and studio update keep a 2.10 home, that UNSLOTH_TORCH_UPGRADE=1 moves it, and that a 2.14 home is kept.
  • Loading branch information
danielhanchen committed Nov 28, 2026
commit fa50dd577ae224415664e0bc772035ed361f787a
39 changes: 15 additions & 24 deletions .github/workflows/studio-mac-torch-floor-upgrade.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
# An existing Apple Silicon home on torch 2.10, re-run with the merge base's install.sh (it must end on the
# torch its own log names) and with this checkout's (moved to the 2.13 route); then opt-out, a 2.14 home,
# studio update.
# torch its own log names) and with this checkout's: a plain re-run and studio update keep its torch, only
# UNSLOTH_TORCH_UPGRADE=1 moves it; a 2.14 home is kept too.

name: Studio macOS torch floor upgrade
name: Studio macOS existing-home torch

# Opt-in: never runs on unslothai/unsloth pull requests (the job is skipped there); runs on
# staging repos, which take inherited workflows on pull_request, and by dispatch anywhere.
Expand Down Expand Up @@ -92,38 +92,29 @@ jobs:
bash "$HELPER" probe | tee "$LOGS/A_probe.log"
bash "$HELPER" check-route 2.10.0 "$LOGS/A_base_rerun.log" "$LOGS/A_probe.log"

- name: "B (head): a re-run moves 2.10 to the 2.13 route"
- name: "B (head): a re-run and studio update keep a 2.10 home on 2.10"
env:
STUDIO_LOCAL_REPO: ${{ github.workspace }}
run: |
set -o pipefail
# A may have moved the home off 2.10: start B from the same 2.10 home every time.
bash "$HELPER" seed 2.10.0 0.25.0 2.10.0 | tee "$LOGS/B_seed.log"
grep -q "^PROBE [0-9.]* 2\.10\.0 " "$LOGS/B_seed.log"
bash install.sh --local 2>&1 | tee "$LOGS/B_head_rerun.log"
grep -q "existing install has torch 2.10.0 -- keeping it" "$LOGS/B_head_rerun.log"
"$UNSLOTH_STUDIO_HOME/unsloth_studio/bin/unsloth" studio update --local 2>&1 | tee "$LOGS/B_update.log"
bash "$HELPER" probe | tee "$LOGS/B_probe.log"
grep -q "existing install has torch 2.10.0 -- moving to torch>=2.13.0,<2.14.0" "$LOGS/B_head_rerun.log"
# Hosted macos-15 runners expose a paravirtual Metal device without MPS: the versions are checked always,
# MPS (and the helper's SDPA check) only where it is available.
grep -Eq "^PROBE [0-9.]+ 2\.13\.[0-9]+ 0\.28\.[0-9]+ 2\.11\.[0-9]+ mps (True|False)" "$LOGS/B_probe.log"
grep -q "^PROBE [0-9.]* 2\.10\.0 " "$LOGS/B_probe.log"

- name: "B2 (head): a second re-run and studio update keep 2.13"
env:
STUDIO_LOCAL_REPO: ${{ github.workspace }}
- name: "C (head): UNSLOTH_TORCH_UPGRADE=1 moves a 2.10 home to the new-install route"
run: |
set -o pipefail
bash install.sh --local 2>&1 | tee "$LOGS/B2_head_rerun.log"
grep -Eq "existing install has torch 2\.13\.[0-9]+ -- keeping it" "$LOGS/B2_head_rerun.log"
"$UNSLOTH_STUDIO_HOME/unsloth_studio/bin/unsloth" studio update --local 2>&1 | tee "$LOGS/B2_update.log"
bash "$HELPER" probe | tee "$LOGS/B2_probe.log"
grep -Eq "^PROBE [0-9.]+ 2\.13\.[0-9]+ 0\.28\.[0-9]+ " "$LOGS/B2_probe.log"

- name: "C (head): UNSLOTH_TORCH_UPGRADE=0 keeps a 2.10 home"
run: |
set -o pipefail
bash "$HELPER" seed 2.10.0 0.25.0 2.10.0 | tee "$LOGS/C_seed.log"
UNSLOTH_TORCH_UPGRADE=0 bash install.sh --local 2>&1 | tee "$LOGS/C_optout.log"
UNSLOTH_TORCH_UPGRADE=1 bash install.sh --local 2>&1 | tee "$LOGS/C_forced.log"
bash "$HELPER" probe | tee "$LOGS/C_probe.log"
grep -q "existing install has torch 2.10.0 -- keeping it" "$LOGS/C_optout.log"
grep -q "^PROBE [0-9.]* 2\.10\.0 " "$LOGS/C_probe.log"
if grep -q "existing install has torch 2.10.0 -- keeping it" "$LOGS/C_forced.log"; then exit 1; fi
# Hosted macos-15 runners expose a paravirtual Metal device without MPS: the versions are checked always,
# MPS (and the helper's SDPA check) only where it is available.
grep -Eq "^PROBE [0-9.]+ 2\.1[3-9]\.[0-9]+ [0-9.]+ [0-9.]+ mps (True|False)" "$LOGS/C_probe.log"

- name: "D (head): a 2.14.1 home is kept"
run: |
Expand Down
20 changes: 3 additions & 17 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4368,8 +4368,6 @@ _CU130_NEW_INSTALL_TORCH="torch>=2.13.0,<2.14.0"
# Apple Silicon: 2.13 is the first with fused MPS attention (mflux needs >=2.13); 2.15 lacks cp310/torchvision.
_MACOS_TORCH_CEILING="2.15.0"
_MACOS_NEW_INSTALL_TORCH="torch>=2.13.0,<2.14.0"
# An existing home below this moves to the new-install spec; fixed at Studio's fused-attention gate, not the pin.
_MACOS_TORCH_MOVE_FLOOR="2.13.0"

# ── Resolve repo root (for --local installs) ──
_REPO_ROOT="$(cd "$(dirname "$0" 2>/dev/null || echo ".")" && pwd)"
Expand Down Expand Up @@ -7037,7 +7035,6 @@ fi # _torch_index_pinned guard (Radeon + Strix reroute)
_PRESERVE_TORCH_CONSTRAINT="$TORCH_CONSTRAINT"
_CU130_NEW_INSTALL_ROUTE=false
_MACOS_NEW_INSTALL_ROUTE=false
_MACOS_FLOOR_MOVE=false
if [ "$SKIP_TORCH" = false ] && [ "$(_cu130_torch213_platform "$TORCH_INDEX_URL")" = "yes" ]; then
_PRESERVE_TORCH_CONSTRAINT="torch>=2.4,<${_CU130_TORCH_CEILING}"
# An existing home never takes 2.13 unasked, even when its torch could not be read or kept.
Expand All @@ -7049,31 +7046,20 @@ if [ "$SKIP_TORCH" = false ] && [ "$(_cu130_torch213_platform "$TORCH_INDEX_URL"
_CU130_NEW_INSTALL_ROUTE=true
fi
elif [ "$SKIP_TORCH" = false ] && [ "$(_macos_torch213_platform "$TORCH_INDEX_URL")" = "yes" ]; then
# Same policy as cu130: keep a resident 2.4-2.14, move a fresh home (or an explicit upgrade).
# Except a resident release below _MACOS_TORCH_MOVE_FLOOR (no fused MPS attention): it moves too when the route is
# open, unless UNSLOTH_TORCH_UPGRADE is set (=0 keeps it).
# Same policy as cu130: keep a resident 2.4-2.14, move only a fresh home (or an explicit upgrade).
_PRESERVE_TORCH_CONSTRAINT="${TORCH_CONSTRAINT%%,*},<${_MACOS_TORCH_CEILING}"
_macos_below_floor=false
if [ "$_EXISTING_INSTALL" = true ] && [ -z "${UNSLOTH_TORCH_UPGRADE:-}" ] \
&& [ -n "$(_previous_torch_pin "$_PREV_TORCH_VER" "${TORCH_CONSTRAINT%%,*},<${_MACOS_TORCH_MOVE_FLOOR}" keep)" ]; then
_macos_below_floor=true
fi
if [ "$(printf '%s' "$PACKAGE_NAME" | tr '[:upper:]' '[:lower:]')" = "unsloth" ] \
&& { [ "$_EXISTING_INSTALL" = false ] || [ "${UNSLOTH_TORCH_UPGRADE:-0}" = "1" ] || [ "$_macos_below_floor" = true ]; } \
&& { [ "$_EXISTING_INSTALL" = false ] || [ "${UNSLOTH_TORCH_UPGRADE:-0}" = "1" ]; } \
&& [ "${_torch_index_pinned:-false}" = false ] \
&& [ "$(_macos_torch213_host_ok)" = "yes" ] \
&& [ "$(_pypi_unsloth_admits_torch "2.13.0")" = "yes" ]; then
# an index set with UNSLOTH_TORCH_INDEX_URL (a mirror or snapshot) may not carry 2.13: only the chosen one moves
_MACOS_NEW_INSTALL_ROUTE=true
_MACOS_FLOOR_MOVE="$_macos_below_floor"
fi
fi
if [ "$_MACOS_FLOOR_MOVE" = true ]; then
substep "existing install has torch $_PREV_TORCH_VER -- moving to $_MACOS_NEW_INSTALL_TORCH for the fused MPS attention kernel (set UNSLOTH_TORCH_UPGRADE=0 to keep it)"
fi
_PREV_TORCH_PIN=""
_PREV_FALLBACK_CONSTRAINT="$TORCH_CONSTRAINT"
if [ "$SKIP_TORCH" = false ] && [ "$_MACOS_FLOOR_MOVE" = false ]; then
if [ "$SKIP_TORCH" = false ]; then
_prev_pin=$(_previous_torch_pin "$_PREV_TORCH_VER" "$_PRESERVE_TORCH_CONSTRAINT")
if [ -z "$_prev_pin" ] && [ "${UNSLOTH_TORCH_UPGRADE:-0}" = "1" ] \
&& [ "$_CU130_NEW_INSTALL_ROUTE" = false ] && [ "$_MACOS_NEW_INSTALL_ROUTE" = false ] \
Expand Down
89 changes: 5 additions & 84 deletions tests/sh/test_macos_torch213_route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ assert_eq "install.sh new-install body matches the replayed one" "yes" \
"$(grep -A2 '^if \[ -z "\$_PREV_TORCH_PIN" \] && \[ "\$_MACOS_NEW_INSTALL_ROUTE" = true \]; then$' "$INSTALL_SH" | tail -2 \
| tr -d '\n' | grep -qF 'TORCH_CONSTRAINT="$_MACOS_NEW_INSTALL_TORCH" TORCHVISION_CONSTRAINT="torchvision>=0.28.0,<0.29.0"' && echo yes)"
substep() { :; }
eval "$(grep -E '^_(CU130|MACOS)_(TORCH_CEILING|NEW_INSTALL_TORCH|TORCH_MOVE_FLOOR)=' "$INSTALL_SH")"
eval "$(grep -E '^_(CU130|MACOS)_(TORCH_CEILING|NEW_INSTALL_TORCH)=' "$INSTALL_SH")"
assert_eq "macOS ceiling" "2.15.0" "$_MACOS_TORCH_CEILING"
assert_eq "macOS new-install spec" "torch>=2.13.0,<2.14.0" "$_MACOS_NEW_INSTALL_TORCH"
assert_eq "macOS move floor is the fused-attention gate" "2.13.0" "$_MACOS_TORCH_MOVE_FLOOR"
SKIP_TORCH=false; TORCH_INDEX_URL="$CPU"; PACKAGE_NAME="unsloth"
_run_block() { # $1 existing-install flag, $2 previous torch version, $3 default floor
_EXISTING_INSTALL="$1"; _PREV_TORCH_VER="$2"
Expand All @@ -108,14 +107,10 @@ for gate in unreachable capped open; do
assert_eq "PyPI $gate: existing 2.13 kept" "torch==2.13.0" "$TORCH_CONSTRAINT"
_run_block true "2.14.1"
assert_eq "PyPI $gate: existing 2.14 kept" "torch==2.14.1" "$TORCH_CONSTRAINT"
if [ "$gate" != open ]; then
_run_block true "2.11.0"
assert_eq "PyPI $gate: existing 2.11 kept" "torch==2.11.0" "$TORCH_CONSTRAINT"
assert_eq "PyPI $gate: kept 2.11 keeps its torchvision window" "torchvision>=0.19,<0.27.0" "$TORCHVISION_CONSTRAINT"
assert_eq "PyPI $gate: kept pin falls back to the old default" "torch>=2.6,<2.12.0" "$_PREV_FALLBACK_CONSTRAINT"
_run_block true "2.10.0"
assert_eq "PyPI $gate: existing 2.10 kept (no 2.13 to move to)" "torch==2.10.0" "$TORCH_CONSTRAINT"
fi
_run_block true "2.11.0"
assert_eq "PyPI $gate: existing 2.11 kept" "torch==2.11.0" "$TORCH_CONSTRAINT"
assert_eq "PyPI $gate: kept 2.11 keeps its torchvision window" "torchvision>=0.19,<0.27.0" "$TORCHVISION_CONSTRAINT"
assert_eq "PyPI $gate: kept pin falls back to the old default" "torch>=2.6,<2.12.0" "$_PREV_FALLBACK_CONSTRAINT"
_run_block true ""
assert_eq "PyPI $gate: existing home with unreadable torch stays on the old default" "torch>=2.6,<2.12.0" "$TORCH_CONSTRAINT"
_run_block false ""
Expand Down Expand Up @@ -145,80 +140,6 @@ SKIP_TORCH=true; _run_block false ""; SKIP_TORCH=false
assert_eq "--no-torch never takes the route" "torch>=2.6,<2.12.0" "$TORCH_CONSTRAINT"
_stub_python 3.9; _run_block false "" 2.4; _stub_python 3.13
assert_eq "Python 3.9 keeps the old window" "torch>=2.4,<2.12.0" "$_PRESERVE_TORCH_CONSTRAINT"

echo "=== an existing home below the 2.13 floor moves to 2.13 when the route is open ==="
_pypi_fixture "torch<2.15.0,>=2.4.0"
_SUBSTEP_LOG=$(mktemp)
substep() { printf '%s\n' "$1" >> "$_SUBSTEP_LOG"; }
for prev in 2.10.0 2.11.0 2.12.1 2.6.0; do
: > "$_SUBSTEP_LOG"
_run_block true "$prev"
assert_eq "existing $prev moves to the new-install spec" "torch>=2.13.0,<2.14.0" "$TORCH_CONSTRAINT"
assert_eq "existing $prev moves torchvision with it" "torchvision>=0.28.0,<0.29.0" "$TORCHVISION_CONSTRAINT"
assert_eq "existing $prev is not a kept pin" "" "$_PREV_TORCH_PIN"
assert_contains "existing $prev: the move is announced with its opt-out" "$(cat "$_SUBSTEP_LOG")" "UNSLOTH_TORCH_UPGRADE=0"
assert_not_contains "existing $prev: no 'keeping it' line" "$(cat "$_SUBSTEP_LOG")" "keeping it"
done
_run_block true "2.10.0+cpu"
assert_eq "a local-tagged 2.10.0+cpu moves too" "torch>=2.13.0,<2.14.0" "$TORCH_CONSTRAINT"
for prev in 2.13.0 2.13.1 2.14.0 2.14.1; do
: > "$_SUBSTEP_LOG"
_run_block true "$prev"
assert_eq "existing $prev (at or above the floor) kept" "torch==$prev" "$TORCH_CONSTRAINT"
assert_contains "existing $prev: 'keeping it' line" "$(cat "$_SUBSTEP_LOG")" "keeping it"
done
for v in 0 false no; do
UNSLOTH_TORCH_UPGRADE=$v; _run_block true "2.10.0"; unset UNSLOTH_TORCH_UPGRADE
assert_eq "UNSLOTH_TORCH_UPGRADE=$v keeps an existing 2.10" "torch==2.10.0" "$TORCH_CONSTRAINT"
assert_eq "UNSLOTH_TORCH_UPGRADE=$v keeps the 2.10 torchvision window" "torchvision>=0.19,<0.27.0" "$TORCHVISION_CONSTRAINT"
done
UNSLOTH_TORCH_UPGRADE=""; _run_block true "2.10.0"; unset UNSLOTH_TORCH_UPGRADE
assert_eq "an empty UNSLOTH_TORCH_UPGRADE is the default (moves)" "torch>=2.13.0,<2.14.0" "$TORCH_CONSTRAINT"
UNSLOTH_TORCH_UPGRADE=1; _run_block true "2.10.0"; unset UNSLOTH_TORCH_UPGRADE
assert_eq "UNSLOTH_TORCH_UPGRADE=1 still moves an existing 2.10" "torch>=2.13.0,<2.14.0" "$TORCH_CONSTRAINT"
_torch_index_pinned=true; _run_block true "2.10.0"; _torch_index_pinned=false
assert_eq "a pinned index keeps an existing 2.10" "torch==2.10.0" "$TORCH_CONSTRAINT"
MACOS_MAJOR=13; _run_block true "2.10.0"; MACOS_MAJOR=15
assert_eq "macOS 13 keeps an existing 2.10 (no macosx_14_0 wheel)" "torch==2.10.0" "$TORCH_CONSTRAINT"
_stub_python 3.13 gil-disabled; _run_block true "2.10.0"; _stub_python 3.13
assert_eq "free-threaded Python keeps an existing 2.10" "torch==2.10.0" "$TORCH_CONSTRAINT"
PACKAGE_NAME="unsloth-fork"; _run_block true "2.10.0"; PACKAGE_NAME="unsloth"
assert_eq "--package other than unsloth keeps an existing 2.10" "torch==2.10.0" "$TORCH_CONSTRAINT"
_run_block true "2.12.0.dev20261001"
assert_eq "a nightly below the floor is unchanged (old default, never 2.13)" "torch>=2.6,<2.12.0" "$TORCH_CONSTRAINT"
_run_block true "2.3.1" 2.4
assert_eq "a release under the window floor is unchanged (old default)" "torch>=2.4,<2.12.0" "$TORCH_CONSTRAINT"
_stub_python 3.9; _run_block true "2.10.0" 2.4; _stub_python 3.13
assert_eq "Python 3.9 keeps an existing 2.10" "torch==2.10.0" "$TORCH_CONSTRAINT"
SKIP_TORCH=true; _run_block true "2.10.0"; SKIP_TORCH=false
assert_eq "--no-torch never moves an existing home" "torch>=2.6,<2.12.0" "$TORCH_CONSTRAINT"
_ARCH=x86_64; _run_block true "2.2.2" 2.2; _ARCH=arm64
assert_eq "Intel macOS keeps its torch (2.2.2)" "torch==2.2.2" "$TORCH_CONSTRAINT"
_ARCH=x86_64; _run_block true "2.2.2" 2.2; _ARCH=arm64
assert_eq "Intel macOS window untouched" "torch>=2.2,<2.12.0" "$_PRESERVE_TORCH_CONSTRAINT"
for os in linux wsl windows; do
OS=$os
_run_block true "2.10.0"
assert_eq "$os cpu: existing 2.10 kept" "torch==2.10.0" "$TORCH_CONSTRAINT"
assert_eq "$os cpu: window untouched" "torch>=2.6,<2.12.0" "$_PRESERVE_TORCH_CONSTRAINT"
TORCH_INDEX_URL="https://download.pytorch.org/whl/cu128"
_run_block true "2.10.0+cu128"
assert_eq "$os cu128: existing 2.10 kept" "torch==2.10.0" "$TORCH_CONSTRAINT"
TORCH_INDEX_URL="$CPU"
done
OS=macos
# A later pin bump (here to 2.14) must not move a 2.13 home: the floor is its own literal.
_pin_saved="$_MACOS_NEW_INSTALL_TORCH"; _MACOS_NEW_INSTALL_TORCH="torch>=2.14.0,<2.15.0"
_run_block true "2.13.0"
assert_eq "pin bumped to 2.14: an existing 2.13 home is kept" "torch==2.13.0" "$TORCH_CONSTRAINT"
_run_block true "2.13.1"
assert_eq "pin bumped to 2.14: an existing 2.13.1 home is kept" "torch==2.13.1" "$TORCH_CONSTRAINT"
_run_block true "2.10.0"
assert_eq "pin bumped to 2.14: an existing 2.10 home moves to the bumped pin" "torch>=2.14.0,<2.15.0" "$TORCH_CONSTRAINT"
_MACOS_NEW_INSTALL_TORCH="$_pin_saved"
rm -f "$_SUBSTEP_LOG"
substep() { :; }

OS=linux; TORCH_INDEX_URL="https://download.pytorch.org/whl/cu128"; _run_block false "" 2.4
assert_eq "Linux cu128 is untouched" "torch>=2.4,<2.12.0" "$TORCH_CONSTRAINT"
assert_eq "Linux cu128 window untouched" "torch>=2.4,<2.12.0" "$_PRESERVE_TORCH_CONSTRAINT"
Expand Down
Loading