Skip to content

install.sh: move existing Apple Silicon homes below torch 2.13 to the fused-MPS-attention release on re-run - #20038

Merged
danielhanchen merged 4 commits into
mainfrom
studio-macos-torch-floor-upgrade
Nov 27, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-macos-torch-floor-upgrade

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

New Apple Silicon homes get torch 2.13 (#18428), because 2.13 is the first release with the fused MPS prefill attention kernel. Studio only enables that kernel on torch 2.13 or newer (mps_prefill_supported in diffusion_attention.py). An existing home keeps whatever torch it has, from 2.4 up to 2.14, unless the user sets UNSLOTH_TORCH_UPGRADE=1. So every Mac that was installed before #18428 keeps its old torch and runs diffusion on the math-only attention path.

On a MacBook Pro M5 Max with the same Studio backend and the same prompts, warm time per 1024x1024 image was:

Pipeline torch 2.10.0 (that Mac's existing home) torch 2.14.1
FLUX.2 klein, bf16 8.60 s 3.69 s
FLUX.2 klein, GGUF 11.30 s 6.39 s
Z-Image, GGUF 64.37 s 18.00 s

Peak memory was also 3 to 5 GB lower on the newer torch. A large-linear check showed no corruption on either version. The images are not pixel-identical across versions, because the MPS random generator stream changed between those releases. Within a single version, repeated runs are bit-identical.

Change

The change is in install.sh, on the macOS arm64 route only. On a re-run, an existing home whose resident torch is a plain release below _MACOS_TORCH_MOVE_FLOOR (2.13.0, the release Studio's fused MPS attention gate needs) now takes the same torch>=2.13.0,<2.14.0 / torchvision>=0.28.0,<0.29.0 constraint that a new home gets. torchaudio resolves to 2.11.x, as it does on a new home. This happens only when every gate of the new-install route already holds:

  • the package is unsloth;
  • the index is the default cpu index (an index set with UNSLOTH_TORCH_INDEX_URL or UNSLOTH_TORCH_INDEX_FAMILY never moves);
  • macOS 14 or later, with a GIL-enabled Python 3.10 to 3.14;
  • the released unsloth on PyPI admits torch 2.13. An unreachable or capped PyPI keeps the resident release.

These cases are unchanged:

  • A home already on 2.13 or 2.14 is kept.
  • A home whose torch cannot be read, or holds a nightly, takes the same path as before.
  • UNSLOTH_TORCH_UPGRADE=0 (any value other than empty or 1) keeps the resident release.
  • UNSLOTH_TORCH_UPGRADE=1 behaves as before.

The move floor is its own literal, not derived from _MACOS_NEW_INSTALL_TORCH. A later bump of the new-install pin (for example to 2.14) therefore never moves a 2.13 home. Homes below 2.13 move to whatever the pin is at that point.

The installer prints existing install has torch X -- moving to torch>=2.13.0,<2.14.0 for the fused MPS attention kernel (set UNSLOTH_TORCH_UPGRADE=0 to keep it).

This follows the rule the installer already uses for a raised floor (#7250): a release below a route's floor is outside the preservation window, so it moves. On ROCm 7.2 and Strix, that floor is 2.11. Here it is 2.13.

Linux, WSL, Windows (install.ps1 is untouched), Intel macOS, CUDA, ROCm and XPU take exactly the same decisions as before. The new code runs only inside the macOS arm64 branch, and the shared pin block skips _previous_torch_pin only when that branch has decided to move.

Why existing homes were preserved, and why this is safe on Apple Silicon

Tests

  • tests/sh/test_macos_torch213_route.sh: 132 checks. 22 fail on main. 3 more fail on a version of this branch that derived the floor from the pin: the floor literal, and a pin bumped to 2.14 still keeping 2.13.0 and 2.13.1 homes.
    • Existing 2.6 / 2.10 / 2.11 / 2.12.1 homes, and 2.10.0+cpu, move to the 2.13 constraint and announce the opt-out.
    • These homes are kept: 2.13.0 / 2.13.1 / 2.14.0 / 2.14.1; UNSLOTH_TORCH_UPGRADE=0|false|no; a pinned index; macOS 13; free-threaded Python; Python 3.9; another --package; an unreachable or capped PyPI.
    • With the pin bumped to 2.14 in the test: 2.13.0 and 2.13.1 homes are kept, and a 2.10 home moves to the bumped pin.
    • These are unchanged: a nightly, a release under the window floor, --no-torch, Intel macOS, and Linux / WSL / Windows on the cpu and cu128 indexes.
  • Unchanged and passing: test_cu130_torch213_route.sh (104), test_previous_torch_pin.sh (50), test_get_torch_index_url.sh (109), test_torch_constraint.sh, and tests/python/test_macos_torch213_pins.py.
  • Whole tests/sh suite: all 101 scripts pass on this branch, and all of them pass on the merge base too (the base runs its own copy of the route test).
  • Workflow lints: scripts/lint_workflow_triggers.py and actionlint pass. 58 test files read the workflow files: 3655 passed. The 2 failures (test_cached_paths_hold_no_credentials, test_version_compat_bundle daily sweep) fail the same way on the merge base, because of this host's environment.

Upgrade run on macOS 15

.github/workflows/studio-mac-torch-floor-upgrade.yml (helper .github/scripts/mac-torch-floor-upgrade.sh) runs on macos-15 with Python 3.13 and 3.10. It starts a home with the merge base installer and moves it to torch 2.10.0 / torchvision 0.25.0 / torchaudio 2.10.0. Then it checks:

  • A: re-running the merge base installer keeps 2.10.
  • B: re-running this branch's installer moves the home to 2.13.x / 0.28.x / 2.11.x, with MPS available and MPS attention matching an fp64 CPU reference.
  • B2: a second re-run, then unsloth studio update --local, keep 2.13.
  • C: UNSLOTH_TORCH_UPGRADE=0 keeps a 2.10 home.
  • D: a 2.14.1 home is kept.

The workflow runs on dispatch, and on pull requests only outside unslothai/unsloth. On this repository's pull requests the job is skipped, so it takes no macOS runner. It also skips drafts.

Results: pending.

Not covered

  • The Desktop automatic startup repair runs the installer without UNSLOTH_TORCH_UPGRADE, so a repair of a home below 2.13 now moves it to 2.13 as well. This is intended. Set UNSLOTH_TORCH_UPGRADE=0 in the environment to keep the resident torch.
  • The Desktop app updates through unsloth studio update, which never runs install.sh. A Desktop home that is never repaired or re-installed keeps its torch. It moves through Settings > Repair installation, which already sets UNSLOTH_TORCH_UPGRADE=1. Follow-up: a Studio "Repair recommended" hint for Apple Silicon homes below 2.13, like the Windows one in Studio on Windows: recommend Repair when an existing home is older than the managed torch / xFormers #19870.
  • GitHub's macOS runners are virtual machines, so they show that the install works, not how fast it runs.

…e 2.13 route on re-run

An existing macOS arm64 home kept its resident torch (2.4 to 2.14) unless
UNSLOTH_TORCH_UPGRADE=1, so homes installed before #18428 stay on a torch
without the fused MPS prefill attention kernel that Studio gates on 2.13.

A resident plain release below 2.13 now takes the new-install constraint
when every gate of that route holds (package unsloth, default cpu index,
macOS 14+, GIL Python 3.10-3.14, PyPI unsloth admits 2.13). Homes at 2.13
or 2.14, an unreadable or nightly torch, a pinned index, and any non-empty
UNSLOTH_TORCH_UPGRADE other than 1 behave as before. Every other OS and
index takes the same decisions.
…rade run

The move floor is now its own literal (_MACOS_TORCH_MOVE_FLOOR, Studio's
fused MPS attention gate) instead of the new-install pin's lower bound, so
a later pin bump never moves a 2.13 home. Tested with the pin bumped to 2.14.

studio-mac-torch-floor-upgrade.yml seeds an existing torch 2.10 home on
macos-15 and re-runs the merge base installer (kept) and this one (moved to
2.13), then checks a second re-run plus studio update, the
UNSLOTH_TORCH_UPGRADE=0 opt-out and a 2.14.1 home. It runs on dispatch and
on pull requests outside unslothai/unsloth only, and skips drafts.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T22:16:18.717672Z acbff67 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0683a4f841

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

bash install.sh --local 2>&1 | tee "$LOGS/B_head_rerun.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"
grep -Eq "^PROBE [0-9.]+ 2\.13\.[0-9]+ 0\.28\.[0-9]+ 2\.11\.[0-9]+ mps True" "$LOGS/B_probe.log"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow the upgrade probe to pass without MPS on hosted runners

On the GitHub-hosted macos-15 runner selected by this job, MPS is unavailable: the existing .github/workflows/studio-mac-ui-smoke.yml explicitly runs CPU-only because hosted macOS exposes a paravirtual Metal device, and tests/test_mlx_trl_lazy_all.py also accounts for these runners lacking MPS. The new helper correctly skips its attention check when torch.backends.mps.is_available() is false, but this assertion then rejects its mps False output even when the torch upgrade succeeds. Consequently, the workflow fails at B and never exercises B2, C, or D. Keep the version assertions unconditional and make the MPS requirement conditional, or run the MPS-specific assertion on a runner with supported GPU access.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push. The B step now always checks the torch, torchvision and torchaudio versions, and accepts mps True or mps False. On hosted macos-15 runners MPS is unavailable, so the helper already skips its SDPA check there and B no longer stops the job; B2, C and D run as well. Where MPS is available, the helper's fp64-referenced SDPA check still asserts cosine above 0.999.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: e7f1f6d4c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

The macOS upgrade legs failed because the seed helper only looked for uv on PATH and in ~/.local/bin, while install.sh keeps its own uv under the Studio home when UNSLOTH_STUDIO_HOME is set. The helper now checks $UNSLOTH_STUDIO_HOME/uv/uv first. The two other reds in staging (the amd-smi parity check and test_recipes_without_stdio_and_ui_sessions_still_save) fail the same way on a clean main checkout.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: acbff670af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Nov 27, 2026
…t (red on main since #19615) (#20060)

## Problem

The `parity (ubuntu-latest)` job fails one check in
`tests/studio/test_nvidia_adapter_presence.ps1` on main (`bcbfe14c4f`),
for example on the #20038 staging run:

```
FAIL  WMI without the AMD card: an opted-in amd-smi vetoes the promotion
1 check(s) failed
```

#19615 made the Windows installers stop running `amd-smi`, because it
pops a UAC prompt that cannot be suppressed. With it went the
`UNSLOTH_ENABLE_AMD_SMI` opt-in in `Test-OtherVendorAdapterPresent`,
which used to let an opted-in `amd-smi` veto promoting the NVIDIA route.
That was the intended change, and `install.ps1` and `studio/setup.ps1`
no longer mention `amd-smi` at all. This test still listed "an opted-in
amd-smi" among the signals that veto, so it now asserts behaviour that
was deliberately removed.

## Fix

- The opted-in `amd-smi` case is dropped from the list of AMD signals
that veto the promotion. `hipinfo` on PATH, a HIP SDK under `HIP_PATH`,
and a HIP SDK under `ROCM_PATH` still veto, and are still checked.
- The `amd-smi` check now asserts what #19615 made true: `amd-smi` on
PATH does not veto, either without the opt-in or with
`UNSLOTH_ENABLE_AMD_SMI=1`.
- The new assertion with the opt-in set would have failed on the code
before #19615, so a return of the `amd-smi` probe would be caught.

## Verification

- `pwsh -NoProfile -File tests/studio/test_nvidia_adapter_presence.ps1`
on Linux: `all checks passed`. Before, on main: `1 check(s) failed`, the
line above.
- The test file stays ASCII-only.
danielhanchen added a commit that referenced this pull request Nov 27, 2026
…s (red on main since #19610) (#20062)

## Problem


`studio/backend/tests/test_managed_account_route_gates.py::test_recipes_without_stdio_and_ui_sessions_still_save`
fails on main (`448e211080`), in `(Python 3.13, m-r)`, for example on
the #20038 staging run:

```
TypeError: recipe_store.<locals>.<lambda>() takes 2 positional arguments but 3 were given
```

#19610 (keep recipe edits made just before leaving the editor) gave
`storage.data_recipes_db.upsert_recipe` a third parameter, `also_base`.
The save route now passes `recipe.alsoBaseUpdatedAt` to it. That change
is correct. The test's `recipe_store` fixture replaced `upsert_recipe`
with a two-argument lambda, so the route's real call no longer fits the
stub.

## Fix

The fixture builds both stubs (`upsert_recipe`, `import_legacy`) with
`_shaped_like(real, fake)`:
- Each call is bound against the real function's signature first, then
handed to the fake.
- A parameter the real function gains no longer breaks the stub.
- A call the real function would reject, such as an extra positional
argument, still fails here, because the bind raises.

## Verification

- `tests/test_managed_account_route_gates.py`: 13 passed. Before, on
main: `test_recipes_without_stdio_and_ui_sessions_still_save` failed
with the `TypeError` above.
- The `upsert_recipe` stub accepts the route's three-argument call, and
rejects a fourth positional argument with `TypeError: too many
positional arguments`, as the real function does.
@danielhanchen
danielhanchen merged commit e4207ed into main Nov 27, 2026
1 check passed
@danielhanchen
danielhanchen deleted the studio-macos-torch-floor-upgrade branch November 27, 2026 22:59
danielhanchen added a commit that referenced this pull request Nov 27, 2026
…ute (red on staging since #20038 landed) (#20069)

## Summary

`Studio macOS torch floor upgrade` (`existing torch 2.10 home`, both
Python legs) now fails on every staging run of a PR that touches
`install.sh`. #20066 is the current example. The failing step is arm A,
which re-runs the merge base's `install.sh` on a home seeded with torch
2.10:

```
grep -q "existing install has torch 2.10.0 -- keeping it" "$LOGS/A_base_rerun.log"
##[error]Process completed with exit code 1.
```

#20038 added this workflow to show its own change: its merge base kept a
2.10 home, and its head moves it to the 2.13 route. Arm A hard-coded
what that pre-#20038 base does. Since #20038 merged, every merge base
contains the 2.13 route, so the base re-run correctly says:

```
existing install has torch 2.10.0 -- moving to torch>=2.13.0,<2.14.0 for the fused MPS attention kernel (set UNSLOTH_TORCH_UPGRADE=0 to keep it)
```

It then installs 2.13.0, and arm A fails. The installer is right and the
arm's fixed expectation is out of date. A second, hidden problem follows
from the first: once A moves the home to 2.13, arm B no longer starts
from a 2.10 home. B's `moving to torch>=2.13.0` check would then fail
too, even with a correct head.

## Changes

- `.github/scripts/mac-torch-floor-upgrade.sh` gains `check-route T
INSTALL_LOG PROBE_LOG`. A re-run of a home on torch `T` must either:
  - say `keeping it` and leave the probe on `T`, or
  - say `moving to torch>=LO,<HI` and leave the probe inside that range.

Anything else fails: no route line, a route line the probe contradicts,
or a missing probe line.
- Arm A runs `check-route 2.10.0`. It now checks the merge base against
the route its own log names, so it holds before and after a routing
change lands.
- Arm B reseeds the home to torch 2.10 before re-running the head
installer, so it always starts from the state it is meant to test,
whatever A did.

Arms B, B2, C and D (the head's own expectations) are unchanged.

## Verification

- `check-route` against fixtures built from the failing job's real log
lines:
- pass: `moving to >=2.13.0,<2.14.0` with the probe on 2.13.0, and
`keeping it` with the probe on 2.10.0;
- fail: `moving` with the probe still on 2.10.0, `moving` with the probe
on 2.14.1, `keeping` with the probe on 2.13.0, no route line, and no
probe line.
- `shellcheck` is clean, and the script is `bash -n` clean. The
version-regex escape uses `sed` rather than `${var//}`, so it does not
rely on the replacement quoting of newer bash; macOS `/bin/bash` is 3.2.
- The workflow runs on the staging repos (it is skipped on
`unslothai/unsloth` pull requests). This change touches the workflow, so
the staging run of this PR exercises the edited arms on `macos-15` for
both Python legs.
danielhanchen added a commit that referenced this pull request Nov 28, 2026
…re-run again (repair still upgrades) (#20076)

## Summary

Existing Apple Silicon Studio homes keep the torch they were installed
with on a plain install.sh re-run again. #20038 moved homes below torch
2.13 to the new-install release on any re-run; that is now reverted. An
existing home moves only on:

- a fresh install, or
- a repair: Desktop's Repair passes `UNSLOTH_TORCH_UPGRADE=1`
(`studio/src-tauri/src/install.rs`), and anyone running install.sh by
hand can set the same variable.

`unsloth studio update` keeps the home's torch as before.

## Changes

- `install.sh`: drops `_MACOS_TORCH_MOVE_FLOOR` and the below-floor
branch from #20038. The new-install route and the
`UNSLOTH_TORCH_UPGRADE=1` path are unchanged.
- `tests/sh/test_macos_torch213_route.sh`: back to its pre-#20038 checks
(73 pass).
- `.github/workflows/studio-mac-torch-floor-upgrade.yml` (macOS 15
staging only, skipped on this repo): on a seeded torch 2.10 home,
  - a plain re-run and `studio update` keep 2.10;
  - `UNSLOTH_TORCH_UPGRADE=1` moves it to the new-install route;
  - a 2.14.1 home is kept.

The merge base arm still checks the base against its own log, so it
passes with and without #20038 in the base.

## Not proven here

- Desktop's Repair on a physical Mac was not clicked in this PR; the
flag it passes is covered by the existing Tauri test
`only_a_manual_repair_asks_the_installer_for_a_newer_torch`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant