Skip to content

Unsloth Studio installer: warn when PyTorch can't see the GPU the installer found (AMD, NVIDIA, Intel) - #8620

Closed
danielhanchen wants to merge 45 commits into
mainfrom
gpu-verdict-reconcile-8473
Closed

danielhanchen wants to merge 45 commits into
mainfrom
gpu-verdict-reconcile-8473

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Fixes #8473.

What the user sees

On an AMD host, unsloth studio update prints

gpu             AMD ROCm (gfx1201)
python          dependencies up to date

and Studio then runs CPU-only: the Live monitor shows VRAM --, "No visible GPU", and a CPU detail line. The user is told twice that their GPU is fine and given no diagnostic at all. Reported this way in #7485, and the same shape is problem 5 of #7307 (install path says gfx1201, update path says "AMD Ryzen 9 9950X").

Why it happens

The installer's GPU line and the backend's GPU verdict are computed by two stacks that share no state and never reconcile.

The installer probes rocminfo / amd-smi / hipinfo and a marketing-name table (studio/setup.sh:1794-1880, install.sh:4346-4438, studio/setup.ps1:2287-2653).

The backend's device list comes from get_backend_visible_gpu_info() (studio/backend/utils/hardware/hardware.py:3350). On an AMD host that function skips the SMI branch outright (:3356 is device == DeviceType.CUDA and not IS_ROCM), so the only branch that can populate devices is torch.cuda (:3371-3399). "No visible GPU" therefore means exactly one thing: torch.cuda.is_available() returned False in the backend process, so _detect_hardware_locked fell through to DEVICE = CPU (:624).

Nothing in the current-layout install or update path ever ran torch.cuda.is_available() to check that the GPU the installer just announced is the GPU torch can actually see. The only such probe was the legacy-layout migration one at install.sh:2504-2519, which passes on device = 'cpu' by construction. On Windows there is a probe at setup.ps1:4429-4447, but it runs BEFORE the dependency pass and its job is to clear the fast path, so a pass that ran and still left torch blind reported nothing.

What this changes

One bounded probe, in the venv, on both installers, immediately after the GPU summary and the dependency step, plus the report when the two verdicts disagree:

  • studio/setup.sh: a new block after the GPU detection summary. Runs only when an accelerator was announced (_setup_nvidia_usable or _setup_amd_detected), asks the venv interpreter for torch.cuda.is_available(), torch.cuda.device_count(), torch.__version__ and torch.version.hip, and on a mismatch prints, in the error colour:
gpu check       PyTorch cannot see the AMD GPU reported above
                detected by the installer: AMD ROCm (gfx1201) -- Radeon RX 9070 XT
                torch.cuda.is_available() is False in /home/me/.unsloth/studio/unsloth_studio
                torch 2.9.0+cpu, device_count 0, torch.version.hip none
                Studio will run CPU-only: the Live monitor will show VRAM "--" and "No visible GPU".
                Please report the two lines above at https://github.com/unslothai/unsloth/issues
  • studio/setup.ps1: Get-TorchGpuVisibility, built on the existing Invoke-BoundedPythonProbe, and the same report. It sits deliberately OUTSIDE the $SkipPythonDeps gate, because the reported run is the one that prints "dependencies up to date", so a check nested in the dependency-pass branch would stay silent on exactly the run being complained about.

Naming the symptom in the installer output is the point: the whole class of report this comes from is "the installer says my GPU is fine and Studio disagrees", and it is currently unfalsifiable from the user's side.

Bounding, because import torch on a box with a stalled GPU driver is the classic hang. setup.sh follows the existing XPU probe idiom exactly: an outer timeout 90 where timeout(1) exists, and a signal.alarm(90) inside the probe for hosts without it (base macOS, minimal images). setup.ps1 uses the existing Invoke-BoundedPythonProbe with an explicit 90s bound.

Loud, never fatal. A timeout or a crash means the probe failed, not that the GPU is missing, and collapsing those two facts would print an accusation the run cannot support against a host whose GPU may be perfectly fine. Even a confirmed mismatch does not abort: a CPU-only Studio still chats and still runs GGUF, and aborting here would turn a diagnosable install into a failed one. Costs nothing where it cannot help: a CPU-only host, a no-torch (GGUF-only) venv, and a missing interpreter are all skipped without launching anything, and UNSLOTH_SKIP_TORCH_GPU_CHECK=1 turns the probe off entirely.

This is diagnosis only. No GPU routing, wheel-index selection or placement behaviour changes anywhere in the diff.

What I deliberately did not do

The issue asks for a second half: persist the installer's detected gfx into unsloth_install_manifest.json and have the Live monitor say "PyTorch cannot see the AMD GPU (gfx1201)" instead of "No visible GPU". I left that out, and here is the reasoning rather than a shrug.

The manifest half is genuinely cheap and safe. write_manifest() (studio/install_manifest.py:124-159) already has the precedent in no_torch: an additive key written only when known, absent meaning "unknown" and never False. There is no hash fingerprint over the manifest at all, and verify_install() (:326-375) is a four-key allowlist (schema, package, package_version, requirement_files) using .get(). I checked rather than asserted: writing a manifest, adding rocm_gfx = "gfx1201" and re-running verify_install() gives byte-identical manifest_ok and reason. Every reader tolerates an added key (read_manifest, recorded_no_torch, verify_install, unsloth_cli/_studio_deps.py:169, setup.ps1:3823 Get-PersistedNoTorch, which reads one property off ConvertFrom-Json, and setup.ps1:4962, which moves the file without re-serialising it). The Rust preflight (studio/src-tauri/src/preflight/managed.rs:165) hashes the manifest bytes as a capability-cache marker, so a new key costs one re-probe, once, by design.

The consumer half is the problem, in two ways:

  1. Nothing under studio/backend/ imports install_manifest.py today, there is no gfx field anywhere in the backend, and /api/system (main.py:1914-2005) carries none either, so the message needs a new backend reader, a new field on the /api/system contract, the SystemGpuInfo type in use-system.ts, resources-tab.tsx, and a new key with a {gfx} placeholder in en.ts plus all 11 overlays with real translations.
  2. More importantly, the manifest is only rewritten by a full dependency pass. The run in [Bug] Latest llama.cpp build broke AMD GPU detection #7485 is an update that fast-paths past it, so on the exact host that motivated the issue the manifest would carry no gfx and the Live monitor would keep saying "No visible GPU" until something forced a dependency pass. The half that is silent on the reported host is not the half to ship first.

Part 1 stands alone: it turns an unfalsifiable report into a self-diagnosing one at install time, at the moment the contradiction is created. Happy to do part 2 as a follow-up if you want the message in the UI too.

How it was verified

New tests, no AMD hardware needed (every runner in this repo is a hosted ubuntu/windows/macos box, so all AMD coverage here is mock-based, as in studio/backend/tests/test_rocm_windows_vram_7072.py):

  • tests/studio/install/test_torch_gpu_visibility_8473.py, 15 tests. The real block is extracted from setup.sh and run under bash with stubbed printers, against a fake venv interpreter whose answer, exit code and latency the test controls, and a fake timeout that records the bound setup.sh asked for while enforcing a short one. So the hang case is a real hang, bounded and observed in seconds, and the 90s figure is asserted from what the script actually passed.
  • tests/studio/test_torch_gpu_visibility_8473.ps1, 45 checks. Get-TorchGpuVisibility is driven through a stubbed Invoke-BoundedPythonProbe (a real interpreter will not produce a banner-spoofed line or a timeout on demand), plus wiring checks on the real source with CRLF normalised once and a "was found" guard on every extracted region.

Every assertion was mutation-tested: 35 mutations, each reverting one behaviour the tests claim, each confirmed to fail at least one test, zero survivors. Two first-round survivors were real test weaknesses and were fixed rather than explained away: the spoofed-banner case passed with the line anchor removed because the sentinel prefix strip is a second, independent guard (both are now asserted per guard), and the Answered flag needed the mutation moved outside the parse branch to be observable.

Existing suites, run serially: tests/studio/install 1881 passed / 2 skipped, tests/python/test_cross_platform_parity.py 76 passed, tests/test_installer_interactive_prompts.py 92 passed, and the PowerShell setup suites test_setup_xpu_runtime_prereport, test_amd_venv_repair_loop, test_pre_turing_cap, test_intel_registry_fallback, test_torch_flavor, test_setup_pin_stale, test_torch_index_pin_hardening all green. bash -n studio/setup.sh and a PowerShell AST parse of studio/setup.ps1 both clean.

…ust announced

On an AMD host the installer prints `gpu AMD ROCm (gfx1201)` and `python
dependencies up to date`, and Studio then runs CPU-only with VRAM `--` and
"No visible GPU". The installer's GPU line comes from rocminfo / amd-smi /
hipinfo plus a marketing-name table; the backend's verdict is
torch.cuda.is_available() in its own process. The two never reconciled, so the
user was told twice their GPU was fine and given no diagnostic.

setup.sh and setup.ps1 now run one bounded probe in the venv and print the
mismatch when an announced accelerator is invisible to torch. Diagnosis only:
no routing, wheel index or placement behaviour changes.
chatgpt-codex-connector[bot]

This comment was marked as outdated.

On a hybrid Intel/NVIDIA machine using the XPU wheel, torch.cuda.is_available()
is False while the box runs on its GPU: _detect_hardware_locked falls through
from CUDA to XPU. The new check read that as a CPU verdict and printed a red
mismatch about a machine that is working, which is worse than staying quiet.

setup.sh gates on the _setup_xpu_ready it already computes; setup.ps1 uses
Test-VenvTorchIsXpu, which reads torch/version.py off disk, so the suppression
cannot hang on a stalled Arc driver.
chatgpt-codex-connector[bot]

This comment was marked as outdated.

Test-VenvTorchIsXpu only answers whether the installed wheel is a +xpu build.
A hybrid host whose Intel runtime has regressed keeps that wheel while both
torch.cuda.is_available() and torch.xpu.is_available() are False, falls through
to CPU exactly like the hosts this check exists for, and was being silenced.

torch.xpu.is_available() now rides along in the same bounded probe as the CUDA
question, so the suppression turns on the runtime actually being usable. No
extra interpreter launch, and the existing timeout still covers it.
chatgpt-codex-connector[bot]

This comment was marked as outdated.

…ry announced

Colab has no Unsloth venv: setup.sh installs the backend deps into the system
python and sets _COLAB_NO_VENV, so requiring $VENV_DIR/bin/python skipped the
check on the runtime that always announces an NVIDIA GPU. Probe the interpreter
that path installed into, and name it in the report.

setup.ps1 quieted every failed probe that mentioned a missing module, so a torch
that is installed and cannot import over a missing transitive dep was swallowed
along with an absent one, on exactly the host the check exists for. Match torch
itself.

setup.ps1 re-derived the announced GPU from the detection flags, which disagrees
with the summary on a host with an Intel Arc next to an AMD card whose arch gets
no ROCm wheels: the scan lets Intel win there while $script:ROCmGfxArch stays
set. Record what the summary announced and quote that.

Also fix the xpu posix summary test, whose torch.xpu.is_available() line count
started counting the new bounded probe.
chatgpt-codex-connector[bot]

This comment was marked as outdated.

Three ways the diagnostic could accuse a working host.

An explicit CPU pin is a request: install_python_stack's
_explicit_cpu_torch_index_url treats UNSLOTH_TORCH_INDEX_FAMILY=cpu or a /cpu
index leaf as authoritative and force-reinstalls the CPU wheel, so torch
answering False is the pin working. Exclude the exact cpu leaf in both scripts,
resolved fresh rather than off the pin variables the dependency-pass branch owns
(they are null on the fast path this check exists for). install.sh already
carries the same exclusion for its ROCm line.

An AMD arch outside $_rocmWheelArches gets CPU torch by design and the install
path already warns about it, so all three AMD summary arms now announce for
reconciliation only when the arch will actually route to a repo.amd.com index.

llama.cpp is a separate stack: with the Vulkan bundle the backend fills
inference_gpu from get_vulkan_inference_gpu_info() and the monitor shows that
card's real VRAM, so promising a CPU-only Studio and a VRAM "--" readout can be
false. Claim only what the probe answered and make the symptom a conditional.
chatgpt-codex-connector[bot]

This comment was marked as outdated.

…e backend does

install.sh exports UNSLOTH_TORCH_BACKEND from the index it RESOLVED, so a host it
deliberately routes to CPU (non-x86_64, ROCm older than 6.0, an unreadable ROCm
runtime) arrives with the CPU wheel it asked for while setup.sh's AMD detection,
which has no uname or ROCm-version gate, still reports the GPU. Skip the
reconciliation on the exact cpu backend; unset stays reconciled, since that is the
normal standalone studio update.

The pinned ROCm path routes a gfx*/rocm* leaf through the GPU index whatever the
arch and skips the unsupported-arch CPU fallback, so suppressing on
$AmdHasGpuWheels alone silenced a host that really does get a GPU wheel. All four
AMD summary arms now announce when the arch is mapped OR a non-cpu pin is set.

Training does not run on CPU when torch cannot see the device: hardware.py leaves
CHAT_ONLY true and disables Train/Export. Say what the XPU arm already says.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

A hide-all AMD visibility mask is a request: the KFD sysfs fallback reads the
kernel topology and ignores HIP_VISIBLE_DEVICES, so the summary announces the
card and torch correctly sees nothing. _setup_cvd_hides_nvidia already keeps a
masked NVIDIA host out of _setup_nvidia_usable; this adds the missing AMD half,
first-set-wins like the runtime, and only for a hide-all value.

A GGUF-only install has no torch to reconcile. setup.ps1 excludes it through
$NoTorchMode; setup.sh now reads the same two durable records install_manifest
writes, plus UNSLOTH_NO_TORCH, instead of launching an interpreter that can only
fail.

A false torch.cuda.is_available() says nothing about llama.cpp, which still
offloads GGUF to the same card, so the unavailability line now names PyTorch.
chatgpt-codex-connector[bot]

This comment was marked as outdated.

nvidia-smi ignores CUDA_VISIBLE_DEVICES and an AMD arch can be inferred from a WMI
GPU name, so a Windows host launched with a hide-all mask still announces the card
while torch is meant to see nothing. Test-VisibleMaskHidesAll mirrors the POSIX
half, first-set-wins and hide-all only, and the gate applies the mask that governs
what was announced so an idle HIP mask cannot mute a genuine NVIDIA mismatch. The
parameter is untyped because a [string[]] cast turns an unset env read into the
empty string, which is itself the hide-all value.

device_count() is CUDA-only, so the verbose success line read 'torch sees 0
GPU(s)' on exactly the hybrid host the XPU answer had just cleared. Name what the
number counts and print the xpu answer beside it.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@LeoBorcherding LeoBorcherding changed the title fix(AMD): installer, report when PyTorch cannot see the GPU the installer just announced Unsloth Studio installer: warn when PyTorch can't see the GPU the installer found (AMD, NVIDIA, Intel) Sep 25, 2026
@danielhanchen danielhanchen self-assigned this Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Sep 28, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
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.

Studio: installer reports an AMD GPU while the backend runs CPU-only, with no reconciliation between them

4 participants