Repository navigation
Studio: keep an Apple Silicon install's torch through studio update - #18659
Merged
Merged
Conversation
… core package resolve The core unsloth / unsloth-zoo update re-resolves with deps, and the UV_OVERRIDE freeze that keeps the resident torch trio was scoped to Linux and Windows x64 with torch >= 2.13. Apple Silicon now gets torch 2.13 only on a new install or a manual repair (UNSLOTH_TORCH_UPGRADE=1 through install.sh), so the update freezes every resident release there, the same way install.sh freezes the trio for every with-deps unsloth install. Linux, Windows and Intel macOS resolve exactly as before.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This was referenced Nov 26, 2026
danielhanchen
added a commit
that referenced
this pull request
Nov 26, 2026
…19772) ## Problem On Apple Silicon macOS runners, `studio/backend/tests/test_cu130_repair_torch_specs.py::test_core_update_freezes_only_torch_past_the_released_ceiling[darwin-2.13.0-False]` fails. For example, the macos-26 leg of the cross-platform staging run for #19762: ``` assert mod._TORCH_FREEZE_ACTIVE is pinned E AssertionError: assert True is False ``` The test passes on Linux, which is why the normal CI shards never show it. ## Cause - #18659 made `_FreezeNewTorchForCoreUpdate` keep an Apple Silicon install's torch at any release: `sys.platform == "darwin" and platform.machine() == "arm64"`. - This test fakes `sys.platform` per row but read the real `platform.machine()`. Its darwin row expects no freeze, so the row really means Intel macOS. - On an x64 Linux runner the machine is `x86_64` and the row passes. On an arm64 macOS runner it is `arm64`, the freeze engages, and the row fails. The code is correct, and Apple Silicon's freeze is already covered by `test_macos_core_update_torch_freeze.py`. The test is host-dependent. ## Fix Pin `platform.machine()` to `x86_64` in this test, so every row describes an x64 host and the darwin row is Intel macOS on any runner. No product code changes. ## Verification To reproduce an Apple Silicon host on Linux, a small plugin sets `platform.machine = lambda: "arm64"` before the session: | Arm | Simulated arm64 host | Native x86_64 host | |---|---|---| | main 6a3a230 | `1 failed, 57 passed`: the same `darwin-2.13.0-False` row as the macos-26 job | `58 passed` | | this branch | `58 passed` | `58 passed` | Sabotage: making the freeze apply to every macOS machine (dropping the `platform.machine() == "arm64"` check in `studio/install_python_stack.py`) fails the darwin row on this branch. The row therefore still guards that Intel macOS is not frozen. #19762 edits the same parametrize list. Its own macOS failure is this one, so it will pass once this lands.
danielhanchen
added a commit
that referenced
this pull request
Nov 27, 2026
… fused-MPS-attention release on re-run (#20038) ## 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 - #6959 / #7250: a re-run should keep the torch release a user has validated. The trigger was a silent 2.10 to 2.11 move on a CUDA host. That still holds at or above 2.13 here. - #12150: on CUDA, the torch release is tied to prebuilt flash-attn, causal-conv1d and mamba-ssm wheels. `studio update` can also re-resolve torch under an older release's cap. Apple Silicon has no such prebuilt kernels. The PyPI gate is kept, and #18659 freezes the resident torch through `studio update` on Apple Silicon, so a moved home stays on 2.13 there. - torchcodec is chosen from the resident torch on every `install_python_stack.py` pass, so it follows the move. - A re-run rebuilds the venv anyway. A failed install rolls back to the previous environment, unless `--no-rollback` was passed. ## 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 #19870. - GitHub's macOS runners are virtual machines, so they show that the install works, not how fast it runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unsloth studio updatere-resolvesunslothandunsloth-zoowith dependencies. On Linux and Windows x64,_FreezeNewTorchForCoreUpdatepins the resident torch, torchvision and torchaudio throughUV_OVERRIDEwhile that happens, but only for torch >= 2.13. macOS had no freeze.Apple Silicon is moving to torch 2.13 for new installs only (#18428). Existing installs keep their torch unless the user runs a manual repair, which sets
UNSLOTH_TORCH_UPGRADE=1through install.sh. Without a freeze, a released unsloth with a torch ceiling (2026.9.11 declaredtorch<2.13.0) could move a 2.13 Mac install back to 2.12 onstudio update. A torch floor could also move a 2.11 install up.Change
studio/install_python_stack.py: on Apple Silicon (darwin+arm64),_FreezeNewTorchForCoreUpdatenow freezes every resident plainX.Y.Ztorch release, not only >= 2.13. install.sh already freezes the trio this way for every with-deps unsloth install, on every OS. The bundledoverrides-darwin-arm64.txtis folded into the frozen file, minus any torch lines, so the MLX transformers / anyio / huggingface_hub overrides still apply.UV_OVERRIDEand would honour the released cap. This is the same behaviour Linux already has under the freeze.Tests
New file:
studio/backend/tests/test_macos_core_update_torch_freeze.py, CPU only.UV_OVERRIDEis restored afterwards.UV_OVERRIDEis restored to unset.Base (main) vs head: 6 tests fail on main and pass on the branch. The 6 host-unchanged cases pass on both. No head test fails.
Across all 75 test files that import
install_python_stack(8.5k tests), the head's failing test IDs are a subset of main's. The failures are pre-existing and come from this host's environment. They are identical apart from one ROCm spoof test that failed only on the main arm.Not covered