Skip to content

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

Merged
danielhanchen merged 9 commits into
mainfrom
studio/name-the-llama-backend-in-logs
Sep 8, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio/name-the-llama-backend-in-logs

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

What this fixes

A Strix Halo report arrived with four Unsloth Studio install and update logs spanning nine days. The machine was running the Vulkan llama.cpp bundle throughout, deliberately and correctly, and none of the four logs can say so, because the installer never names the backend:

installed release: unslothai/llama.cpp@b10715-mix-86bd2d3 (tag b10715)

That line is identical whether the installed bundle is ROCm, Vulkan, CUDA or CPU. Establishing which one was in use needed the server logs, which record "backend": "vulkan" on each update.

On this hardware the answer matters: AMD put the ROCm/Vulkan gap on Strix Halo at about 20%, so which bundle you are on is a first-order performance fact, not a detail. The prebuilt marker already carries the resolved backend (backend_for_install_kind), so both setup scripts now print it:

installed release: unslothai/llama.cpp@b10715-mix-86bd2d3 (tag b10715) -- vulkan backend

A marker without the field prints exactly what it prints today, so older installs are unaffected.

And a second misleading line in the same logs

Every update run printed:

 3/13  torch check (cpu)
...
 6/13  dependency overrides (skipped, Windows ROCm)

Two detectors disagreeing three lines apart, on a host that really is Windows ROCm. _torch_step_label falls back to GPU detection when UNSLOTH_TORCH_BACKEND is unset, which is every standalone unsloth studio update, and on Windows that detection probes rocminfo and amd-smi. Those ship with the HIP SDK, not with AMD's bundled-runtime wheels, so a working ROCm host reads as CPU. _installed_torch_is_windows_rocm() reads torch.version.hip and is already consulted a few steps later for the torchao override, so the label now uses it too.

This is a label only. _ensure_cpu_torch() returns immediately unless an explicit CPU index URL is set, so no CPU torch was ever pushed over the ROCm build. It is the single most misleading string in these logs for anyone asking "is my GPU being used".

Verification

  • studio/backend/tests/test_torch_step_label.py, five cases. The regression case fails on the pre-change code with the other four passing, so the test discriminates rather than ritually passing.
  • Both setup twins exercised on real markers rather than eyeballed. The PowerShell function dot-sourced against three markers (vulkan, rocm, no backend field) and the setup.sh Python snippet run against the same three, producing the same three lines.
  • setup.ps1 parses clean through the PowerShell AST parser; setup.sh through bash -n.
  • test_torchao_select.py and test_pytorch_mirror.py still pass, 39 tests with the new file.

Not changed here

While reading this path I found that setup.ps1's mismatched-install guard reads $existingMeta.install_kind, and write_prebuilt_metadata never writes that key, so the guard can never fire. The marker does carry the equivalent backend. Making it live changes deletion behaviour and there is no PowerShell test coverage to hold it, so it is left alone and reported rather than patched.

…ling 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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T05:13:36.734307Z d8369e2 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: 47b7376e43

ℹ️ 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_python_stack.py Outdated
# and not with AMD's bundled-runtime wheels, so a Windows ROCm host without
# the SDK reads as CPU here while the very next step correctly detects it.
# torch.version.hip is the installed build's own answer.
elif _has_rocm_gpu() or _installed_torch_is_windows_rocm():

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 Avoid a second torch runtime probe for the progress label

When a standalone Windows update has neither a usable NVIDIA probe nor ROCm SDK tooling, this new operand calls _installed_torch_is_windows_rocm(), which can spend up to 90 seconds importing torch before _progress() emits anything. The subsequent extras installs invalidate _TORCH_RUNTIME_PROBE, so the existing Windows ROCm check at studio/install_python_stack.py:7241 repeats the same import; on the wedged-driver hosts that the probe timeout explicitly handles, this change therefore adds another unexplained 90-second stall solely to construct a label.

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.

Correct, and fixed in fe4b0a5.

I traced the four _ensure_* calls that follow _progress(_torch_step_label("check")) on the affected host (Windows, standalone update, UNSLOTH_TORCH_BACKEND unset, no rocminfo or amd-smi) and none of them reaches _probe_torch_runtime either: _ensure_cuda_torch returns on no-NVIDIA, _ensure_xpu_torch at its IS_WINDOWS guard, _ensure_rocm_torch at "no AMD GPU visible via hipinfo", and _ensure_cpu_torch unless an explicit CPU pin is set. So this was not merely an earlier probe, it was the only probe at that point, and pip_install invalidates the memo before the torchao-step check you named, so the cost was not amortised.

The fix reads torch.version.hip and torch.__version__ out of torch/version.py through find_spec, which is the idiom _installed_torch_version_label and _installed_torch_label_on_disk already use for exactly this reason (their docstrings name the wedged-driver case). The memoized probe is still preferred when something else has already paid for it. The label on the reported Strix Halo host is unchanged.

Held by a test that asserts zero _probe_torch_runtime entries and a still-cold _TORCH_RUNTIME_PROBE across the whole [Windows, Linux, WSL, macOS] x [NVIDIA, AMD with tooling, AMD bundled-runtime, Intel XPU, CPU-only, no torch] matrix. It passes on the merge base, fails on 47b7376, and passes now.

Comment thread studio/setup.ps1 Outdated
# Name the backend. Without it a host running a Vulkan bundle and a host running
# a ROCm one print the same line, so a bundle that has drifted away from the
# hardware is invisible in the install log.
if ($payload.backend) {

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 Check that legacy markers contain the backend property

When setup.ps1 is invoked from a PowerShell scope with Set-StrictMode enabled, reading a nonexistent PSCustomObject property is an error. Older valid UNSLOTH_PREBUILT_INFO.json markers have no backend field, so this newly added access aborts the setup instead of preserving the previous release line as intended; inspect $payload.PSObject.Properties before reading the optional property.

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.

Correct, and fixed in fe4b0a5. Reproduced against pwsh 7.6.0:

Set-StrictMode -Version Latest
'{"published_repo":"r","release_tag":"t","tag":"b"}' | ConvertFrom-Json | % { $_.backend }
-> PropertyNotFoundException: The property 'backend' cannot be found on this object.

Worse than it first looks on the timeline: backend has only been written since #8520 (5426a78, 2026-08-13), and markers go back to #4562 (f4d8a24, 2026-03-25), so the no-backend shape covers roughly four and a half months of releases that are on disk today. My claim in the description that such a marker "prints exactly what it prints today" was wrong.

Guarded through PSObject.Properties as you suggested. Two neighbours had the same hazard and are guarded with it, since leaving them beside a fixed one would be odd:

  • $payload.tag is equally optional.
  • An empty or truncated marker (an interrupted write leaves one) deserializes to $null, so $payload.published_repo in the precondition threw under StrictMode, and with strict mode off the function fell through and printed installed release: @.

The guard is -ccontains rather than -contains: PowerShell property access is case-insensitive and the payload.get("backend") in the setup.sh twin is not, so a case-folded guard would print a suffix for a "BACKEND" key that setup.sh ignores.

Both printers now share one value contract (string only, trimmed, ^[A-Za-z0-9._+-]{1,32}$), because without it they disagree on non-string values: PowerShell renders @(1, 2) as 1 2 and Python renders [1, 2] as [1, 2].

Held by a new suite that runs both real functions against a marker corpus crossed with StrictMode off, 1.0, 2.0, 3.0 and Latest, including all twelve historical marker key sets. The legacy-marker case passes on the merge base, fails on 47b7376, and passes now.

…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

Both review findings fixed, and the whole line verified against real markers

Pushed as fe4b0a5. Summary of what changed and how far it was tested.

The two fixes

The label no longer imports torch. On the affected host (Windows, standalone unsloth studio update, UNSLOTH_TORCH_BACKEND unset, no rocminfo or amd-smi) none of the four _ensure_* calls after _progress(_torch_step_label("check")) reaches _probe_torch_runtime, so the new operand was the first probe and it ran before _progress() emitted anything, spending up to its 90 second timeout on exactly the wedged-driver hosts that timeout exists to rescue. _installed_torch_is_windows_rocm_cheap now reads torch.version.hip out of torch/version.py through find_spec, the idiom _installed_torch_version_label and _installed_torch_label_on_disk already use, and prefers the memoized probe only when something else has paid for it.

The marker reads are guarded. backend has only existed since #8520 (2026-08-13) while markers go back to #4562 (2026-03-25), so a missing property under a caller's Set-StrictMode -Version 2.0 or higher aborted setup on roughly four and a half months' worth of installs. tag, published_repo and release_tag had the same hazard, and an empty or truncated marker printed installed release: @. All four go through PSObject.Properties now, and both printers share one value contract so they cannot drift.

Blast radius, checked before changing anything

Nothing parses either string. The only matches on installed release: anywhere in the repo are substring assertions against the source text of the setup scripts (tests/studio/install/test_pr4562_bugfixes.py:678,812). studio/src-tauri/src/install.rs:168 reads only [TAURI:STEP] lines, and .github/scripts/interrupt-install.{sh,ps1} match the progress bar shape, not the label. No frontend, backend route, CI grep or golden log reads either. _progress writes to stdout and increments a counter, nothing else, so no install decision moves. Every other reader of the marker's backend key already goes through marker_backend(), which has its own absence fallback.

No hardware path is added or removed. NVIDIA still wins, the rocminfo/amd-smi/KFD probe is untouched, and the Windows helper returns False on not IS_WINDOWS before doing any work, so Linux, WSL and macOS keep their existing answers. There are no frontend or webview changes, so no browser matrix applies here.

Verification

Everything ran in an isolated uv venv (Python 3.12) on Linux, against pwsh 7.6.0, bash 5.2.21 and shellcheck 0.11.0.

studio/backend/tests/test_torch_step_label.py, 164 cases: the full [Windows, Linux, WSL, macOS] x [NVIDIA, AMD with tooling, AMD bundled-runtime, Intel XPU, CPU-only, no torch] product, all three label suffixes, explicit-backend precedence on every platform, the off-disk reader's own edge cases, the zero-subprocess assertions, and one unsimulated check on the real host this ran on.

tests/studio/install/test_installed_release_backend_line.py, 498 cases, new: drives the real Get-InstalledLlamaPrebuiltRelease through pwsh and the real installed_llama_prebuilt_release through bash, both sliced out of their scripts the way tests/studio_setup_ps1/Get-FunctionSource.ps1 and tests/sh/ already do. The corpus covers every backend name, unknown future names, null, empty, whitespace, ints, floats, booleans, lists, objects, unicode, CJK, emoji, 1 KiB and 64 KiB strings, quotes, backticks, $(...), semicolons, backslashes, newlines, CRLF, tabs, ANSI and NUL, upper and mixed case keys, malformed JSON, truncated JSON, empty file, whitespace-only file and absent file. Each is crossed with StrictMode off, 1.0, 2.0, 3.0 and Latest, and each asserts the two printers produce identical bytes. All twelve historical marker key sets from f4d8a24 (2026-03-25) through 1400031 (2026-08-31) are replayed the same way, plus the backend: null shape that backend_for_install_kind can produce.

Both new assertions discriminate, run unchanged against three trees:

assertion merge base 47b7376 fe4b0a5
Windows ROCm host labelled rocm fail pass pass
backend suffix printed fail pass pass
legacy marker survives StrictMode 2.0+ pass fail pass
label starts no torch subprocess pass fail pass

Adjacent suites, all green on this branch: test_torchao_select.py and test_pytorch_mirror.py (34), the tests/studio_setup_ps1 Pester suite against the edited setup.ps1 (64 passed, 0 failed), every tests/sh/test_*.sh, tests/studio/test_ci_shell_suite_coverage.py (29), and the setup.ps1 source-shape tests under tests/python and tests/ (414). bash -n clean, Parser::ParseFile reports zero errors, and shellcheck reports the same 25 findings as the merge base, none new.

What this run cannot establish, and one thing left alone

Linux cannot prove Windows driver behaviour, native macOS Metal, or Windows PowerShell 5.1. The strict mode rule is documented identically from 2.0 up, but 5.1 raises it with FullyQualifiedErrorId: PropertyNotFoundStrict rather than the 7.x exception shape, so the Windows CI job remains the authority there. GPU combinations are simulated by patching the detectors; only NVIDIA silicon was physically present.

Two pre-existing issues found while testing and deliberately 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, so it is asserted in the new test as a known divergence instead. And the mismatched-install guard at setup.ps1:5773 still reads $existingMeta.install_kind, which no writer has ever emitted across any of the twelve marker shapes, so it has never fired; its own comment already says "inert for now", and making it live changes deletion behaviour with no coverage holding it.

pre-commit-ci Bot and others added 3 commits September 7, 2026 12:59
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.
…-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.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ad3bb604cd

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

…s 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.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d8369e2c5c

ℹ️ 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 9b30276 into main Sep 8, 2026
76 checks passed
@danielhanchen
danielhanchen deleted the studio/name-the-llama-backend-in-logs branch September 8, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant