Repository navigation
Studio: load GGUF on CPU when the auto-selected Vulkan driver hangs or has no device - #14521
Conversation
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. |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
|
@codex security review |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
…be fixture [skip ci]
…store env after a failed stall replay [skip ci]
|
@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: 1c81380645
ℹ️ 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".
| self._kill_process() | ||
| # Terminal like the crash replay: the rungs below would relaunch the | ||
| # same driver, and the replay has already rewritten env for CPU. | ||
| if _try_auto_vulkan_cpu_fallback(_stalled_cmd, None, stalled = True): |
There was a problem hiding this comment.
Restore policy state when stalled replay staging fails
When a stalled auto-Vulkan launch uses a speculative drafter and CPU staging cannot be built (for example, because the CPU library is missing or staging hits an I/O error), this call returns false after _prepare_cpu_fallback_launch has already run _drop_managed_dio(..., clear_record=False) and may have rewritten the shared environment. Execution then falls through to the drafterless retry below; if that Vulkan child succeeds, it still carries the original managed DirectIO arguments while _memory_dio_applicable and _memory_policy_active describe the abandoned CPU replay. Fresh evidence beyond the earlier resolved policy-state comment is the prepared is None path, which remains nonterminal despite mutating launch state. Make preparation transactional, or restore/terminate before entering subsequent retry rungs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: staging returns None only for a bundle without a CPU ggml library (every managed prebuilt ships one) or a drafter the build cannot pin to CPU, and the pre-launch route already refuses those. Guarding that path adds code for an install that is already broken.
| else f"probe: {_vk_outcome}", | ||
| ) | ||
| intent = replace(intent, cpu_fallback = True) | ||
| _cpu_route_reason = _remembered or "vulkan_no_device" |
There was a problem hiding this comment.
Reprobe no-device fallbacks on forced reload
After this route records vulkan_no_device, every later same-source request is rewritten by _preserve_cpu_fallback_intent before force_reload is considered, so even an explicit forced reload arrives here with intent.cpu_fallback=True and skips _vulkan_probe_outcome. If a GPU is hot-plugged, enabled, or made visible after the original load, reloading the same model therefore keeps using the staged CPU runtime indefinitely; switching models, unloading, or manually changing placement is required to recover acceleration. Preserve the sticky behavior for remembered stalls if desired, but allow a no-device fallback to reprobe on a forced reload.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping it sticky on purpose: it matches the existing crash recovery, which also replays on CPU for the same source. Hot-plugging a GPU into a host whose Vulkan probe saw zero devices is rare, and loading another model or restarting Studio re-probes.
There was a problem hiding this comment.
Revisited: a reload of the same source after a zero-device CPU route now runs the Vulkan probe again, and a device that has appeared since takes the Vulkan path (test_a_reload_after_a_zero_device_probe_asks_again). Crash recoveries stay sticky as before.
| _cpu_route_reason | ||
| or self._cpu_fallback_reason | ||
| or "vulkan_startup_crash" |
There was a problem hiding this comment.
Preserve the fallback cause across rollback replay
When a model that was running under vulkan_no_device or vulkan_startup_stall is unloaded by a failed model switch, the failure cleanup clears _cpu_fallback_reason, while the frontend rollback request retains only the boolean cpu_fallback. This default consequently labels the restored CPU model as vulkan_startup_crash, so its status and toast give users the wrong diagnosis and recovery guidance. Carry the previous reason in the rollback request/state, or recover it from the current no-device probe/session-stall memo instead of defaulting every reasonless replay to a crash.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this: it only changes the wording of the CPU notice after a rollback in a fresh state, the placement and behaviour are correct, and carrying the reason through the rollback request is more surface than the label is worth.
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
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". |
|
pre-commit.ci run |
… stall replay with the vision argv clears the text-only diagnosis
|
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". |
|
pre-commit.ci run |
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts [skip ci]
Conflicts: - studio/frontend/scripts/check-bundle-budget.ts: took main's budget and history, then re-measured. origin/main 2f9e7d3 alone: 6,919,932 B raw / 2,084,279 B transfer. Merged tree: 6,921,180 B raw / 2,084,519 B transfer (Node 24, 97 chunks), +1,248 B raw / +240 B transfer from this PR. Raw raised to 6,921,340 (measured + 160 B); transfer stays at main's 2,084,696. - studio/frontend/tests/partial-offload.test.ts: kept the vulkan_no_device / vulkan_startup_stall assertions, dropped the comment main removed. [skip ci]
|
Codex Review: Didn't find any major issues. Bravo. 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". |
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts # studio/frontend/src/features/chat/lib/partial-offload.ts [skip ci]
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
… that was still loading
|
@codex review |
1 similar comment
|
@codex review |
|
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". |
## Summary `studio/backend/tests/test_model_memory_settings.py::TestNoNestedHelperIsUsedBeforeItsDef::test_every_nested_def_precedes_its_calls` fails on main, so `(Python 3.13, g-r)` is red on unrelated PRs (for example #15225): ``` AssertionError: UnboundLocalError at runtime: _try_auto_vulkan_cpu_fallback called at 8198, defined at 8232 ``` #14521 (load GGUF on CPU when the auto-selected Vulkan driver hangs) added the nested `_recover_vulkan_stall` inside `load_model`. It calls `_try_auto_vulkan_cpu_fallback`, which is defined about 40 lines further down. Today this does not raise: all three callers of `_recover_vulkan_stall` sit below both definitions, and a closure looks the name up when it runs. But the guard's rule is "a nested helper is defined above every textual use", because the looser version (the call is fine as long as every caller of the caller runs late enough) already shipped broken once and aborted every full-offload launch. Keeping that simple rule true is cheaper than teaching the guard call-graph ordering. ## Change - Move `_recover_vulkan_stall` (unchanged, 19 lines) from just above `_vulkan_stall_pending` to just below `_try_auto_vulkan_cpu_fallback`. It is still above its first caller. Only `def`s sit between the old and new spots, and the defaults are literals, so nothing evaluates differently. ## Verification - The diff is a pure move: every removed line is added back once. - `test_every_nested_def_precedes_its_calls`: fails on main, passes with this change. - `test_vulkan_no_device_cpu_route.py`, `test_gpu_init_crash_message.py`, `test_load_mode_fit_matrix.py`, `test_vram_budget_settings.py`, `test_model_memory_settings.py`: `1 failed, 2402 passed` on main (the guard), `2403 passed` with this change.
Main's Vulkan no-device probe (#14521) sends a load to --device none after the spilled-MoE cut was priced. The pre-spawn CPU route already restores the slots; this checks it once that route is merged, and skips before. [skip ci]
…iled (unslothai#18172) ## Problem A Discord user on Unsloth Desktop (Windows 11, Intel Core i7-6700T, 8 GB RAM, only an Intel HD Graphics 530) saw "Loading a model..." for more than 30 minutes on `unsloth/DeepSeek-R1-Distill-Qwen-1.5B-GGUF`. Settings > System showed "No visible GPU" with the bundled Vulkan build. Since unslothai#14521 a Vulkan auto-selected load already handles most of this: - the device probe listed zero devices: start on CPU right away; - the probe timed out or crashed: wait 300 s without counting CPU spin as progress, then replay on CPU. A probe that failed any other way (`error`: non-zero exit without a signal, an exception, or a bundle without the Vulkan backend library) was grouped with a probe that listed a working device. That gets the listed-device budget: CPU work renews the 600 s stall window, the ceiling is 3x (30 minutes for a small model), and the end is a terminal error that tells the user to pick CPU in Settings. A failed probe proved no device, so the rationale for that budget ("the probe saw a working device, so a slow start is not proof of a broken driver") does not apply. ## Fix Treat a failed probe like a timed-out or crashed one (`_vulkan_suspect`). A healthy start is unchanged and stays on Vulkan; only a start that makes no loading progress is replayed on CPU after 300 s instead of failing after 30 minutes. A probe that listed a device keeps the current behaviour. This does not change the UI or any setting, and the next load re-probes, so one bad start never pins a build to CPU. ## Tests `tests/test_vulkan_no_device_cpu_route.py`: `error` joins the suspect cases in the stall-window test and in `test_a_hung_suspect_launch_replays_on_cpu`; the listed-device stall test keeps `devices` only. | Case | merge base | this PR | |---|---|---| | failed probe, healthy start | Vulkan, 600 s window, CPU counts as progress | Vulkan, 300 s window, CPU does not count | | failed probe, start with no progress | terminal error, no CPU replay | replayed on CPU, reason `vulkan_startup_stall` | | probe listed a device, stalled | terminal error | terminal error (unchanged) | `pytest tests/test_vulkan_no_device_cpu_route.py`: 52 passed (base: the two `error` cases fail). `tests/test_gpu_arch_gate_os_matrix_7624.py tests/test_llama_cpp_mmproj_fallback.py`: 341 passed on both base and head.
Summary
On a Windows PC whose only GPU is an older Intel iGPU (reported on an i7-6700T with Intel HD Graphics 530), Studio and Desktop install the Vulkan llama.cpp build automatically. Loading a small GGUF (DeepSeek-R1-Distill-Qwen-1.5B UD-IQ1_S) then sat on "Loading a model..." for over 30 minutes and never finished. Settings > System showed
VULKANwith "No visible GPU", and the Compute backend picker was blank.GGUF chat should always work on such a machine, since the Vulkan build also carries the llama.cpp CPU backend. This PR makes it fall back to CPU instead of waiting forever.
Root cause
ggml-vulkanand initialises the driver even with-ngl 0or--device none(see [Bug] Unsloth Studio built llama.cpp with Vulkan instead of CPU only #7213). A driver stuck in device init or shader compilation never makes llama-server healthy.--device none -ngl 0 --fit off) only runs after a signal crash, never after a hang./api/llama/backendis still resolving, because the selected value has no item yet.What changes
All of this applies only to a managed, auto-selected Vulkan bundle with automatic placement, i.e. the same gate the existing crash recovery uses. A Vulkan backend picked in Settings or by
UNSLOTH_LLAMA_CPP_BACKEND, a custom llama.cpp folder, explicitgpu_ids, layer counts or tensor splits all keep today's behaviour, as do CUDA, ROCm, Metal and CPU builds.The rule throughout: a GPU that might work is never moved to CPU on a guess. Only a probe that proves there is no device, or a driver that cannot even enumerate and then does no loading work at all, sends a load to CPU.
cpu_fallback_reason = "vulkan_no_device").cpu_fallback_reason = "vulkan_startup_stall"). If that replay also fails, the load fails with the classified error, the same as the crash replay.cpu_fallback_reasonaccepts the two new values. The chat load notice says the model runs on CPU and why, using the same flow as the crash recovery.Loading...until the status arrives (orUnknownnext to the error if it fails), and keeps the current selection visible when no options resolved, instead of a blank box. No new i18n keys.Testing
A Linux end-to-end harness runs the upstream
b11795ubuntu-vulkan bundle as a managed auto-selected install and callsLlamaCppBackend.load_modeldirectly. AnLD_PRELOADshim makesvkEnumeratePhysicalDevicesspin forever, optionally allocating 2 MiB/s, to mimic the stuck driver. The harness stall window is 60 s on both sides. The timings were measured on the first revision of this PR; the last column is what the current rule does, and the two rows marked * changed with it (covered by the unit tests below, not re-timed).With the shipped defaults a driver that cannot enumerate reaches CPU after the 15 s probe plus 300 s of no loading work. The zero-device route (probe completes and lists nothing) is covered by unit tests; on this host a missing ICD makes the probe abort instead, which keeps today's behaviour.
Unit tests:
tests/test_vulkan_no_device_cpu_route.py(new, 40 tests): probe outcome classification; the route taken only for zero devices; no route for a listed device, timeout, fault, error, user-chosen Vulkan or explicit placement; a stall replays on CPU only after a timed-out or faulted probe with no loading work; a stall after a listed device, or a child cut off by the ceiling while loading, fails with the Settings advice and spawns nothing else; a recovered stall is not remembered (the next load launches Vulkan); the health wait tells "no progress" from "ceiling" (including a ceiling no longer than the window); a slow but loading child comes up on its device; the bounded text-only projector retry; the terminal stall replay; cancellation. 13 of them fail against the previous revision of this branch.test_gpu_init_crash_message.py,test_llama_cpp_wait_for_health.py,test_llama_cpp_vulkan_probe.py,test_gguf_load_cache_reuse.py,test_llama_cpp_placement.py: 850 passed here; main fails the same 5 placement test IDs (noggufmodule in this environment, drafter tests) and nothing else.npm run typecheckis clean. The startup bundle grows by 737 B raw / 288 B transfer over main (measured, budget raised by that).Not covered here: real Windows hardware with an Intel Gen9 driver. The Windows exit-code classification is covered by unit tests only.
Screenshots
Settings > System > GGUF inference engine, merge base vs this PR, Chromium.
While
/api/llama/backendis still answering (held open in the browser, the resolver can take up to 60 s on a slow host): the picker was blank, the state from the original report. It now readsLoading....When the status resolves with no options (here
UNSLOTH_DISABLE_UPDATE_CHECK=1), the picker was blank. It now shows the current selection,Automatic (CUDA)on this host.Re-checked on the final head
441552d72against merge basec9fab474c(Settings > System, Chromium, the Studio UI regression run): the Compute backend picker that rendered blank now shows the current selection.