Repository navigation
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
Closed
danielhanchen wants to merge 45 commits into
danielhanchen wants to merge 45 commits into
Conversation
…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.
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.
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.
…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.
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.
…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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8473.
What the user sees
On an AMD host,
unsloth studio updateprintsand Studio then runs CPU-only: the Live monitor shows VRAM
--, "No visible GPU", and aCPUdetail 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 saysgfx1201, 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/hipinfoand 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 (:3356isdevice == DeviceType.CUDA and not IS_ROCM), so the only branch that can populate devices istorch.cuda(:3371-3399). "No visible GPU" therefore means exactly one thing:torch.cuda.is_available()returned False in the backend process, so_detect_hardware_lockedfell through toDEVICE = 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 atinstall.sh:2504-2519, which passes ondevice = 'cpu'by construction. On Windows there is a probe atsetup.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_usableor_setup_amd_detected), asks the venv interpreter fortorch.cuda.is_available(),torch.cuda.device_count(),torch.__version__andtorch.version.hip, and on a mismatch prints, in the error colour:studio/setup.ps1:Get-TorchGpuVisibility, built on the existingInvoke-BoundedPythonProbe, and the same report. It sits deliberately OUTSIDE the$SkipPythonDepsgate, 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 torchon a box with a stalled GPU driver is the classic hang.setup.shfollows the existing XPU probe idiom exactly: an outertimeout 90wheretimeout(1)exists, and asignal.alarm(90)inside the probe for hosts without it (base macOS, minimal images).setup.ps1uses the existingInvoke-BoundedPythonProbewith 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=1turns 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.jsonand 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 inno_torch: an additive key written only when known, absent meaning "unknown" and never False. There is no hash fingerprint over the manifest at all, andverify_install()(:326-375) is a four-key allowlist (schema,package,package_version,requirement_files) using.get(). I checked rather than asserted: writing a manifest, addingrocm_gfx = "gfx1201"and re-runningverify_install()gives byte-identicalmanifest_okandreason. Every reader tolerates an added key (read_manifest,recorded_no_torch,verify_install,unsloth_cli/_studio_deps.py:169,setup.ps1:3823Get-PersistedNoTorch, which reads one property offConvertFrom-Json, andsetup.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:
studio/backend/importsinstall_manifest.pytoday, 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/systemcontract, theSystemGpuInfotype inuse-system.ts,resources-tab.tsx, and a new key with a{gfx}placeholder inen.tsplus all 11 overlays with real translations.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 fromsetup.shand run underbashwith stubbed printers, against a fake venv interpreter whose answer, exit code and latency the test controls, and a faketimeoutthat records the boundsetup.shasked 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-TorchGpuVisibilityis driven through a stubbedInvoke-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
Answeredflag needed the mutation moved outside the parse branch to be observable.Existing suites, run serially:
tests/studio/install1881 passed / 2 skipped,tests/python/test_cross_platform_parity.py76 passed,tests/test_installer_interactive_prompts.py92 passed, and the PowerShell setup suitestest_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_hardeningall green.bash -n studio/setup.shand a PowerShell AST parse ofstudio/setup.ps1both clean.