Repository navigation
installer: add pipe-safe --cpu / --vulkan flags for the llama.cpp backend (#7213) - #7675
LeoBorcherding wants to merge 3 commits into
Conversation
…kend (unslothai#7213) UNSLOTH_LLAMA_CPP_BACKEND=cpu placed before `curl ... | sh` binds the var to curl, not the piped sh, so setup.sh never sees it and installs the auto-detected backend (Vulkan on an Intel/other iGPU, which crashed the reporter). Add --cpu / --vulkan flags to install.sh and install.ps1 that export the env var setup.sh already reads, so `| sh -s -- --cpu` works, forward it across the WSL reroute, and document the correct post-pipe env form. No selection-logic change.
|
@codex review |
|
Overall this is a clean, well-scoped fix and the root cause (the 1. (medium) install.ps1 leaks
|
…leak into the iex session Set the flag-derived backend only around the setup.ps1 invocation with save/restore, mirroring UNSLOTH_STUDIO_HOME / UNSLOTH_LOCAL_LLAMA_CPP_DIR, so `irm | iex` doesn't leave $env:UNSLOTH_LLAMA_CPP_BACKEND set in the caller's session and a later same-session install can't silently reuse it. Pin the cleanup in the wiring test and loosen the whitespace-exact ps1 assertions.
🌊 Poseidon Review 🐚Reviewed Two findings remain open, both at P2/P3. The misleading comment at install.sh:16 (raised by all 40 earlier runs) is still unchanged, and the env-var leak in install.ps1 on early --with-llama-cpp-dir failure is still structurally present. Neither is a blocking issue for ROCm specifically, but the comment one is the higher-value fix since it directly undermines the point of the PR. P2 - Rewrite the anti-example comment so it does not read as the correct form Line 16 reads # Placing the env var before `curl` (`UNSLOTH_LLAMA_CPP_BACKEND=cpu curl ... | sh`)
# binds it to curl, not the piped sh, so the installer never sees it (#7213).
# Use the form above (env var after the pipe) or `sh -s -- --cpu`.P3 - Env var leaks when --with-llama-cpp-dir validation fails early
Move lines 2805-2807 (the save/set block) into the |
|
@LeoBorcherding I think your implementation is correct and good to merge, but I don't think we should add new flags for this as for Linux/macOS/WSL, or already work. Maybe we should just document this in the README somewhere visible/convenient. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37851175d7
ℹ️ 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".
| # an inherited value for this run. | ||
| $previousLlamaBackend = $env:UNSLOTH_LLAMA_CPP_BACKEND | ||
| $hadPreviousLlamaBackend = ($null -ne $previousLlamaBackend) | ||
| if ($LlamaCppBackendFlag) { $env:UNSLOTH_LLAMA_CPP_BACKEND = $LlamaCppBackendFlag } |
There was a problem hiding this comment.
Move backend override under the setup try/finally
When --cpu or --vulkan is combined with --with-llama-cpp-dir pointing at a missing directory, this line sets the process-scoped UNSLOTH_LLAMA_CPP_BACKEND before the later path validation calls Exit-InstallFailure, so the restore block in the finally is never entered. In the documented irm | iex / scriptblock path that runs in the caller's PowerShell session, the backend override is left behind and can affect subsequent commands or installs; validate the path before setting this env var, or include the validation inside the same try/finally.
Useful? React with 👍 / 👎.
|
Closing this. ooba's call was right, and the ground moved under it since. UNSLOTH_LLAMA_CPP_BACKEND already covers the case: it landed in #7228 the day after #7213 was filed. The bug turned out to be the variable sitting before curl instead of after the pipe, not a selection bug, and the reporter confirmed the post-pipe form works. Since then main documents the variable in the README under "Vulkan, custom llama.cpp backends", and #8520 made the backend switchable from the UI. Two installer flags are a third spelling of a knob that already has two. Merging current main and taking the flags back out leaves a zero-line diff, so there is nothing here worth carrying forward. The one thing still undocumented is the broken form itself, UNSLOTH_LLAMA_CPP_BACKEND=cpu curl ... | sh, which binds to curl and silently auto-detects. That is a few lines and belongs in the next README pass, not in a PR of its own. |
Problem
Forcing the CPU llama.cpp build doesn't work through the documented pipe:
The
VAR=xprefix binds tocurl, not theshon the other side of the pipe, sosetup.shreads the backend as unset, auto-detects the reporter's Intel iGPU, andinstalls the Vulkan prebuilt (their
UNSLOTH_PREBUILT_INFO.json:force_cpu: false,a vulkan asset). The selection logic is correct: when the var actually reaches the
environment,
setup.shforwards--force-cpuand the install honours it. It justnever arrives.
install.shalready documents this same pipe footgun for--no-torchand solves it with a flag; there was none for the backend.
Fix
Add
--cpu/--vulkanflags toinstall.shandinstall.ps1, mirroring--no-torch, that exportUNSLOTH_LLAMA_CPP_BACKENDso it survives the pipe:Also forwarded across the WSL reroute, and the header now shows the correct
post-pipe env form. No change to backend selection, prebuilt resolution, or setup.
An explicit flag wins over an inherited env var, matching the other flags.
Tests
New
tests/sh/test_llama_backend_flag.sh(11 checks) pins the flag to env-varwiring in both installers and the WSL forward; existing
test_install_pipe_safety.shand
test_with_llama_cpp_dir_flag.shstill pass; both installers parse clean.Not verified end to end (no Intel-iGPU host here). The reporter can confirm with
... | sh -s -- --cpu, then checkforce_cpu: trueand a cpu asset in the marker.