Skip to content

Studio: switch llama.cpp backends from the UI - #8520

Merged
danielhanchen merged 26 commits into
unslothai:mainfrom
oobabooga:llama-backend-switcher
Aug 13, 2026
Merged

danielhanchen merged 26 commits into
unslothai:mainfrom
oobabooga:llama-backend-switcher

Conversation

@oobabooga

@oobabooga oobabooga commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Adds a llama.cpp backend selector under Settings > System > GGUF inference engine. Users can switch between Automatic, CPU, CUDA, ROCm, and Vulkan without restarting Studio or reinstalling from the shell.
print

Behavior

The selector only offers alternatives that have a compatible bundle for the machine and installed llama.cpp release. Vulkan is the broad fallback for NVIDIA, AMD, and Intel GPUs where a compatible Linux or Windows bundle exists. ROCm requires a published artifact matching the AMD GPU's gfx target.

Explicit choices are saved in UNSLOTH_PREBUILT_INFO.json and preserved across later updates. Automatic restores hardware detection, while UNSLOTH_LLAMA_CPP_BACKEND continues to override the saved choice.

A named backend that cannot be served here fails the install rather than substituting a different one. install_llama_prebuilt.py makes that call, including for a choice recorded only in the marker, and reports it with its own exit code; setup.sh and setup.ps1 route on that code instead of re-deriving the request from the environment, which is the only part of it they can see.

Switching uses the same serialized install job as llama.cpp updates, preventing concurrent updates, switches, or browser tabs from modifying the install together. An active model is unloaded before the bundle is replaced and must be loaded again afterward, but Studio itself does not need to restart. A slim whisper.cpp install borrows llama.cpp's ggml libraries, so it is reinstalled for the new backend once the llama phase lands; stable-diffusion.cpp remains independent.

The feature works in web and Tauri builds that include this change. The previously published v0.1.701-beta desktop binary does not contain it.

Testing

  • Backend installer, marker, update, switch, and race coverage
  • Frontend tests, type checking, lint, localization parity, and production build

@oobabooga

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: 3029526d67

ℹ️ 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".

Comment thread studio/setup.sh Resolved
Comment thread studio/setup.sh Resolved
Comment thread studio/install_llama_prebuilt.py Resolved
Comment thread studio/install_llama_prebuilt.py Resolved

@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: 973a25c600

ℹ️ 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".

Comment thread studio/setup.sh Resolved
Comment thread studio/setup.sh Resolved
Comment thread studio/backend/routes/llama.py Resolved
Comment thread studio/install_llama_prebuilt.py Resolved

@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: 6b7cc1ec10

ℹ️ 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".

Comment thread studio/setup.sh Resolved

@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: dd638d970d

ℹ️ 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".

Comment thread studio/install_llama_prebuilt.py Resolved

@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: ecf20008eb

ℹ️ 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".

@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: b2873432ef

ℹ️ 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".

Comment thread studio/prebuilt_core.py Resolved

@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: cd3b88da29

ℹ️ 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".

Comment thread studio/setup.sh Resolved

@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: 1dc78b1ad9

ℹ️ 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".

Comment thread studio/install_llama_prebuilt.py Resolved
Comment thread studio/setup.sh Resolved
@oobabooga

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: d3af574434

ℹ️ 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".

@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: e190343fea

ℹ️ 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".

@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: 91268c31a7

ℹ️ 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".

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: e8af85d268

ℹ️ 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".

@tugucuk31

Copy link
Copy Markdown

cuda + rocm backend dynamic loading ??? (-DGGML_BACKEND_DL=ON)

@danielhanchen

Copy link
Copy Markdown
Member

Before/after evidence for this PR, from two isolated Studio installs built with install.sh --local at the merge base (9c46cc4a8) and at the head (a8f190636). Same scene driven against both, same viewport, same fixed clip. Host is Linux + a single NVIDIA B200, no AMD GPU, and both homes ended up on a managed prebuilt (b10360-mix-87da1a2).

Settings > System, at the section boundary. Before, "GPU devices" runs straight into "Model memory". After, the new section sits between them, with the trigger reading Automatic (CUDA), the line "llama.cpp currently runs on CUDA.", and Apply correctly disabled because the stored request already matches what is installed.

Settings System tab, before and after

The picker open. Before there is no control to open. After it lists exactly four rows and ROCm is absent, which the API confirms is the availability filter rather than a rendering accident.

Compute backend dropdown, before and after

GET /api/llama/backend goes from 404 on the base to:

{
  "supported": true, "reason": null, "env_backend": null,
  "backend": "cuda", "backend_request": "auto", "selection_applied": true,
  "installed_tag": "b10360-mix-87da1a2",
  "options": [
    {"backend": "auto",   "available": true,  "resolved_backend": "cuda",   "download_size_bytes": 229262760},
    {"backend": "cpu",    "available": true,  "resolved_backend": "cpu",    "download_size_bytes": 16730497},
    {"backend": "cuda",   "available": true,  "resolved_backend": "cuda",   "download_size_bytes": 229262760},
    {"backend": "rocm",   "available": false, "unavailable_reason": "unavailable", "resolved_backend": null},
    {"backend": "vulkan", "available": true,  "resolved_backend": "vulkan", "download_size_bytes": 32738678}
  ]
}

One quieter change worth recording, since no screenshot of the new section would show it: the pre-existing /api/llama/update-status job model gains operation and requested_backend on this branch, which is how the switch shares the update job.

Test runs on the head, on this box: the eight llama backend suites under studio/backend/tests/ pass (602 passed, 1 skipped), tests/studio/install/test_install_llama_prebuilt_logic.py passes (111 passed, 1 skipped), and the frontend suite passes (2023 passed) with npm run typecheck clean.

The Source lint job fails on studio/install_llama_prebuilt.py: scripts/verify_import_hoist.py
reports INSTALL_KIND_BACKENDS and marker_backend as hoisted but unused.

marker_backend is genuinely dead here, so it goes. INSTALL_KIND_BACKENDS is not: the
installer is meant to share one vocabulary with the marker readers, and two tests assert
that through this module. Give it a real use instead of a bare re-export by deriving
VULKAN_INSTALL_KINDS from the map rather than spelling the same two names out again, which
also removes a mirrored definition of the kind this file warns about elsewhere.
read_install_marker returns whatever json.loads produced, so a marker holding [] or 123
reaches callers as something without .get. Every caller assumes a mapping, and the new
backend picker adds one more: get_backend_status calls marker_backend(marker) and raises
AttributeError, so GET /api/llama/backend answers 500 and Settings > System shows a load
error for what is only a corrupt file.

This is not new on this branch (get_update_status raises the same way on main), but the
picker makes it reachable from a page users open. Guard it where the file is read, so the
update planner, the picker and crash recovery all degrade to the source-build path
together, exactly as they already do for unparseable JSON.
The Select is disabled whenever env_backend is set, but Apply is gated only on dirtiness,
and the two are computed independently. An automatic install whose detection has since
drifted reports selection_applied false, so the row is dirty while the Select is disabled
and Apply becomes the only live control. POST /api/llama/backend then refuses it with
environment_override, which is correct, but the button should not have offered it.

Also fills in the status shapes the payload tests did not reach: every unsupported reason,
a macOS install reporting metal, and the terminal job states.
The Windows half of the fail-closed change was asserted by comparing source strings, which
cannot catch a branch that reads the same and behaves differently. Extract the routing
block the way the bash harness already does, run it under pwsh, and require the same
decision from both: identical exit code, and identical answer on whether a source build
was queued.

Covers exit codes 0/1/2/3/4/5/137 against each explicit backend and both install states,
70 pairs, and pins the two branches the picker depends on: exit 5 fails closed everywhere,
exit 2 stays the one automatic path allowed to fall back to a compile. Skipped where pwsh
is absent, like the other PowerShell tests here.
@danielhanchen

Copy link
Copy Markdown
Member

I pushed four commits to this branch after simulating the compatibility surface. Summary of what I ran and what it showed.

The one thing that was actually red

Source lint fails on this branch, and it is ours: scripts/verify_import_hoist.py reports INSTALL_KIND_BACKENDS and marker_backend in studio/install_llama_prebuilt.py as hoisted but unused. marker_backend is dead there so I removed it. INSTALL_KIND_BACKENDS is not dead in spirit, since two tests assert the installer shares the vocabulary through this module, so instead of a bare re-export I derived VULKAN_INSTALL_KINDS from the map. The set is byte-identical to the literal it replaces and test_llama_backend_selection.py:102 already pins it. The gate now reports OVERALL: PASS.

The other red jobs are not this PR. The Python matrices fail on test_desktop_auth.py, test_gemini_provider.py and test_external_provider_usage_chunk.py, and Unsloth Updating Tests died fetching diffusers from GitHub.

Host matrix

Drove resolve_backends_payload against the real b10360-mix-87da1a2 release with only detect_host fabricated, 14 cells. Every one is right:

host auto resolves to offered hidden
linux x64 nvidia cuda auto, cpu, cuda, vulkan rocm
linux x64 amd gfx1100 rocm auto, cpu, rocm, vulkan cuda
linux x64 cpu only cpu auto, cpu, vulkan cuda, rocm
linux x64 intel vulkan auto, cpu, vulkan cuda, rocm
linux x64 nvidia + amd cuda auto, cpu, cuda, rocm, vulkan none
linux arm64 nvidia cuda auto, cpu, cuda rocm, vulkan
linux arm64 cpu cpu auto, cpu cuda, rocm, vulkan
wsl2 nvidia cuda auto, cpu, cuda, vulkan rocm
windows x64 nvidia cuda auto, cpu, cuda, vulkan rocm
windows x64 amd rocm auto, cpu, rocm, vulkan cuda
windows x64 cpu only cpu auto, cpu, vulkan cuda, rocm
windows arm64 cpu auto, cpu cuda, rocm, vulkan
macos arm64 / x64 metal auto none

Worth noting three of these specifically. The mixed NVIDIA plus AMD host still offers ROCm, so the re-probe in route_backend_request does its job. Windows AMD resolves through windows-rocm, which matters because this release publishes no windows-hip at all. And Linux arm64 correctly reports Vulkan as unavailable rather than silently crossing to ggml-org and moving the pinned release.

Note the caveat on WSL: HostInfo cannot express it, so that row is Linux plus NVIDIA. The WSL specific behaviour lives inside detect_host's HSA_ENABLE_DXG_DETECTION branch, which a fabricated host does not reach.

Old installs

Ran every marker shape a pre-existing install can have through the readers. All 22 behave, including force_cpu without backend_request, a blank or non-string backend_request, llama_backend: 7, and a future sycl. Two results worth having in writing:

  • A marker holding valid JSON that is not an object (["cpu"], "cuda", 123) raised AttributeError out of get_backend_status, so GET /api/llama/backend answered 500 and Settings > System showed a load error. This is not new on this branch, get_update_status raises the same way on main, but the picker makes it reachable from a page users open. I fixed it at read_install_marker so the update planner, the picker and crash recovery all degrade to the source build path together, the way they already do for unparseable JSON.
  • Downgrades are safe. Every picker choice is still written to the legacy force_cpu and llama_backend keys as well as the new ones, so an older Studio reading the marker keeps the pin rather than re-detecting. Checked for cpu, cuda, rocm, vulkan and auto.

setup.sh against setup.ps1

The PowerShell half of the exit routing was asserted by comparing source strings, which cannot catch a branch that reads the same and behaves differently. I added a harness that extracts the block and runs it under pwsh, then requires the same decision from both scripts: same exit code, same answer on whether a source build was queued. 70 pairs, exit codes 0/1/2/3/4/5/137 against each explicit backend and both install states. All 70 agree.

That also measures the change this PR is really making. On the merge base, exit 2 with a concrete cuda request queues a hardware detected source build, so the request can finish as ROCm or CPU, and only Vulkan was guarded. On this branch the concrete case exits 5 and fails closed on both platforms, and exit 2 stays the one automatic path allowed to fall back.

Browsers

Drove the picker in Chromium, Firefox and WebKit against one Studio built from this branch. All three read Automatic (CUDA), list the same four options, keep Apply disabled, and survive Escape inside the Select with the Settings dialog still open. Zero page errors in any engine. Chromium covers Chrome and Edge; WebKit is the engine, not Safari itself. This felt worth doing rather than assuming, because a Radix Select inside a Radix Dialog is the exact pairing behind radix-ui/primitives#2505 and the Gecko releasePointerCapture problem.

One small UI fix

The Select is disabled whenever env_backend is set, but Apply was gated only on dirtiness, and the two are computed independently. An automatic install whose detection has since drifted reports selection_applied: false, so the row is dirty while the Select is disabled and Apply becomes the only live control. The server refuses it with environment_override, which is right, but the button should not have offered it. I gated Apply on the same conditions and added the payload cases that were missing: every unsupported reason, a macOS install reporting metal, and the terminal job states.

Test runs

studio/backend/tests in full: 22617 passed against 22614 on the branch before these commits, with an identical failure set. The three that differed are the test_tool_output_streaming.py grandchild tests, and they pass on both trees when re-run on a quiet box. tests/studio/install passes, frontend is 2027 passing with typecheck and i18n:check:strict clean.

Nothing here changes the feature's behaviour. Happy to drop any of the four if you would rather keep them separate.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: a8b4f599f4

ℹ️ 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".

Comment on lines +28 to +30
!acceptedStartedAt ||
job.startedAt !== acceptedStartedAt ||
job.operation !== "switch"

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 Use a unique identifier for switch jobs

When two switch operations are started within the same wall-clock second, this ownership check can mistake the second job for the first because the backend populates started_at with _flow.utcnow(), whose format has only second precision. This is reachable with fast reuse-only switches across two tabs: a tab still polling the first switch can adopt the second switch and report its success or failure as the outcome of the first request. Return a unique job ID or a sufficiently precise timestamp and compare that instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The precision point is correct: update_flow.utcnow() is time.strftime("%Y-%m-%dT%H:%M:%SZ"), so started_at carries whole seconds and is doing duty as a job identity. But I do not think the window is reachable, for two reasons.

The reuse-only case named here is the one that never takes ownership. A switch whose bundle already matches is refused during planning: _plan_llama_phase returns already_selected through _finish_planning_refusal, which sets started: false, and the hook only records ownedJob.current = { startedAt } after if (!started.started) returns early. So a fast reuse-only switch produces no owned job to confuse.

A switch that does start is serialized and is not sub-second. _claim_operation takes _operation_lock non-blocking and stamps started_at before any work, so a second switch cannot start until the first has finished; for both stamps to land in one second the whole of the first job would have to complete inside it. A started switch always spawns the installer for the resolve, then again for the llama phase, then runs the whisper phase. Importing install_llama_prebuilt alone measures 0.11 to 0.16 s here before any download, validation or hardlinking, and the resolve runs with force_refresh=True so it does not read the memo.

Worth noting the blast radius too: the outcome would be a toast attributed to the wrong request, while the installed backend and the shared job state are both correct.

Agreed that a second-granularity timestamp is a fragile identity, and a unique job id would be the right shape if this grows a second writer. As it stands it would mean changing the job contract across the model, the parser, the lifecycle helper and their tests to close a race that needs a sub-second install, so I am leaving it and recording the reasoning here.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: a8b4f599f4

ℹ️ 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".

Comment on lines +976 to +977
if not llama_will_run:
return {}

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 retrying a failed whisper re-pair

When the llama phase succeeds but the slim whisper repair then fails with a retryable exit such as 1 or 3, the llama marker already records the requested backend while the whisper marker still records the old one. Retrying the same selection is classified as already_selected, making llama_will_run false, and this return suppresses the repair phase; the picker is also no longer dirty and the normal whisper update check does not detect the backend mismatch. The user therefore cannot retry the reported repair failure without switching llama.cpp away and back, so permit a repair-only retry when the llama refusal is specifically already_selected and the slim whisper pairing is stale.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Genuine, and fixed in dda83d8. Reproduced the chain at head: the llama phase runs first and writes the marker, so a whisper repair that raises a retryable exit leaves backend_request on the new backend with the slim install still hardlinked to the old runtime. The retry then lands in the already_selected branch, llama_spec is None, and _whisper_phase_plan returned {} on if not llama_will_run, so the repair could never run again.

Worth noting this is an interaction between two earlier fixes on this branch rather than an original defect: making exits other than 2 re-raise is what turned a swallowed repair failure into a reported one, and making a refused switch stay refused is what closed the retry path behind it.

The fix restores what the earlier item asked for more precisely: a repair-only job is allowed for the already_selected refusal specifically, and only while slim_pairing_is_stale() says the slim marker's backend differs from the installed llama backend, which is the same comparison run_repair_phase already makes before doing any work. Gating on staleness matters, otherwise every already-selected request would start a whisper job that finds nothing to do and reports success in place of a clear refusal.

Two regression tests: the retry now plans a repair phase, and a healthy pairing (plus every non-already_selected refusal) still returns no phase. Both fail with the fix reverted. Suites green: 101 passed across the switch, update and whisper freshness tests.

The llama phase runs first and records the new backend, so a retryable whisper failure
(a dropped download, an install that was busy) ends with llama.cpp on the requested
backend and dictation still hardlinked to the old runtime. Retrying that selection is
then already_selected, which skips the llama phase, and the whisper planner refused to
run without one. The reported failure was unfixable except by switching away and back.

Allow a repair-only job for that one refusal, gated on the pairing actually being stale
so an ordinary already-selected request stays a refusal instead of becoming a no-op job
that reports success. slim_pairing_is_stale exposes the comparison run_repair_phase
already makes before it does any work.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: dda83d884f

ℹ️ 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
danielhanchen merged commit 5426a78 into unslothai:main Aug 13, 2026
90 of 92 checks passed
danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Aug 13, 2026
unslothai#8520 consolidated the per-field sync_marker_* helpers into one
sync_marker_selection driven by _marker_selection_patch, which conflicted with
the sync_marker_arch_coverage this branch added.

Took main's consolidation and folded the built-arch coverage into
_marker_selection_patch instead of keeping a separate helper. It already
receives the AssetChoice, so the coverage now rides the single write every
reuse path already makes, and the tests move to that writer.
rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request Sep 7, 2026
…reads

Two fixes on top of this branch, both from review.

The progress label was answering with `import torch`. `_torch_step_label` runs before
the first pip step of its block, where `_TORCH_RUNTIME_PROBE` is cold, and on the very
host the label exists for (Windows, no NVIDIA, no rocminfo or amd-smi) none of the four
`_ensure_*` calls that follow reach the probe either: `_ensure_cuda_torch` returns on
no-NVIDIA, `_ensure_xpu_torch` on IS_WINDOWS, `_ensure_rocm_torch` at its "no AMD GPU
visible via hipinfo" guard, `_ensure_cpu_torch` unless an explicit CPU pin is set. So
the new operand was the first probe, spending up to its 90s timeout before `_progress()`
had printed anything, on exactly the wedged-driver hosts that timeout exists to rescue.
`pip_install` then invalidates the memo before the existing check at the torchao step,
so the cost was not amortised either.

`_installed_torch_is_windows_rocm_cheap` answers the same question from torch/version.py
via `find_spec`, which is the idiom `_installed_torch_version_label` and
`_installed_torch_label_on_disk` already use for this exact reason, and falls back to the
memoized probe only when something else has already paid for it. Behaviour on the
reported Strix Halo host is unchanged.

The marker reads were unguarded. `backend` has only been written since unslothai#8520
(2026-08-13); markers go back to unslothai#4562 (2026-03-25), so every install older than that has
no such property, and reading a missing property under a caller's `Set-StrictMode
-Version 2.0` or higher is a terminating error. The function's only try/catch wraps
`ConvertFrom-Json`, so it escaped and aborted setup. `tag`, `published_repo` and
`release_tag` had the same hazard, and an empty or truncated marker (an interrupted write
leaves one) made the function print "installed release: @" instead of staying quiet. All
four reads are now guarded through `PSObject.Properties`.

Both printers now share one contract for the value: string only, trimmed, and matching
`^[A-Za-z0-9._+-]{1,32}$`. Without it the twins disagree, since PowerShell renders
@(1, 2) as "1 2" and Python renders [1, 2] as "[1, 2]", and a newline in the value would
split the log line. The vocabulary is cuda, rocm, vulkan, cpu and metal, so nothing real
is rejected. The guard uses -ccontains because PowerShell property access is
case-insensitive and Python's dict lookup is not.

Tests. `test_torch_step_label.py` grows to 164 cases: the full
[Windows, Linux, WSL, macOS] x [NVIDIA, AMD with tooling, AMD bundled-runtime, Intel XPU,
CPU-only, no torch] matrix, explicit-backend precedence, the off-disk reader, and the
cost assertions. `test_installed_release_backend_line.py` is new: 498 cases driving the
real `Get-InstalledLlamaPrebuiltRelease` through pwsh and the real
`installed_llama_prebuilt_release` through bash, over a marker corpus (every backend,
null, non-string, unicode, 64KiB, quotes, backticks, subexpressions, newlines, control
characters, malformed and empty files) crossed with StrictMode off, 1.0, 2.0, 3.0 and
Latest, plus all twelve historical marker key sets from 2026-03-25 to today, and a
byte-for-byte parity assertion between the two printers on every case.

Both new assertions discriminate: the legacy-marker StrictMode case and the
zero-subprocess case pass on the merge base, fail on this branch before these fixes, and
pass after.

Recorded, not fixed here: setup.sh names a non-fork binary source ("+ ggml-org@b10715")
and setup.ps1 never has. Teaching setup.ps1 that branch changes what Windows prints for
upstream bundles, which is a separate change; the divergence is asserted in the new test
so it stays a known quantity.
danielhanchen added a commit that referenced this pull request Sep 8, 2026
…ling Windows ROCm torch as CPU (#10370)

* Studio: name the llama.cpp backend in the install log, and stop labelling Windows ROCm torch as CPU

The installer prints "installed release: <repo>@<tag>" and never says which
backend the installed bundle runs on, so a host running a Vulkan bundle and a
host running a ROCm one produce identical lines. A Strix Halo report came with
four install and update logs covering nine days that all read healthy while the
machine ran Vulkan; only the server logs, which record the backend, showed it.
The marker already carries the resolved backend, so both setup scripts now print
it.

Separately, the torch progress label falls back to GPU detection when
UNSLOTH_TORCH_BACKEND is unset, which is every standalone "unsloth studio
update". On Windows that detection probes rocminfo and amd-smi, which ship with
the HIP SDK rather than with AMD's bundled-runtime wheels, so the same run
printed "torch check (cpu)" a few lines above "dependency overrides (skipped,
Windows ROCm)". torch.version.hip is the installed build's own answer and is
already read for the torchao override, so the label uses it too.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: read the Windows ROCm verdict off disk, and guard the marker reads

Two fixes on top of this branch, both from review.

The progress label was answering with `import torch`. `_torch_step_label` runs before
the first pip step of its block, where `_TORCH_RUNTIME_PROBE` is cold, and on the very
host the label exists for (Windows, no NVIDIA, no rocminfo or amd-smi) none of the four
`_ensure_*` calls that follow reach the probe either: `_ensure_cuda_torch` returns on
no-NVIDIA, `_ensure_xpu_torch` on IS_WINDOWS, `_ensure_rocm_torch` at its "no AMD GPU
visible via hipinfo" guard, `_ensure_cpu_torch` unless an explicit CPU pin is set. So
the new operand was the first probe, spending up to its 90s timeout before `_progress()`
had printed anything, on exactly the wedged-driver hosts that timeout exists to rescue.
`pip_install` then invalidates the memo before the existing check at the torchao step,
so the cost was not amortised either.

`_installed_torch_is_windows_rocm_cheap` answers the same question from torch/version.py
via `find_spec`, which is the idiom `_installed_torch_version_label` and
`_installed_torch_label_on_disk` already use for this exact reason, and falls back to the
memoized probe only when something else has already paid for it. Behaviour on the
reported Strix Halo host is unchanged.

The marker reads were unguarded. `backend` has only been written since #8520
(2026-08-13); markers go back to #4562 (2026-03-25), so every install older than that has
no such property, and reading a missing property under a caller's `Set-StrictMode
-Version 2.0` or higher is a terminating error. The function's only try/catch wraps
`ConvertFrom-Json`, so it escaped and aborted setup. `tag`, `published_repo` and
`release_tag` had the same hazard, and an empty or truncated marker (an interrupted write
leaves one) made the function print "installed release: @" instead of staying quiet. All
four reads are now guarded through `PSObject.Properties`.

Both printers now share one contract for the value: string only, trimmed, and matching
`^[A-Za-z0-9._+-]{1,32}$`. Without it the twins disagree, since PowerShell renders
@(1, 2) as "1 2" and Python renders [1, 2] as "[1, 2]", and a newline in the value would
split the log line. The vocabulary is cuda, rocm, vulkan, cpu and metal, so nothing real
is rejected. The guard uses -ccontains because PowerShell property access is
case-insensitive and Python's dict lookup is not.

Tests. `test_torch_step_label.py` grows to 164 cases: the full
[Windows, Linux, WSL, macOS] x [NVIDIA, AMD with tooling, AMD bundled-runtime, Intel XPU,
CPU-only, no torch] matrix, explicit-backend precedence, the off-disk reader, and the
cost assertions. `test_installed_release_backend_line.py` is new: 498 cases driving the
real `Get-InstalledLlamaPrebuiltRelease` through pwsh and the real
`installed_llama_prebuilt_release` through bash, over a marker corpus (every backend,
null, non-string, unicode, 64KiB, quotes, backticks, subexpressions, newlines, control
characters, malformed and empty files) crossed with StrictMode off, 1.0, 2.0, 3.0 and
Latest, plus all twelve historical marker key sets from 2026-03-25 to today, and a
byte-for-byte parity assertion between the two printers on every case.

Both new assertions discriminate: the legacy-marker StrictMode case and the
zero-subprocess case pass on the merge base, fail on this branch before these fixes, and
pass after.

Recorded, not fixed here: setup.sh names a non-fork binary source ("+ ggml-org@b10715")
and setup.ps1 never has. Teaching setup.ps1 that branch changes what Windows prints for
upstream bundles, which is a separate change; the divergence is asserted in the new test
so it stays a known quantity.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: stop the hip-reader tests reading the runner's real torch

The four _torch_hip_version_on_disk cases built a stand-in torch package under
tmp_path and prepended it to sys.path, which is enough only when torch is absent.
importlib.util.find_spec returns sys.modules[name].__spec__ when the module is
already imported, so on any job that installs torch the real package answered, the
fixture was ignored, and the reader returned "" instead of the planted hip string.
They passed locally for the same reason they failed in CI.

_fake_torch_on_path now drops the sys.modules entry as well, so find_spec does a real
path search; monkeypatch restores the real torch at teardown. Reproduced the CI shape
locally by importing a stub torch before collection: 4 failed before this, 164 pass
after. Test-only, the reader itself is unchanged.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: cut the comments on the backend-label change down to the load-bearing ones

Opening comment-reduction pass over the lines this PR adds: 173 comment and docstring
lines to 73. Deleted first, shortened second.

Gone are the docstrings that only restated a test name, the per-row provenance comments
that repeated the dict key beside them, the corpus section banners, and the multi-line
rationales whose facts already sit one line above in code. Kept, at one line each: why
rocminfo and amd-smi are absent on the reported host, why find_spec needs the sys.modules
entry dropped, why the guard is -ccontains rather than -contains, why pip_install
invalidating the memo is what made the old probe unamortised, and the pre-existing
setup.sh upstream-source branch that setup.ps1 has never had.

Comments, docstrings and whitespace only. prepush_gate --comment-only passes on
install_python_stack.py, setup.ps1 and test_torch_step_label.py. It fails closed on
setup.sh and test_installed_release_backend_line.py because the edited comments live
inside an embedded-language string (a shell heredoc and a PowerShell harness literal),
which no Python or shell lexer can see into, so both were verified by hand instead: the
heredoc's Python AST and everything outside it are byte-identical, all 12 changed lines
in setup.sh start with #, and the single AST delta in the test file is one # line inside
the PowerShell string.

164 and 496 tests still pass, bash -n clean, setup.ps1 parses with zero errors.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: probe bash before using it, so the setup.sh printer test skips on Windows

The Windows staging run turned this up: 141 of the new printer cases failed with the
expected line compared against UTF-16 text reading "Windows Subsystem for Linux has no
installed distributions."

C:\Windows\System32\bash.exe is the WSL launcher, not a shell. WSL puts it on the system
PATH ahead of Git's bin, so shutil.which("bash") returns it even when no distro is
installed, and running it prints that notice to stdout instead of executing the script.
The skipif therefore believed bash was available and the harness read the notice as
printer output. Microsoft documents the launcher as deprecated in favour of wsl.exe, and
the same first-PATH-hit mistake is on record against pnpm and several editors.

_usable_bash now runs `bash -c "printf ok"` and accepts the executable only if it prints
ok, which is the fix those reports converge on: probe the candidate rather than trusting
the first PATH match. A stub that ignores -c is rejected, so the file skips instead of
asserting against garbage. Nothing is lost by skipping there: setup.sh is never executed
on Windows, since _find_setup_script picks setup.ps1.

Verified against a stub that mimics the launcher (prints the notice, ignores -c): the
guard resolves to None. 660 tests pass here, ruff clean.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

3 participants