Skip to content

feat(studio): add UNSLOTH_LLAMA_CPP_BACKEND env var to force CPU fallback #7213 - #7228

Merged
danielhanchen merged 14 commits into
unslothai:mainfrom
VectorCipher:fix/7213-vulkan-only-built-error
Jul 20, 2026
Merged

danielhanchen merged 14 commits into
unslothai:mainfrom
VectorCipher:fix/7213-vulkan-only-built-error

Conversation

@VectorCipher

Copy link
Copy Markdown
Contributor

This PR introduces a new user-facing environment variable UNSLOTH_LLAMA_CPP_BACKEND to allow users to force the CPU-only llama.cpp prebuilt on GPU hosts.

Background

Currently, install_llama_prebuilt.py automatically routes Intel (and other non-NVIDIA/non-AMD) GPUs to the Vulkan prebuilt because it generally offers better performance than the CPU backend. However, on some specific hardware setups (e.g., Intel UHD 630 on Linux), the Vulkan backend crashes with vk::Queue::submit: ErrorDeviceLost.

Before this PR, users facing this driver/hardware compatibility issue had no way to bypass the Vulkan auto-routing and force a CPU fallback.

Changes Made

This fix is pure plumbing—it does not alter the existing hardware auto-detection logic, but exposes the internal --cpu-fallback mechanism as a user override.

  • setup.sh / setup.ps1: Added support for UNSLOTH_LLAMA_CPP_BACKEND=cpu. When this is set, the installer scripts append --cpu-fallback to the install_llama_prebuilt.py command, bypassing the Vulkan/CUDA/ROCm selection. Follows the same env-var-override convention already used for UNSLOTH_LLAMA_RELEASE_TAG / UNSLOTH_LLAMA_FORCE_COMPILE / UNSLOTH_ROCM_GFX_ARCH.

Testing

  • Existing coverage in test_install_resolve_prebuilt.py (test_route_to_vulkan_prebuilt_cpu_fallback_wins, test_force_cpu_clears_all_gpu_attributes_including_intel) already confirms --cpu-fallback correctly suppresses Vulkan routing — unchanged by this PR since the routing logic itself isn't touched, only its trigger surface.
  • Added a new test asserting setup.sh appends --cpu-fallback to the installer command array when UNSLOTH_LLAMA_CPP_BACKEND=cpu is set — this is the actual new behavior this PR introduces.
  • Equivalent coverage for setup.ps1's $prebuiltArgs forwarding — in progress / open for review.
  • Manually confirmed the environment variable correctly forwards the flag and selects the CPU bundle on both Windows and Linux paths.

Follow-ups (intentionally not in this PR)

  1. The Vulkan ErrorDeviceLost crash itself is a separate hardware/driver-compat problem worth its own investigation — e.g. a startup health-check that auto-retries with --cpu-fallback if the GPU backend crashes immediately on launch, so users don't have to self-diagnose this the way the original reporter did.
  2. A Studio Settings UI toggle for this, once the env var path is proven out in the wild.

@VectorCipher VectorCipher changed the title feat(studio): add UNSLOTH_LLAMA_CPP_BACKEND env var to force CPU fallback feat(studio): add UNSLOTH_LLAMA_CPP_BACKEND env var to force CPU fallback #7214 Jul 18, 2026
@VectorCipher VectorCipher changed the title feat(studio): add UNSLOTH_LLAMA_CPP_BACKEND env var to force CPU fallback #7214 feat(studio): add UNSLOTH_LLAMA_CPP_BACKEND env var to force CPU fallback #7213 Jul 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the UNSLOTH_LLAMA_CPP_BACKEND environment variable in both setup.ps1 and setup.sh. When set to 'cpu', it forces a CPU-only prebuilt bundle via the --cpu-fallback flag to prevent Intel iGPU Vulkan crashes. A Python test was also added to verify this fallback behavior. Feedback suggests making the environment variable check in setup.sh case-insensitive for consistency with the PowerShell script, and points out that a test for setup.sh mentioned in the PR description is missing from the changes.

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.

Comment thread studio/setup.sh Outdated
Comment on lines +1369 to +1371
if [ "${UNSLOTH_LLAMA_CPP_BACKEND:-auto}" = "cpu" ]; then
_PREBUILT_CMD+=(--cpu-fallback)
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better robustness and consistency with the PowerShell script (setup.ps1), which performs a case-insensitive comparison, I suggest making this check case-insensitive as well. This will ensure that UNSLOTH_LLAMA_CPP_BACKEND=CPU works as a user might expect.

A case statement is a portable and idiomatic way to achieve this in shell scripts.

Suggested change
if [ "${UNSLOTH_LLAMA_CPP_BACKEND:-auto}" = "cpu" ]; then
_PREBUILT_CMD+=(--cpu-fallback)
fi
case "${UNSLOTH_LLAMA_CPP_BACKEND:-auto}" in
[cC][pP][uU])
_PREBUILT_CMD+=(--cpu-fallback)
;;
esac

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in fe6b681: setup.sh now uses a case-insensitive case match ([cC][pP][uU]), so cpu, CPU and Cpu all work, matching setup.ps1's -eq.

Comment thread studio/setup.sh Outdated
# UNSLOTH_LLAMA_CPP_BACKEND: "auto" (default) or "cpu" -- forces the CPU-only
# prebuilt, bypassing Vulkan/CUDA/ROCm selection. Fixes Intel iGPU Vulkan
# crashes (#7213). Matches install_llama_prebuilt.py --cpu-fallback.
if [ "${UNSLOTH_LLAMA_CPP_BACKEND:-auto}" = "cpu" ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The pull request description states, "Added a new test asserting setup.sh appends --cpu-fallback to the installer command array when UNSLOTH_LLAMA_CPP_BACKEND=cpu is set". However, this test does not appear to be included in the current changes. Please ensure the test is added to verify this new logic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added studio/backend/tests/test_setup_llama_cpp_backend.py, which extracts and runs the real setup.sh case block and asserts --cpu-fallback is appended for cpu/CPU/Cpu and absent for auto/unset/vulkan. Updater-side behavior is covered by test_start_update_preserves_cpu_via_flag.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f09743fb0f

ℹ️ 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".

Comment thread studio/setup.sh Outdated
Comment on lines +1369 to +1370
if [ "${UNSLOTH_LLAMA_CPP_BACKEND:-auto}" = "cpu" ]; then
_PREBUILT_CMD+=(--cpu-fallback)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve CPU backend during llama.cpp updates

When users set UNSLOTH_LLAMA_CPP_BACKEND=cpu on an Intel GPU host, this setup path installs the CPU bundle, but the in-app updater later reconstructs the installer command in studio/backend/utils/llama_cpp_update.py:518-524 without --cpu-fallback, and the installer has no env default for that flag (install_llama_prebuilt.py:7206-7209). Because _run_update only preserves Vulkan markers (llama_cpp_update.py:528-533), accepting a llama.cpp update after using this new override reruns host detection and auto-routes the CPU install back to the upstream Vulkan bundle, reintroducing the crash the override is meant to avoid.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was a real gap. Fixed in fe6b681: the installer now records install_kind in the prebuilt marker, and _run_update re-asserts --cpu-fallback when the installed bundle is CPU, so an in-app llama.cpp update no longer re-routes a forced-CPU Intel host back to the Vulkan bundle. Keyed on install_kind rather than the asset name because the Linux CPU bundle (bin-ubuntu-x64) carries no cpu marker. Covered by test_start_update_preserves_cpu_via_flag.

shimmyshimmer and others added 2 commits July 19, 2026 07:57
…unslothai#7228

The in-app updater rebuilt the installer command without --cpu-fallback and
only re-asserted Vulkan, so accepting a llama.cpp update after forcing CPU on
an Intel iGPU host re-ran host detection and routed back to the crashing Vulkan
bundle (unslothai#7213). Record install_kind in the prebuilt marker and re-assert
--cpu-fallback on update when the installed bundle is CPU.

Also make setup.sh's UNSLOTH_LLAMA_CPP_BACKEND check case-insensitive to match
setup.ps1, and add tests for the updater CPU preservation and the setup.sh flag
plumbing.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed fe6b681 to address the review feedback.

Preserve the CPU override across in-app updates (the main gap)
The in-app updater rebuilt the installer command without --cpu-fallback and only re-asserted Vulkan, so accepting a llama.cpp update after forcing CPU on an Intel iGPU host re-ran host detection and routed straight back to the crashing Vulkan bundle. Now:

  • install_llama_prebuilt.py records install_kind in UNSLOTH_PREBUILT_INFO.json.
  • _run_update re-asserts --cpu-fallback when the installed bundle is CPU (install_kind ends with -cpu). Keyed on install_kind rather than the asset name, since the Linux CPU bundle (bin-ubuntu-x64) has no cpu marker.

setup.sh case-insensitivity
Switched to a case-insensitive case match, so cpu, CPU and Cpu all work, matching setup.ps1.

Tests

  • test_start_update_preserves_cpu_via_flag: a forced-CPU install re-asserts --cpu-fallback on update.
  • test_setup_llama_cpp_backend.py: runs the real setup.sh block and checks the flag plumbing for cpu/CPU/Cpu vs auto/unset.

Local runs are green: test_llama_cpp_update.py (51 passed), test_install_resolve_prebuilt.py (33 passed), test_setup_llama_cpp_backend.py (6 passed).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce7586f01f

ℹ️ 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".

# detect_host would otherwise re-route to the Vulkan bundle and bring
# back the crash the override avoids (#7213). install_kind is *-cpu for
# every CPU bundle; the asset name has no "cpu" marker on Linux.
if install_kind and install_kind.endswith("-cpu"):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve arm64 CPU fallback on updates

Fresh evidence since the earlier CPU-preservation thread is that not every CPU-only install kind ends in -cpu: Linux arm64 CPU bundles are recorded as linux-arm64 in install_llama_prebuilt.py (the selector uses that kind for arm64 CPU assets). On an ARM64 Linux GPU host where setup used --cpu-fallback—either from UNSLOTH_LLAMA_CPP_BACKEND=cpu or the existing arm64 CPU fallback—this check skips re-adding --cpu-fallback during an in-app update, so detect_host can switch the install back to a GPU/source-build path instead of preserving the CPU bundle. Please treat the CPU-only arm64 kind as a CPU install here too.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ff226d4: the update-path check now matches the full set of CPU-only kinds (linux-cpu, windows-cpu, linux-arm64, windows-arm64) via _CPU_INSTALL_KINDS instead of only a -cpu suffix, so an arm64 CPU install re-asserts --cpu-fallback on update. Added parametrized coverage over the arm64 kinds plus GPU-kind negatives.

Comment thread studio/setup.ps1 Outdated
Comment on lines +3377 to +3378
if ($env:UNSLOTH_LLAMA_CPP_BACKEND -eq "cpu") {
$prebuiltArgs += "--cpu-fallback"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor CPU override before pruning Windows installs

In the Windows setup path, this flag is appended after the existing install mismatch-pruning block has already computed expected kinds from $HasROCm/$HasNvidiaSmi. Since this commit also starts persisting install_kind, that block is no longer inert: on Windows NVIDIA/ROCm hosts with UNSLOTH_LLAMA_CPP_BACKEND=cpu, it sees a valid windows-cpu marker as mismatched and deletes it before this flag can make CPU expected, causing every rerun to reinstall instead of skipping an up-to-date CPU bundle. Please incorporate the override into the expected-kind check before deleting.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ff226d4: normalized the override once at the top of the prebuilt block and made the Windows mismatch-prune treat UNSLOTH_LLAMA_CPP_BACKEND=cpu as expecting windows-cpu/windows-arm64, so a deliberate CPU install is no longer deleted on a GPU host. Also corrected the now-stale 'block is inert' comment since install_kind is persisted. Added a pwsh test asserting windows-cpu stays expected on an NVIDIA host.

…or PR unslothai#7228

Trim surrounding whitespace and lowercase the value in both setup.sh and
setup.ps1, so values like ' cpu ' or 'CPU' still force the CPU-only prebuilt.
An unrecognized value (e.g. 'gpu') now prints a warning instead of silently
falling back to auto. Extend test_setup_llama_cpp_backend.py to cover both
scripts, including trimmed, empty and unknown values.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed 8412eae with two small hardening follow-ups.

Value trimming and validation
Both setup.sh and setup.ps1 now trim surrounding whitespace and lowercase the value, so cpu or CPU still force the CPU-only prebuilt. An unrecognized value (for example gpu) now prints a warning instead of silently falling back to auto, so a typo is visible rather than quietly ignored.

setup.ps1 coverage (closes the open checkbox)
test_setup_llama_cpp_backend.py now exercises the real block extracted from both setup.sh and setup.ps1 across cpu/CPU/Cpu, trimmed values, empty/auto, and unknown values (26 cases). The PowerShell cases skip automatically when pwsh is not on PATH.

Local runs are green: test_setup_llama_cpp_backend.py (26 passed), test_llama_cpp_update.py (51 passed), test_install_resolve_prebuilt.py (33 passed).

…ws prune for PR unslothai#7228

The update-path CPU preservation only matched install_kind ending in -cpu, so
arm64 CPU bundles (linux-arm64, windows-arm64) were re-routed to a GPU or source
build on update. Match the full set of CPU-only kinds instead.

Persisting install_kind also activated the previously inert Windows
mismatch-prune in setup.ps1: on a GPU host with UNSLOTH_LLAMA_CPP_BACKEND=cpu it
saw the windows-cpu marker as mismatched and deleted it every rerun. Normalize
the override once and make CPU expected so a deliberate CPU install is kept.
Extend the tests to cover both.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff226d462c

ℹ️ 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".

repo = marker.get("published_repo") or DEFAULT_PUBLISHED_REPO
from_tag = marker.get("tag") or marker.get("release_tag")
asset = marker.get("asset")
install_kind = marker.get("install_kind")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve CPU fallback for legacy prebuilt markers

Pre-existing CPU installs have no install_kind, so this reads None and the updater omits --cpu-fallback. This is not automatically repaired by rerunning setup: existing_install_matches_choice() still accepts the old marker because it does not require the newly added field, so it skips rewriting it. Consequently, an Intel-GPU user with an older CPU bundle (including one who now sets the new environment variable) can accept an in-app update and be routed back to the Vulkan bundle that this override is meant to avoid. Infer the CPU kind from the existing asset or force a metadata refresh when the field is absent.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is intentional, so I am leaving it as install_kind-only. A legacy marker with no install_kind is deliberately allowed to heal to a GPU bundle on update, which is the existing behavior from #6097 (test_install_cmd_ggml_cpu_marker_has_no_cpu_fallback asserts the updater must not add --cpu-fallback for a legacy CPU marker, since it force-drops GPU detection).

The crash path described is not reachable: before this PR there was no way to force CPU on an Intel x86_64 host (that is the premise of #7213), so an Intel GPU host carries a linux-vulkan marker, not a CPU one. The only legacy CPU-asset markers that reroute on update are the arm64 source-build rescue (linux-arm64), where healing to the now-available GPU prebuilt is the intended outcome. Inferring CPU from the asset there would pin the host to CPU and block that heal, which is a worse regression than the hypothetical it avoids.

The env-var user is already covered: setting UNSLOTH_LLAMA_CPP_BACKEND=cpu and re-running setup installs a CPU bundle whose new marker records install_kind=linux-cpu, which the updater preserves. On the existing_install_matches_choice skip you note: release_tag is part of the install fingerprint, so any out-of-date legacy install reinstalls and records install_kind anyway; the residual skip is a pre-existing property, not introduced here. Documented the boundary with a comment and a regression case in f718576.

…nslothai#7228

Legacy prebuilt markers written before install_kind was persisted intentionally
do not force --cpu-fallback on update: the in-app updater lets them re-resolve
(heal to a GPU bundle) per the existing behavior from unslothai#6097, and only markers
that explicitly record a CPU install_kind are pinned to CPU. Add a comment and a
regression case documenting the boundary.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: f718576791

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: a4fea9bc14

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

Thanks!

…nslothai#7228

Persisting install_kind activated the setup.ps1 mismatch-prune, whose
expectedKinds was incomplete: the non-NVIDIA/non-AMD branch omitted
windows-vulkan (the Intel auto-route) and the GPU branches omitted the
windows-cpu/windows-arm64 fallback the installer uses when a GPU prebuilt is
missing. That made every setup rerun delete and re-download a valid Intel Vulkan
(or CPU-fallback) install. List all kinds the installer can produce per host so
only a bundle the host cannot run is pruned. Cover the full matrix in tests.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70d89c33a2

ℹ️ 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".

Comment on lines +535 to +536
if install_kind in _CPU_INSTALL_KINDS:
cmd.append("--cpu-fallback")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve only explicitly forced CPU installs

When a CPU bundle was installed as the normal fallback (for example, an Intel host when the upstream Vulkan asset was temporarily absent) or after a user later removes UNSLOTH_LLAMA_CPP_BACKEND=cpu, its marker is indistinguishable from an explicitly forced CPU install. This appends --cpu-fallback on every future update, preventing hardware detection from ever selecting a newly available Vulkan/GPU bundle. Record whether the CPU override was explicitly requested (or consult the current environment) instead of inferring that intent from install_kind.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Reworked this to record an explicit force_cpu flag instead of inferring intent from install_kind. write_prebuilt_metadata now persists force_cpu (True only when --cpu-fallback was passed), and start_update re-asserts --cpu-fallback on update only when force_cpu is True. A CPU bundle installed as the normal fallback records force_cpu False and stays free to heal to a Vulkan/GPU bundle later, and dropping UNSLOTH_LLAMA_CPP_BACKEND=cpu no longer sticks.

Comment thread studio/setup.ps1 Outdated
# adds windows-vulkan (the Intel auto-route). Only a bundle this host
# cannot run (e.g. windows-cuda with no NVIDIA) is pruned;
# UNSLOTH_LLAMA_CPP_BACKEND=cpu narrows expected to CPU to replace a GPU one.
$expectedKinds = if ($llamaBackend -eq "cpu") { @("windows-cpu", "windows-arm64") } elseif ($HasROCm -or $script:ROCmGfxArch) { @("windows-rocm", "windows-hip", "windows-cpu", "windows-arm64") } elseif ($HasNvidiaSmi) { @("windows-cuda", "windows-cpu", "windows-arm64") } else { @("windows-vulkan", "windows-cpu", "windows-arm64") }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep force-Vulkan installs in the expected kind set

On a Windows NVIDIA or ROCm host that intentionally uses the existing UNSLOTH_FORCE_VULKAN override, the installer still resolves a windows-vulkan bundle, but this list labels the current Vulkan install as mismatched and deletes it before attempting the replacement. If the subsequent download or validation fails, rerunning setup has destroyed the working forced-Vulkan backend; include Vulkan when that override is active (or defer removal until a staged replacement succeeds).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Instead of widening expectedKinds, I dropped the install_kind marker entirely, so the setup.ps1 prune stays inert exactly as #6097 left it: install_kind is never persisted, so $existingKind is always null and nothing is ever removed. A forced-Vulkan install via UNSLOTH_FORCE_VULKAN on an NVIDIA/ROCm host is therefore never deleted before its replacement lands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 583649970a

ℹ️ 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".

Comment thread studio/install_llama_prebuilt.py Outdated
Comment on lines +6478 to +6481
# Whether CPU was explicitly forced (--cpu-fallback). The updater re-asserts it
# so a deliberate CPU install is not re-routed to a GPU bundle (#7213); a natural
# CPU fallback stays False so it can still heal to GPU.
"force_cpu": force_cpu,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist forced CPU intent when reusing a CPU bundle

When a user enables UNSLOTH_LLAMA_CPP_BACKEND=cpu after an up-to-date CPU bundle was installed naturally, the resolved asset is unchanged, so existing_install_matches_plan() returns early before this metadata write. Its existing force_cpu: false remains unchanged; consequently the in-app updater will not re-add --cpu-fallback and can route that explicitly requested CPU install back to Vulkan/GPU on its next update. Treat a forced invocation as a metadata change even when the bundle itself is reusable (or make the match check include force_cpu).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed. Added sync_marker_force_cpu: when the resolved bundle is unchanged and install_prebuilt skips the reinstall, it now rewrites just the force_cpu flag of the existing marker to match the current invocation. So enabling UNSLOTH_LLAMA_CPP_BACKEND=cpu (which passes --force-cpu) on top of a naturally-installed CPU bundle records force_cpu:true even though the asset is identical, and the updater re-asserts --force-cpu on the next update. Added unit tests for the flip (false/absent to true), the no-op when already in sync, and a missing marker.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 583649970a

ℹ️ 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".

# Whether CPU was explicitly forced (--cpu-fallback). The updater re-asserts it
# so a deliberate CPU install is not re-routed to a GPU bundle (#7213); a natural
# CPU fallback stays False so it can still heal to GPU.
"force_cpu": force_cpu,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not persist automatic arm64 CPU fallback

setup.sh already invokes this installer with --cpu-fallback as an automatic last resort after an arm64 Linux GPU source build fails (around setup.sh:1911). That recovery path now writes force_cpu: true, so start_update() will subsequently re-append --cpu-fallback and permanently keep the CPU bundle even if a compatible GPU prebuilt later becomes available. This conflicts with the intended behavior for natural fallbacks described in the updater comments; distinguish the setup recovery path from a user-requested CPU override before persisting this flag.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed. Split the two callers: --cpu-fallback stays automatic and transient (drops GPU detection, does NOT persist), and a new --force-cpu is the deliberate CPU-only choice (drops GPU AND records force_cpu). The arm64 GPU-build recovery in setup.sh keeps --cpu-fallback, so its marker stays force_cpu:false and a later update still heals to a GPU bundle (#6097). UNSLOTH_LLAMA_CPP_BACKEND=cpu and the updater re-assert now use --force-cpu. Added a CLI-wiring test and a setup.sh regression test that the arm64 recovery never uses --force-cpu.

Comment thread studio/setup.sh
Comment on lines +1368 to +1369
_llama_backend="$(printf '%s' "${UNSLOTH_LLAMA_CPP_BACKEND:-auto}" | awk '{$1=$1; print tolower($0)}')"
case "$_llama_backend" in

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject or implement the CPU override on macOS

When this variable is set on macOS, this code still appends --cpu-fallback, but the installer has no macOS CPU asset path: _apply_host_overrides() only clears NVIDIA/ROCm/Intel attributes, and the resolver unconditionally selects the macOS bundle based on host.is_macos. Consequently, macOS users who set the documented cpu backend continue to receive the same Metal-enabled prebuilt rather than a CPU-only backend. Warn that the override is unsupported on macOS or add a genuine CPU selection path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. setup.sh now warns on macOS (Darwin) that UNSLOTH_LLAMA_CPP_BACKEND=cpu has no effect (the universal macOS bundle already runs on CPU; Metal offload is a runtime -ngl choice, and there is no separate CPU-only macOS asset) and skips the flag rather than writing a misleading forced-CPU marker. Added a test covering the Darwin branch (warns, no flag appended).

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 9c4c212895

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ff1e0c1f6

ℹ️ 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".

Comment on lines +7149 to +7150
# Persist only the deliberate choice, not a transient fallback.
force_cpu = persist_force_cpu,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update validator test doubles for the new keyword

The new unconditional force_cpu keyword breaks the existing installer tests that monkeypatch validate_prebuilt_attempts (for example, tests/studio/install/test_install_llama_prebuilt_logic.py::test_install_prebuilt_falls_back_to_older_release_plan), because their fakes do not accept it. Running the installer test suite now produces TypeError: ... got an unexpected keyword argument 'force_cpu' in four tests, so CI will fail until those fakes are updated (and the fake validate_prebuilt_choice signatures likewise accept the forwarded keyword).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed. The force_cpu keyword forwarded into validate_prebuilt_attempts (and on to validate_prebuilt_choice) broke four fakes in tests/studio/install/test_install_llama_prebuilt_logic.py that pin explicit signatures. Added force_cpu=False to the three fake_validate (attempts) doubles and to fake_validate_choice so they match the real signatures. All 1051 tests in tests/studio/install/ pass again.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 2457f453b0

ℹ️ 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".

@danielhanchen
danielhanchen merged commit cf912cb into unslothai:main Jul 20, 2026
1 check passed
@danielhanchen

Copy link
Copy Markdown
Member

Thanks!

@VectorCipher
VectorCipher deleted the fix/7213-vulkan-only-built-error branch July 20, 2026 11:42
VectorCipher added a commit to VectorCipher/unsloth that referenced this pull request Jul 20, 2026
…back unslothai#7213 (unslothai#7228)

* test(studio): add e2e test for cpu-fallback overriding vulkan

* feat(studio): add UNSLOTH_LLAMA_CPP_BACKEND env var

* feat(studio): add UNSLOTH_LLAMA_CPP_BACKEND env var

* Preserve UNSLOTH_LLAMA_CPP_BACKEND=cpu across llama.cpp updates for PR unslothai#7228

The in-app updater rebuilt the installer command without --cpu-fallback and
only re-asserted Vulkan, so accepting a llama.cpp update after forcing CPU on
an Intel iGPU host re-ran host detection and routed back to the crashing Vulkan
bundle (unslothai#7213). Record install_kind in the prebuilt marker and re-assert
--cpu-fallback on update when the installed bundle is CPU.

Also make setup.sh's UNSLOTH_LLAMA_CPP_BACKEND check case-insensitive to match
setup.ps1, and add tests for the updater CPU preservation and the setup.sh flag
plumbing.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Trim and validate UNSLOTH_LLAMA_CPP_BACKEND, warn on unknown values for PR unslothai#7228

Trim surrounding whitespace and lowercase the value in both setup.sh and
setup.ps1, so values like ' cpu ' or 'CPU' still force the CPU-only prebuilt.
An unrecognized value (e.g. 'gpu') now prints a warning instead of silently
falling back to auto. Extend test_setup_llama_cpp_backend.py to cover both
scripts, including trimmed, empty and unknown values.

* Preserve arm64 CPU installs on update and honor CPU override in Windows prune for PR unslothai#7228

The update-path CPU preservation only matched install_kind ending in -cpu, so
arm64 CPU bundles (linux-arm64, windows-arm64) were re-routed to a GPU or source
build on update. Match the full set of CPU-only kinds instead.

Persisting install_kind also activated the previously inert Windows
mismatch-prune in setup.ps1: on a GPU host with UNSLOTH_LLAMA_CPP_BACKEND=cpu it
saw the windows-cpu marker as mismatched and deleted it every rerun. Normalize
the override once and make CPU expected so a deliberate CPU install is kept.
Extend the tests to cover both.

* Document legacy llama.cpp markers keep heal-to-GPU on update for PR unslothai#7228

Legacy prebuilt markers written before install_kind was persisted intentionally
do not force --cpu-fallback on update: the in-app updater lets them re-resolve
(heal to a GPU bundle) per the existing behavior from unslothai#6097, and only markers
that explicitly record a CPU install_kind are pinned to CPU. Add a comment and a
regression case documenting the boundary.

* Tighten llama.cpp CPU-fallback comments for PR unslothai#7228

* Fix Windows install-prune to keep valid Intel/fallback bundles for PR unslothai#7228

Persisting install_kind activated the setup.ps1 mismatch-prune, whose
expectedKinds was incomplete: the non-NVIDIA/non-AMD branch omitted
windows-vulkan (the Intel auto-route) and the GPU branches omitted the
windows-cpu/windows-arm64 fallback the installer uses when a GPU prebuilt is
missing. That made every setup rerun delete and re-download a valid Intel Vulkan
(or CPU-fallback) install. List all kinds the installer can produce per host so
only a bundle the host cannot run is pruned. Cover the full matrix in tests.

* Persist force_cpu marker flag so only forced CPU installs re-assert on update for PR unslothai#7228

* Add --force-cpu for deliberate CPU installs and warn on macOS for PR unslothai#7228

* Record force_cpu when reusing a matching CPU bundle for PR unslothai#7228

* Accept force_cpu keyword in installer test validator fakes for PR unslothai#7228

---------

Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
danielhanchen pushed a commit that referenced this pull request Jul 22, 2026
Carry the force_cpu preservation from #7228 into the chained update:
_run_llama_phase gains the force_cpu parameter, the llama phase spec
records it from the install marker, and the phase lambda forwards it so
a deliberate CPU install stays CPU across chained updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants