Repository navigation
Studio: name the llama.cpp backend in the install log, and stop labelling Windows ROCm torch as CPU - #10370
Conversation
…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.
Codex Review SummaryThis 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. |
|
@codex review |
There was a problem hiding this comment.
💡 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".
| # 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(): |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| # 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) { |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.tagis equally optional.- An empty or truncated marker (an interrupted write leaves one) deserializes to
$null, so$payload.published_repoin the precondition threw under StrictMode, and with strict mode off the function fell through and printedinstalled 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.
Both review findings fixed, and the whole line verified against real markersPushed as fe4b0a5. Summary of what changed and how far it was tested. The two fixesThe label no longer imports torch. On the affected host (Windows, standalone The marker reads are guarded. Blast radius, checked before changing anythingNothing parses either string. The only matches on No hardware path is added or removed. NVIDIA still wins, the rocminfo/amd-smi/KFD probe is untouched, and the Windows helper returns VerificationEverything ran in an isolated
Both new assertions discriminate, run unchanged against three trees:
Adjacent suites, all green on this branch: What this run cannot establish, and one thing left aloneLinux 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 Two pre-existing issues found while testing and deliberately not fixed here. |
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.
|
@codex review |
|
@codex security 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". |
…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.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
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:
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: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:
Two detectors disagreeing three lines apart, on a host that really is Windows ROCm.
_torch_step_labelfalls back to GPU detection whenUNSLOTH_TORCH_BACKENDis unset, which is every standaloneunsloth studio update, and on Windows that detection probesrocminfoandamd-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()readstorch.version.hipand 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.setup.shPython snippet run against the same three, producing the same three lines.setup.ps1parses clean through the PowerShell AST parser;setup.shthroughbash -n.test_torchao_select.pyandtest_pytorch_mirror.pystill 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, andwrite_prebuilt_metadatanever writes that key, so the guard can never fire. The marker does carry the equivalentbackend. 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.