Repository navigation
Studio: support Vulkan GPU selection and explicit Vulkan installation - #7188
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for explicit GPU selection and GGUF memory placement modes (auto, pinned, resident) in the inference backend. It updates the LlamaCppBackend to manage these as first-class fields, ensures they are correctly handled during model loading and state comparison, and adds validation for GGUF GPU selection. The changes include updates to the inference models, route logic for model loading, and comprehensive test coverage. I have provided feedback on simplifying redundant conditional checks in the inference route.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae20549d06
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
unsloth/studio/backend/routes/inference.py
Line 4193 in ad14c67
When training is active and a GGUF load supplies gpu_ids, this passes the list into can_load_chat_during_training, whose explicit-GPU branch applies the HF device_map="balanced" per-GPU floor even though the GGUF loader treats the list as a candidate set and _select_gpus may choose only the fitting card. A request such as gpu_ids=[0, 1] with enough free VRAM on GPU 0 but little on GPU 1 can be rejected with 409 before llama.cpp can select GPU 0; pass these IDs as a GGUF candidate pool or make the guard skip the balanced floor when is_gguf is true.
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad14c67fe8
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c781ecf87e
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19c34043d4
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19c34043d4
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad75de784f
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f3511d295
ℹ️ 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".
|
@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: 700aa81821
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f565d2c95d
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee76caa79f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f9ffe5292
ℹ️ 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".
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
Finally :) This PR exposes complexity in Unsloth internals that should be simplified/refactored; I'll leave that for a follow-up and merge the behavior improvements here once unslothai/llama.cpp#42 is merged and compiled for the first time. As a design choice, I removed the options for mlock/no-mmap, as those are relatively niche and Unsloth's UI currently hand-picks what options to display, and restricted the PR's scope to Vulkan improvements. To support further model loading options, maybe we should add an "extra flags" text field in Manual mode rather than adding more and more dropdowns/checkboxes. |
The availability check imported the module purely for its side effect, so the import-hoist verifier flagged it as an added-but-unused import and failed Source lint. find_spec answers the same question without binding a name.
find_spec raises ValueError on a module already in sys.modules whose __spec__ is None, which is what a bare types.ModuleType stub is. Check sys.modules first so anything already present, real or stubbed, is left untouched and only a genuinely absent package gets stubbed.
# Conflicts: # studio/backend/routes/inference.py # studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts # studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
Three of the tests added for the llama.cpp backend selector asserted on the same two helpers with the same inputs, and two more differed only in whether the backend arrived from the environment or from --llama-backend. Fold them into the parametrized cases that already covered those helpers: - test_llama_cpp_backend_env_requests_vulkan, test_llama_cpp_backend_auto_does_not_trigger_vulkan and test_hip_backend_env_opts_out_of_vulkan become rows on test_force_vulkan_requested_accepts_public_selector_and_legacy_alias, which now also asserts llama_backend_from_env() alongside force_vulkan_requested(). The unset case and the whitespace-padded HIP/ROCM values keep their coverage as new rows. - test_explicit_non_vulkan_backend_suppresses_intel_auto_route and test_non_vulkan_backend_argument_suppresses_intel_auto_route become one test parametrized over the env and argument paths. - test_unclassified_gguf_without_pin_keeps_the_torch_budget and test_unclassified_gguf_with_pin_refuses_to_budget shared the same four patches and differed only in the pin, so they become subtests of one case. No source changes and no assertion is dropped. Each behaviour was re-checked by reverting the source hunk it guards and confirming the surviving test fails on a value.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e0b078a3a
ℹ️ 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".
| } | ||
| return { | ||
| ...config, | ||
| gpuMemoryMode: "auto", |
There was a problem hiding this comment.
Preserve the standing GPU mode for diffusion loads
When the standing GPU Memory preference is Manual, reloading an active DiffusionGemma or applying a previously manual per-model config reaches this branch and converts the config to an explicit gpuMemoryMode: "auto". applyPerModelConfigToRuntime then writes that value into the live standing preference, while persistGpuMemoryModeOnLoad intentionally skips diffusion responses, so the session remains on Auto and the next ordinary GGUF without its own override silently loses the user's Manual preference. Omit the mode from the sanitized diffusion config or explicitly preserve the standing mode when applying it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in 090b5f6.
Traced the leak: withoutUnsupportedDiffusionSettings rewrites the config to an explicit gpuMemoryMode "auto", applyPerModelConfigToRuntime writes that straight into the runtime store, and persistGpuMemoryModeOnLoad skips diffusion responses, so nothing writes the standing Manual back. A later ordinary GGUF picked from the sidebar reaches stageOrLoad with selection.config ?? rememberedConfigFor(selection) == null, so selectModel gets no config, applyPerModelConfigToRuntime never runs, loadGpuMemoryMode falls back to stateBeforeUnload.gpuMemoryMode (the stale "auto"), and persistGpuMemoryModeOnLoad then saves it over the user's Manual.
Fixed at the single point that writes the store rather than in the sanitizer, so the load request still sends "auto" for diffusion as intended:
gpuMemoryMode: options.isDiffusion
? readPersistedGpuMemoryMode()
: (config.gpuMemoryMode ?? readPersistedGpuMemoryMode()),
This mirrors the tensorParallel: options.isDiffusion ? false : ... line right above it. Covered by tests/studio/test_model_picker_contracts.py::test_diffusion_load_keeps_the_standing_gpu_memory_mode, which also pins the is_gguf && !is_diffusion persist guard and the sanitizer call so the two halves cannot drift apart.
| if published_repo != UPSTREAM_REPO: | ||
| published_release_tag = "" | ||
| return host, UPSTREAM_REPO, published_release_tag, persist_backend | ||
| return host, published_repo, published_release_tag, persist_backend |
There was a problem hiding this comment.
Retain the upstream Vulkan fallback for Linux ARM64
With UNSLOTH_LLAMA_CPP_BACKEND=vulkan on Linux ARM64 and the default published repository, this now keeps planning against the Unsloth manifest, whose architecture filter rejects its x64-only Vulkan artifact; strict Vulkan filtering then removes the ARM64 CPU attempt and the setup exits without installing anything. The direct upstream resolver already supports llama-*-bin-ubuntu-vulkan-arm64.tar.gz, and the previous implementation routed Vulkan requests there, so Linux ARM64 Vulkan installations that previously worked now fail unless the user manually overrides the repository. Route this unsupported manifest/architecture combination back to upstream or publish a matching ARM64 bundle.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and reproduced before fixing. In 090b5f6.
With UNSLOTH_LLAMA_CPP_BACKEND=vulkan on Linux ARM64 and the default fork repo, _route_to_vulkan_prebuilt now returns published_repo, so resolve_simple_install_release_plans takes the fork-manifest branch. published_asset_choice_for_kind's architecture filter drops the x64-only Vulkan artifact for an ARM64 host, so _linux_published_attempts yields only linux-arm64, and _vulkan_only_release_plans then strips that and raises PrebuiltFallback:
fork attempts: ['linux-arm64']
strict vulkan RAISED: PrebuiltFallback no Vulkan prebuilt bundle attempts were available
Upstream still serves this host: direct_upstream_release_plan on the same routed host returns llama-b9925-bin-ubuntu-vulkan-arm64.tar.gz first.
Fix routes only that combination back to UPSTREAM_REPO, at the end of _route_to_vulkan_prebuilt, and drops the fork pin because the two repos use different tag namespaces (fork b9596-mix- vs upstream b9596). Windows arm64 still exits earlier via _has_no_vulkan_prebuilt and macOS via the Metal branch, Linux x86_64 keeps the fork bundle so it still gets the DiffusionGemma visual server, and an explicit --published-repo override is left alone.
Four tests in studio/backend/tests/test_install_resolve_prebuilt.py cover the reroute, the end-to-end "fork yields only linux-arm64, upstream yields the Vulkan bundle" path, the explicit-repo override, and the x86_64 no-change case.
|
@codex review |
|
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". |
…rness doubling --force-cpu test_non_vulkan_backend_suppresses_intel_auto_route ran on Linux x86_64, where dropping the explicit_backend guard changes only a log line, so the test passed either way. Move it to Linux ARM64 + Intel GPU, the host where the guard decides the routed repo, and assert that value. _run_ps1 composed the --force-cpu snippet twice: it is already inside the normalized block the helper extracts. The substring assertion hid the duplicate. Compose it once and compare the whole argv. setup.ps1 appends the flag once and is unchanged.
|
Two test-quality fixes from an idempotency audit. Both are test-only; the product code was correct in both cases. 1. A test that could not fail. 2. A helper that emitted a flag twice. Test counts unchanged: |
unslothai#7549 taught Test-VCRedistInstalled to consult the host architecture before trusting the System32 DLL. The Pester suite dot-sources a fixed list of functions out of setup.ps1 one at a time, and that list did not gain the helper, so the two clean-box cases (registry miss, and an old sub-14.20 redist) throw "Get-HostMachineArch is not recognized" instead of returning false. The registry hit returns early, which is why the other cases pass. unslothai#7597 made exactly this fix to the sibling list in the VC++ round-trip job but left the Pester suite alone. Verified with pwsh 7.6 + Pester: 3 failed before, 31 passed 0 failed after.
|
Merged main (the branch was 21 commits behind) and fixed the The Windows failures were not a routing problem in this branch. CI builds the PR merged into main, so the merged Local results after the merge, against the pre-merge baselines:
Two remaining reds are main's rather than this branch's:
Both want a fix on main rather than in this PR. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0573a0e0f0
ℹ️ 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".
| # Fork and upstream use different tag namespaces (fork b9596-mix-<sha> vs | ||
| # upstream b9596), so carrying a fork pin over would make the upstream | ||
| # resolver query a release that does not exist. | ||
| return host, UPSTREAM_REPO, "", persist_backend |
There was a problem hiding this comment.
Keep the diffusion runner on ARM64 Vulkan installs
On Linux ARM64 with the default repository and an explicit/automatic Vulkan route, this switches the install to ggml-org/llama.cpp, whose bundle does not contain the Unsloth-only DiffusionGemma visual server. The later backfill cannot recover it: ensure_diffusion_visual_server queries the Unsloth repository using the upstream plan's differently namespaced release tag and checksum manifest, then quietly leaves the install valid without the runner, so DiffusionGemma loads fail unless DG_VISUAL_BIN is supplied manually. Fresh evidence beyond the earlier general Vulkan-runner report is this newly added ARM64-only upstream fallback; either publish an ARM64 fork bundle or resolve a matching verified runner separately.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Checked this against origin/main and it is not a regression this PR introduces.
main's _route_to_vulkan_prebuilt already ends with an unconditional return host, UPSTREAM_REPO, published_release_tag, persist_backend, so on main every Vulkan route installs the ggml-org bundle and has no visual server. The new clause narrows that to Linux ARM64 only. Running _route_to_vulkan_prebuilt on both trees with the same synthetic hosts:
origin/main cf9628882 this branch 5bfd46316
arm64 forced -> ggml-org (no runner) arm64 forced -> ggml-org (no runner)
arm64 auto -> ggml-org (no runner) arm64 auto -> ggml-org (no runner)
x64 forced -> ggml-org (no runner) x64 forced -> unslothai (ships the runner)
x64 auto -> ggml-org (no runner) x64 auto -> unslothai (ships the runner)
Linux ARM64 is unchanged; x86_64 and Windows are the platforms that gain the runner back. The fork publishes no linux-arm64-vulkan bundle at all (41 assets in b10107-mix-1911198, only linux-x64-vulkan and windows-x64-vulkan), which is exactly why ARM64 has to keep planning against upstream, and without the reroute a forced-Vulkan ARM64 host resolves to nothing at all, so there is no diffusion runner there to keep.
On the backfill: ensure_diffusion_visual_server cannot recover the binary for anyone, not just ARM64. unslothai/llama.cpp ships no standalone llama-diffusion-gemma-visual-server asset in any recent release (0 of 41 in each of the last three), so the lookup logs "not found in the published release" even with a correctly namespaced fork tag. The runner only ever arrives inside an app bundle via runtime_patterns_for_choice; I unpacked app-b10107-mix-1911198-linux-x64-vulkan.tar.gz, -linux-x64-cpu.tar.gz and -linux-arm64-cpu.tar.gz and each contains ./llama-diffusion-gemma-visual-server.
Publishing an ARM64 fork Vulkan bundle is a release-side change, not something this PR can make. Same conclusion as the earlier report on this surface.
landed This branch carried a local fix for the same Pester dot-source gap that unslothai#7606 has since merged to main (f21b280). Keeping both leaves the PR diff with an unrelated, now-duplicated change, so drop the branch copy and take main's.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dbfae7d92c
ℹ️ 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".
| bundles explicitly, while ``hip``/``rocm`` opt out of automatic Vulkan routing. | ||
| """ | ||
| return _normalized_llama_backend(os.environ.get("UNSLOTH_LLAMA_BACKEND")) | ||
| return _normalized_llama_backend(os.environ.get("UNSLOTH_LLAMA_CPP_BACKEND")) |
There was a problem hiding this comment.
Preserve the legacy backend environment variable
When an existing installation sets only UNSLOTH_LLAMA_BACKEND (for example, UNSLOTH_LLAMA_BACKEND=vulkan), this now returns None and silently resumes automatic backend selection; before this commit that variable was the explicit selector. This can replace a deliberately selected Vulkan/CPU/HIP backend with a different detected backend during setup or updates. Fall back to UNSLOTH_LLAMA_BACKEND when the new UNSLOTH_LLAMA_CPP_BACKEND does not contain a recognized explicit choice.
Useful? React with 👍 / 👎.
| if host.has_intel_gpu and not host.has_physical_nvidia: | ||
| vulkan_choice = published_asset_choice_for_kind(bundle, "linux-vulkan", host = host) | ||
| if vulkan_choice is not None: | ||
| attempts.append(vulkan_choice) |
There was a problem hiding this comment.
Honor the HIP opt-out in the Intel Linux planner
On a Linux x86_64 host where Intel graphics are detected, setting UNSLOTH_LLAMA_CPP_BACKEND=hip or rocm does not actually opt out of automatic Vulkan installation. _route_to_vulkan_prebuilt correctly declines its auto-route for an explicit backend, but returns the unchanged Intel-marked host, and this planner independently prepends the Vulkan bundle solely from has_intel_gpu. Consequently setup can install Vulkan despite the explicit HIP/ROCm choice; propagate the selector into planning or suppress this Intel branch when a non-Vulkan backend was explicitly selected.
Useful? React with 👍 / 👎.
…lpers (#7645) #7188 added three bare exits to studio/setup.sh and three to studio/setup.ps1 for the explicit-Vulkan paths. Bare exits skip setup_fail / Exit-SetupFailure, so the [TAURI:ERROR] line that #7529 added never reaches Studio desktop and a Vulkan install failure shows up there with no actionable context. tests/sh/test_tauri_retry_failure_context.sh already asserts that each setup script has exactly one explicit exit and that it lives inside the helper. That assertion was failing, but the failure was invisible: Backend CI skips the Shell installer tests step whenever the auto-discovered pytest step fails first, and it had been failing on an unrelated encoding assertion until #7642. Exit codes are unchanged: setup_fail 1 and Exit-SetupFailure both exit 1, and the Tauri line is still emitted only when UNSLOTH_TAURI_MODE is set.
What this PR does
Studio already has a GPU picker for GGUF models. This PR makes that existing picker work with Vulkan devices and makes explicit Vulkan installation reliable.
PR #7373 added explicit Vulkan installer routing and the Windows AMD fallback when no compatible HIP prebuilt exists. This PR preserves those behaviors, consolidates the backend environment setting onto the preexisting
UNSLOTH_LLAMA_CPP_BACKENDselector, and completes the Studio GPU-selection integration.Vulkan GPU selection
/api/systemfor the existing Studio GGUF GPU picker.--device Vulkan0,Vulkan1.--device,--main-gpu,LLAMA_ARG_DEVICE, andLLAMA_ARG_MAIN_GPUvalues when the picker owns device placement.Vulkan installation
UNSLOTH_LLAMA_CPP_BACKENDselector withvulkaninstead of retaining the competingUNSLOTH_LLAMA_BACKENDsetting introduced by Installer: opt-in Vulkan llama.cpp backend (and fallback when no AMD card is HIP-supported) #7373.UNSLOTH_FORCE_VULKANcompatible and acceptsonin addition to its existing truthy values.unslothai/llama.cppinstead of redirecting to the upstreamggml-org/llama.cpppackages.libggml-vulkan.so.0during backend detection and probing.