Repository navigation
Studio: report the GPUs the OS sees, not just the ones PyTorch opened - #9858
Conversation
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93712a48d8
ℹ️ 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".
| if _RECORDED_TORCH_TAG: | ||
| return _RECORDED_TORCH_TAG |
There was a problem hiding this comment.
Let an unknown explicit index override the stale manifest
When an existing installation recorded cu128 and the user later pins a custom index whose leaf is not a recognized flavor (for example an authenticated corporate /simple mirror), setup.ps1 deliberately publishes no expected tag, but this branch immediately revives the old manifest value. A custom or untagged wheel installed from the explicit mirror is then treated as a cu128 mismatch, and _expected_torch_index_url rejects the /simple URL and falls back to the public PyTorch cu128 index, overriding the user's explicit package source. An explicit unknown-family pin should suppress the recorded-family invariant rather than inheriting stale metadata.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This one is already handled, and the review was reading a stale snapshot of the file.
This branch is stacked on #9857, and it was based on that PR's first commit rather than its head. The unknown-family pin case was fixed there in an earlier round: _ensure_expected_torch_flavor consults _explicit_unknown_family_torch_index_url and returns without acting whenever an explicit pin's leaf names no family it can compare against, so the recorded flavor is never revived behind a /simple mirror and _expected_torch_index_url is never reached. tests/studio/install/test_cuda_repair.py covers it.
Since then the resolution order changed again in 0523acc so that a readable pin outranks the manifest outright. I have rebased this branch onto the current #9857 head, so the diff here now carries both.
93712a4 to
f6ce951
Compare
|
I found two remaining compatibility paths at
Focused simulations reproduced the Linux AMD CPU-build verdict without an expected flavor tag and confirmed that the ARM64 repair package list still includes |
604ff1a to
8ace3d4
Compare
|
The earlier edge cases pass my focused repros on head Real-hardware check also passed with an RTX 5070 Ti under WSL: with |
|
Same note as on #9857 about the one red check, since it is not from this PR either.
Not folding an unrelated fix into this branch. It wants either a CI step that runs the suite or a Everything else on this PR is green so far, with the rest still running. |
c14b99f to
5b64212
Compare
_ensure_cpu_torch's own GPU-build predicate now reads torch.version.xpu. An untagged source, conda or private-index XPU wheel carries its runtime only there, so the predicate declined to reinstall while _installed_flavor_tag_now, which does read the marker, went on to report "still xpu" -- the detection had improved and the repair had not followed it, and the update failed instead of honouring the CPU pin. The parity test claims equivalence with the marker empty, which is everything the merge-base predicate could see, and pins the divergence separately. The GPU-present-but-unusable message names both recovery routes. Settings only carries the repair row inside the desktop app and only for a backend it manages: DesktopRepairControl returns null without a Tauri repair context and null for an externally started server. A browser-hosted Studio, or a desktop attached to a server someone started from a terminal, was being sent to a control that is not on its page.
install.sh marks a resolved backend as derived unless the family the caller
STATED survived the resolution. The case statement overwrites
UNSLOTH_TORCH_BACKEND before the marker is decided, so a caller who said "cuda"
on a host with no visible GPU carried the resolved "cpu" and had it recorded as
a deliberate choice, which denies that host the repair for good if the GPU ever
becomes visible.
_expected_torch_flavor_tag stops at an unknown-family pin rather than falling
through to the manifest. The wheel came from that mirror, so the recorded tag
describes the install the mirror replaced and the CUDA probe would hand back the
mirror's own leaf as a flavor. This also made _recordable_torch_flavor_tag's
guard unreachable: it only fires on an empty resolved, and the stale tag arrived
non-empty. The setup handover still outranks it.
Both manifest readers require an actual boolean for expected_torch_tag_pinned.
bool("false") is True, so a migrated or hand-edited manifest read as a deliberate
pin and suppressed the repair on a host that never chose one.
The sidebar collects the refresh its poll triggers. The backend's caches carry
their own 60 second TTL and the health path reads them non-blocking, so the read
that finds them expired only schedules the refresh; polling on the TTL alone put
the collecting read a whole interval later and left an attached eGPU invisible
for close to two minutes.
|
Codex Review: Didn't find any major issues. Nice work! 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". |
The block that test evaluates now reaches for window.setTimeout, and CI runs tsc against tsconfig.test.json, which my local --noEmit on the app tsconfig never covered.
The predicate is read out of install_python_stack.py and evaluated here, so the marker it now consults has to be in the namespace it is evaluated in. Empty for the existing cases, plus one that states it, which is the only way an untagged XPU wheel is known to be one.
HIP stops at the first of HIP_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES that is set, the precedence _first_visible_amd_gpu_id already applies. Reading any of them as un-hiding the cards meant HIP_VISIBLE_DEVICES=-1 beside ROCR_VISIBLE_DEVICES=0 reported a mismatch, and offered a repair, for a host masked exactly as it asked to be.
…ed CUDA install re-record the venv Two things a stale answer outlived. The frozen chat-only verdict held on any unknown inventory, so a broken probe for a vendor that never had a card kept the mismatch: detach an AMD eGPU that sysfs then conclusively reports as gone, and a broken nvidia-smi keeps saying the GPU is unusable for as long as it stays broken. _carry_unanswered_vendors_forward already re-adds the devices an unanswered vendor had reported, so nothing left to point at means no vendor that ever named a card is still unread. The verdict now records which vendors established it and holds only for uncertainty about those. An unknown that names nobody, which is what a cold cache looks like, stays conservative. _expected_torch_flavor_tag excluded a resolved cuda backend, so a CPU pin that had been REMOVED outlived the install that replaced it: install.sh resolves cuda and installs a CUDA wheel, the old manifest still says cpu, and the healthy venv is re-recorded as deliberately CPU-only, with the pinned provenance carried forward. A later update that swaps in a CPU wheel then reads as the install working as asked, and the backend suppresses the mismatch and its repair. The wheel's own cu tag answers instead, under the same rule the cpu/rocm/xpu arm already applies: only when the family agrees with what is actually installed.
The vendor set behind the frozen mismatch was recorded at detection and never after, so a mismatch that MOVES vendors inside one process -- swap an AMD eGPU for an NVIDIA one -- left the scope pointing at a card a later refresh had already watched leave. The refresh that re-establishes a mismatch now re-records who says so. nvidia-smi answering [N/A] for memory.total dropped the whole row, which took the card out of the inventory: the Linux procfs fallback does not cover it either, since that answers for a query that FAILED rather than one that came back short. A host lost its mismatch and its repair guidance over an unknown capacity. _parse_smi_value already reads [N/A] as a missing metric, so the row is kept with memory_total_gb None, which every consumer already handles. _expected_torch_flavor_was_pinned revived an old CPU record underneath the very arms that had just refused to call this run's CPU result deliberate. A ROCm pin that settled on CPU was therefore re-recorded as a pinned CPU install, and the mismatch is suppressed for good once the requested GPU works. A record now only speaks for a run that named no conflicting family; a backend install.sh derived is not a preference and still does not contradict anything.
|
Codex Review: Didn't find any major issues. Another round soon, please! 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 looks like on a real hostSettings > System, same machine and same CPU-only wheel on both sides. BEFORE is this PR's merge base The host has eight B200s in it. BEFORE says "No visible GPU" and "No visible GPU detected. CPU-only resources are shown above." AFTER, the same panel names what actually happened: the VRAM tile reads "GPU unusable / Detected, but PyTorch cannot use it", a banner says "PyTorch is a CPU-only build (2.11.0+cpu), so the GPUs below cannot be used. Repair the installation to restore GPU support.", and the eight cards are listed, greyed, each marked How the state was reproducedBoth sides were installed normally, which put Two shortcuts were deliberately not used, because this PR is supposed to stay quiet for both of them: a Numbers, read from the same servers that were photographed
The last row is the invariant worth stating: the physical inventory is published beside Not visible hereThe Settings > General repair row is Tauri-only, so a browser hosted Studio cannot render it. That is also why the banner names both routes rather than only the in-app button. |
The capability message for a host whose PyTorch cannot use its GPUs tells the user to use Repair installation in Settings, and searching Settings for "repair" answered "No settings found": the row is in the General tab but was never added to the search index, which carries its neighbour in the same Danger zone section. In the desktop-only arm, like the row itself. DesktopRepairControl renders nothing without a Tauri repair controller, so an entry on the web build would scroll to a row that is not on the page, which is what the startup and close-to-tray entries already avoid. Found by driving the real desktop app: searching for the row returned nothing.
Settings > General: the Repair installation rowCompanion to the System tab evidence above. Both sides are the real desktop app built from this branch, run under Xvfb, scrolled to the foot of Settings > General and cropped to the dialog. BEFORE (merge base): the Danger zone ends at "Reset all local preferences". AFTER (this branch): it gains "Repair installation - Reruns the installer over the managed environment. Use this if the GPU is not detected or the app will not start." with a destructive "Repair install" button, which calls Two notes on how the shot was taken, since both are easy to get wrong:
|
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |


What happens
On a Windows box with 2x RTX A4000 (driver 553.09, CUDA 12.4), Studio's Settings > System showed:
while
nvidia-smilisted both cards and Device Manager reported them working properly. The sidebar told the user their machine "needs an NVIDIA or AMD GPU". A second user on a different machine reported the same shape.The managed venv had
torch 2.11.0+cpu.Why
Every GPU field starts from
get_device(), which is torch-only. Oncetorch.cuda.is_available()returns False:_detect_hardware_locked(hardware.py:614->:648) setsDEVICE = CPUandCHAT_ONLY_REASON = "no_gpu"get_backend_visible_gpu_info()(hardware.py:4621) short-circuits on itsDeviceTypegate at:4624and returns{available: False, devices: []}get_visible_gpu_utilization()(hardware.py:3486) short-circuits the same way at:3489So
nvidia.py:239, which shellsnvidia-smi --query-gpu=index,name,memory.totaland would have listed both A4000s correctly, is never reached."no_gpu"is not a measurement here; it is what the code says when it did not look.This is the Windows/NVIDIA shape of #8473, reported there on AMD/Linux with the same conclusion ("the only branch that can populate devices is
torch.cuda"). Related: #7485, #7307.The
(none)device list is the same root cause one layer down.llama_cpp.py:9824 _windows_pip_nvidia_dll_dirssuppliescudart64_*.dll/cublas64_*.dllto the CUDA-built llama-server from the managed venv'storch/libandnvidia/*wheels. A+cpuvenv ships neither, so ggml cannot load its CUDA backend andllama-server.exe --list-devicesprintsAvailable devices: (none)whileUNSLOTH_PREBUILT_INFO.jsonstill correctly saysbackend cuda.What this PR does
Ask the OS as well as PyTorch.
get_physical_gpu_inventory()probesnvidia-smi, and on Windows the DirectX adapter registry that_rocm_windows_per_device_vramalready trusts for the System tab. It runs regardless ofDEVICE, is bounded, never raises, and is cached with a TTL rather than for the process, because a driver restart or an eGPU makes the answer change.classify_torch_build()separates two cases that need different advice:torch_cpu_build- a CPU-only wheel (2.11.0+cpu, or untagged with neithertorch.version.cudanor.hip). No driver update fixes this.torch_cuda_unavailable- an accelerator wheel whose runtime will not initialise. The wheel is right, the environment is not._detect_hardware_lockednow reports one of those instead of"no_gpu"when the host does have GPUs, and carries the torch version as the detail.An emptied
CUDA_VISIBLE_DEVICES/HIP_VISIBLE_DEVICES/ROCR_VISIBLE_DEVICES/ZE_AFFINITY_MASKproduces exactly the same observable shape (torch sees nothing,nvidia-smisees everything) but nothing is broken, so it is excluded and still reads as a deliberate hide. A mask that names devices is not excluded: that host expects those to work.That exclusion is per vendor, not host-wide. An emptied
ZE_AFFINITY_MASKbeside an unmasked NVIDIA card hides the Arc and nothing else, so a CPU wheel on that host is still worth reporting; cancelling the whole classification would let it go unreported for a card the user never masked.HIPalso honoursCUDA_VISIBLE_DEVICES, but reads its own variables first, so an AMD host that NAMES devices inHIP_VISIBLE_DEVICESwhile inheriting an emptyCUDA_VISIBLE_DEVICEShas not hidden its cards.The inventory is display-only.
physical_devicesandmismatchsit besidedevicesin the payload and are never merged into it.devicesis the runtime-usable list that the model-fit estimate budgets against and that the training device picker pins from, so a card torch cannot open must never become selectable.toGpuDevices/toGpuInfoare untouched.A diagnostic for the llama.cpp half. When the CUDA prebuilt is installed but no
cudart64_*.dllis on its DLL search path, that is now logged once per binary. It changes nothing about the launch: the process still starts and still falls back to CPU, and a custom build with the DLLs elsewhere is not second-guessed.The repair the banner points at. Both users were fixed by rerunning the installer, and one asked for a button in Settings.
start_managed_repairgainsforce_installer, which skips the update attempt, because an update reuses the environment it finds: a venv on a CPU-only wheel survives any number of successful updates, and only the installer re-selects the torch index. Settings > General grows a "Repair installation" row beside the existing reset row, wired through a small context to the samestartRepairthe startup screen uses, so it renders the same repairing screen and restarts the backend afterwards. Desktop-only; the row renders nothing on the web build.Testing
studio/backend/tests/test_torch_cpu_build_on_nvidia_host.py(new)tests/studio/install/test_cuda_repair.pytests/studio/install/test_windows_torch_flavor_invariant.pynpm test(frontend)npm run typechecknpm run i18n:check:strictcargo check(studio/src-tauri)No regression, measured rather than asserted. The full backend suite was run on this branch and at its merge base:
The set difference of failing node IDs is empty in both directions. The 110 extra passes are the tests this PR adds. The 43 pre-existing failures are unrelated; the largest cluster, 16 in
test_studio_api.py, is a terminal-width artifact and passes atCOLUMNS=200.Live no-regression on a real CUDA host. On this machine, with real torch and real cards and nothing stubbed:
DeviceType.CUDA,chat_onlyfalse,mismatchabsent,physical_devicesabsent,classify_torch_build()None. The physical probe enumerated all 8 cards and did not leak one intodevices, which correctly showed only the visible device. That is the pre-PR payload exactly.Before and after, on the reported host. The same simulated machine (Windows, two A4000s that
nvidia-smilists,2.11.0+cpuvenv) driven against both trees:no_gputorch_cpu_builddevicesCross-platform, on real runners. Replicated onto a staging repo: all 28 workflows green, including Windows Unsloth UI / API / Update / GGUF / Application Control, Mac Unsloth Install Matrix, Mac UI + API + Update + Inference, MLX CI on Mac M1, Desktop app clean machine, Unsloth Tauri CI, Frontend CI, studiobench CI and UI parity. A generated Playwright job passed on chromium, firefox and webkit.
Matrix coverage. [Windows, Linux, WSL, Mac] x [NVIDIA, AMD, CPU-only], stubbed at the vendor-probe seam so the per-OS branching really runs on each row: the inventory, the classification, the mismatch report and the payload contract are each asserted on all twelve. WSL is its own row, since it is
platform.system() == "Linux"with a workingnvidia-smi, no/sys/class/drm/card*and no procfs. Also: every probe raising at once still answersunknownon all twelve rows, and sixteen threads hammering both TTL caches in both lock orders finish without deadlock or thread leak.Old installs. Every manifest generation was replayed against a real venv: absent, pre-#9857, #9857-era (a flavor with no provenance), and both gen-2 shapes, plus truncated, non-JSON, wrong-typed, keys-from-the-future and permission-denied. Only an explicitly named CPU choice suppresses the repair, because
setup.ps1records an automatic/cpuselection identically to a pinned one.Not done here
The root cause of the CPU-only wheel is the update path, which is #9857. This PR is the reporting half: it makes the failure legible and offers the repair, and it is useful on its own for any host where torch and the hardware disagree, including the AMD/Linux shape in #8473.