Skip to content

Source llama.cpp prebuilts from unslothai/llama.cpp (CUDA, ROCm, macOS) - #5963

Merged
danielhanchen merged 37 commits into
unslothai:mainfrom
oobabooga:llama-prebuilt-multiplatform
Jun 10, 2026
Merged

danielhanchen merged 37 commits into
unslothai:mainfrom
oobabooga:llama-prebuilt-multiplatform

Conversation

@oobabooga

@oobabooga oobabooga commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

This PR wires the new prebuilts that will be generated by unslothai/llama.cpp#17 to the installer here. I'll mark it as a draft until that PR gets merged.

New platforms

New = not previously provided by unslothai/llama.cpp:

  • CUDA Windows
  • CUDA Linux arm64 (e.g. DGX Spark)
  • ROCm Linux + Windows
  • macOS (x86_64 + arm64)

How bundles are selected

  • CUDA prebuilts are segmented by architecture, and detected by reading the host GPU's compute capability and picking the bundle built to cover it. Each CUDA major (12 and 13) has a few variants by architecture range plus a portable catch-all; the installer takes the tightest one that covers the GPU, or the portable build if none do.
  • ROCm is matched on the host's exact gfx arch (gfx1100, gfx1151, ...).
  • macOS is matched on CPU arch.

Anything not covered falls back to a source build, same as today.

Which repo the installer pulls from is decided in the setup scripts: setup.sh (Linux/macOS) and setup.ps1 (Windows) point GPU hosts at the fork and keep CPU-only on ggml-org.

I also moved all of unslothai/llama.cpp onto the manifest. linux-x64 used to take a separate filename-based path with hardcoded coverage tables; I removed it so the fork selects every platform from the manifest, one source of truth. ggml-org still selects by filename since it ships no manifest. This is most of the deleted lines in the diff.

Testing

I tested the full path with a real install on a linux-x64 CUDA box, which pulled and ran b9457 from the release. The per-host bundle selection for every platform is covered by unit tests against the real b9457 manifest.

@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 expands prebuilt support by integrating ROCm (Linux and Windows) and ARM64 CUDA bundles, routing GPU-enabled hosts to the fork's repository while keeping CPU-only hosts on the upstream repository. It unifies the installation planning under a single resolver that delegates to a manifest-reading branch for complex architectures (ARM64 CUDA, Windows CUDA, per-gfx ROCm, macOS) and a fast filename-based path for Linux x64. Additionally, Windows CUDA selection is updated to support app-named bundles, SM-filtering, and relaxed driver version constraints for CUDA 12. Feedback on the changes suggests stripping leading and trailing whitespace from mapped_targets when parsing them from the manifest to ensure robust matching.

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/install_llama_prebuilt.py Resolved
@oobabooga
oobabooga marked this pull request as draft June 3, 2026 00:44
@oobabooga

Copy link
Copy Markdown
Member Author

/gemini review

@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 refactors and unifies the prebuilt installation logic for llama.cpp across Linux, Windows, and macOS, removing the legacy --simple-policy flag and introducing a unified manifest-aware resolver for fork bundles. It adds support for arm64 CUDA, Windows CUDA, per-gfx ROCm, and macOS bundles, matching ROCm bundles by the host's detected gfx family. Feedback on the changes highlights a potential sorting issue in published_windows_cuda_attempts where legacy bundles lacking SM metadata could evaluate to a range of 0 and incorrectly outrank valid targeted bundles; a defensive fallback range is suggested to resolve this.

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/install_llama_prebuilt.py Resolved
@oobabooga
oobabooga marked this pull request as ready for review June 9, 2026 04:14
@danielhanchen

Copy link
Copy Markdown
Member

Pushed 72f3236 to this branch: it fixes Windows AMD hosts never reaching the lemonade prebuilt.

The fork release scan pins llama_tag to each scanned release's upstream tag (b9518, ...), and the lemonade lookup then fetches that exact tag at lemonade-sdk/llamacpp-rocm. Lemonade publishes its own tag series (b1292, ...) that never contains upstream tag numbers, so every scanned release 404s the lemonade fetch twice, the upstream win-hip zip gets dropped by the approved-hash gate, and the scan walks the entire release history until it aborts on the unauthenticated GitHub rate limit (or falls to a HIP source build). Repro on a gfx1151 box:

python studio/install_llama_prebuilt.py --published-repo unslothai/llama.cpp --rocm-gfx gfx1151 --install-dir <scratch>

The Linux attempt builder already passes the requested tag ("latest") to lemonade, which is why the Linux path works. The commit threads the requested tag through resolve_release_asset_choice -> resolve_asset_choice -> resolve_upstream_asset_choice as lemonade_tag, consumed only by the lemonade lookups. Upstream asset names keep the concrete per-release tag and every new parameter defaults to the old behavior, so CUDA, macOS, CPU and the ggml-org direct path are untouched.

Verified on the same box after the fix: native Windows selects llama-b1292-windows-rocm-gfx1151-x64.zip (lemonade) from fork release b9518, staged validation passes, and the installed llama-server enumerates ROCm0: AMD Radeon(TM) 8060S Graphics. WSL Ubuntu 24.04 keeps selecting the matching ubuntu bundle. The four selection suites pass on Linux (327 passed) including a new regression test that pins the lemonade lookup to /releases/latest.

One thing for a possible follow-up: a planning failure still lets the scanner spend around 40 unauthenticated API calls walking old releases. Capping scan iterations or treating a 403 as PrebuiltFallback would soften that failure mode.

@danielhanchen

Copy link
Copy Markdown
Member

Item 1 above (the fork-path Windows CUDA hash mismatch) now has a workflow-side fix: unslothai/llama.cpp#20 records the upstream win-cuda binary digests under their own asset names in the sha256 index. Since the installer checks the exact asset name before the cudart alias, no installer change is needed here - the alias stays as a backstop for older manifests. Verified against the live b9518 assets (binary 52e8dddb vs cudart 8c79a9b2, and the 13.3 entry now present). It is stacked on #17 and mergeable immediately after it.

…nslothai#5963

Audit follow-up to 72f3236 across the other selection pathways. The
ggml-org direct planner kept its lemonade attempt for Windows ROCm
hosts but planned only the CPU tarball for Linux ROCm hosts, so an AMD
Linux box routed to ggml-org (for example a --published-repo override)
silently installed the CPU build. That lemonade planning used to live
in the --simple-policy dispatcher this PR removed.

Add the lemonade attempt ahead of the CPU tarball in the Linux x86_64
branch, mirroring the Windows branch, with the lookup keyed to the
requested tag. Adds a regression test asserting lemonade is the first
attempt for a Linux ROCm host on the direct path.

Also re-verified the other pathways on a gfx1151 box: the fork-routed
flows pass the requested tag everywhere, repeat runs over an existing
lemonade install correctly skip with "already matches selected release
b9518" on both native Windows and WSL, and macOS, CUDA and CPU
selection are untouched. Suites: 328 passed on Linux, Windows matches
the pre-existing baseline.
@danielhanchen

Copy link
Copy Markdown
Member

Audited the remaining selection pathways for the same class of issue and pushed one more commit (457c51b).

The ggml-org direct planner kept its lemonade attempt for Windows ROCm hosts but planned only the CPU tarball for Linux ROCm hosts, so an AMD Linux box routed to ggml-org (for example a --published-repo override) silently installed the CPU build. That planning used to live in the --simple-policy dispatcher this PR removes. The commit adds the lemonade attempt ahead of the CPU tarball in the Linux x86_64 branch, mirroring the Windows branch, plus a regression test that lemonade is the first attempt there.

Everything else checked out clean:

  • All lemonade call sites now key off the requested tag; the fork-routed Linux and Windows flows and the ggml-org direct flows are consistent.
  • --llama-tag stays "latest" through planning (no premature resolution), and an explicit user pin keeps the documented skip-lemonade semantics.
  • Repeat runs over an existing lemonade install correctly log "existing llama.cpp install already matches selected release b9518" and skip, on both native Windows and WSL, so there is no reinstall loop.
  • macOS, CUDA and CPU selection are untouched; suites pass on Linux (328 passed) and Windows matches the pre-existing baseline (only the bash-spawning and symlink-layout tests that cannot run on Windows).

@danielhanchen

danielhanchen commented Jun 10, 2026 •

Copy link
Copy Markdown
Member

Tested end-to-end on N1X "RTX Spark" hardware (Windows-on-ARM -> WSL2 Ubuntu 24.04, Blackwell sm_121, driver CUDA 13.1):

The fork-manifest path works for arm64 CUDA on this machine. Host detection got everything right (compute_caps=121, driver_cuda_version=(13, 1), has_usable_nvidia=True). Driving the full install flow against a release carrying the new linux-arm64-cuda bundle (b9571, built by unslothai/llama.cpp#17's pipeline): it selected app-b9571-linux-arm64-cuda13-portable.tar.gz via the manifest (SM + runtime-line matching), sha256-verified the bundle and the hydrated source tree, passed the staged stories260K validation, and activated the canonical build/bin/llama-server layout. Serving Qwen3-0.6B from the installed tree: 215.4 tok/s, GPU 65% peak / 12.2 GB.

Today's behavior (no arm64 asset in unslothai releases yet) is the correct graceful fallback: prebuilt fallback reason: no compatible Linux prebuilt asset was found -> source build, identical to current main.

Two small notes, neither blocking:

  1. resolve_simple_install_release_plans routes to the manifest planner only when repo == DEFAULT_PUBLISHED_REPO. Any --published-repo override goes down the ggml-org filename planner, which has no Linux+NVIDIA branch - so a repo that ships perfectly good manifest bundles fails with a misleading no compatible upstream prebuilt asset was found (this is how I had to test pre-publish: monkeypatching DEFAULT_PUBLISHED_REPO). Routing by manifest presence in the release (the manifest fetch already happens) would let --published-repo testing - and any future mirror knob - work for manifest-style bundles.
  2. --cpu-fallback's help text "(no arm64 CUDA prebuilt exists anywhere)" goes stale the moment full context lora Yi-34B with 24GB #17 publishes the arm64 bundle to this repo's releases.

@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: ed33286f9f

ℹ️ 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
# not usability: an unusable NVIDIA host has a good CPU prebuilt to fall back to,
# whereas tightening AMD would regress ROCm hosts exposing only hipconfig/hipinfo
# into an unnecessary CPU build.
if [ "$_setup_nvidia_usable" = true ] && [ "${CUDA_VISIBLE_DEVICES:-}" != "-1" ]; then

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 Treat empty CUDA_VISIBLE_DEVICES as hidden

After the visibility fix, this shell probe still only excludes CUDA_VISIBLE_DEVICES=-1; when users hide GPUs with CUDA_VISIBLE_DEVICES= (empty), install_llama_prebuilt.py treats that as no usable NVIDIA device, but setup.sh routes to unslothai/llama.cpp anyway. On CPU-only/hidden-GPU Linux hosts the fork has no CPU bundle, so these installs fall back to a source build instead of using the ggml CPU prebuilt; handle the set-but-empty value the same way as -1.

Useful? React with 👍 / 👎.

Brings the Playwright chat UI driver fix (unslothai#6153) that follows Compare
chat into the More submenu; the previous merge predated it, which is
why Chat UI Tests failed on this branch with 'Compare chat item not
found'.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed 9979b2e: merged main again to pick up the Playwright driver fix from #6153 (follow Compare chat into the More submenu). The previous merge predated it, which is why Chat UI Tests failed on this branch with "Compare chat item not found" - that was the only genuinely red check left after the rebase; the earlier Chat UI / Studio Updating failures were HF 429 rate limits on the validation-model fetch, which main's huggingface_hub download path now mitigates.

Status of the audit items on this branch after the merges: the setup.ps1 ownership guard is back in place (test_studio_install_workspace_guard passes, 44/44), and the updater concern is moot - the in-app updater was refactored into the read-only llama_cpp_freshness staleness check, so nothing re-runs the installer without the detected gfx anymore. The Blackwell cuda-12.4 exclusion and the NVIDIA linux-cpu gate landed as #6156 against main; whichever of that PR and this one merges second will want a trivial reconcile in install_llama_prebuilt.py and test_selection_logic.py.

shimmyshimmer and others added 2 commits June 10, 2026 15:47
…ackwell/CPU hardening)

# Conflicts:
#	studio/install_llama_prebuilt.py
#	tests/studio/install/test_selection_logic.py
@danielhanchen
danielhanchen merged commit cc1a724 into unslothai:main Jun 10, 2026
30 of 34 checks passed
danielhanchen pushed a commit that referenced this pull request Jun 10, 2026
Resolve conflicts from the #5963 installer rework:
- main.py: keep both the routes.llama and hub.* router imports/registrations
- provider.tsx: keep main's DownloadManagerPanel/TooltipProvider alongside the
  LlamaUpdateBanner, and mount the banner on the macOS desktop (native titlebar)
  path so macOS users get the in-app update
- test_desktop_auth.py: union the routes.llama and routes.prompts stub modules
danielhanchen pushed a commit that referenced this pull request Jun 10, 2026
…ller

Re-run install_llama_prebuilt.py the way setup.sh/setup.ps1 now do, and harden
the update flow against the edge cases raised in review.

Installer invocation (utils/llama_cpp_update.py):
- Forward the AMD gfx target the same way setup does. The install marker's asset
  name carries the gfx family for lemonade HIP bundles, so derive --rocm-gfx
  (or --has-rocm for the fork ROCm-version bundles) from it; without this, the
  update could mis-plan a non-HIP asset on amd-smi-only / name-inferred hosts.
- Do not pass --cpu-fallback: setup only uses it for the arm64 source-build
  rescue, and it force-drops GPU detection; re-running into the same install-dir
  and published-repo already reproduces the right CPU bundle.
- No --simple-policy (removed from setup by #5963; the default policy scans the
  published repo).

Update safety:
- Put the backend into a maintenance state for the install window: set a flag
  under the serial load lock and unload whenever a server process exists
  (is_active, not just is_loaded). load_model() rejects fast while the flag is
  set so no server starts from a half-swapped binary; the flag clears in a
  finally. Fails open when the backend is unavailable.
- Frontend hook: handle a 200 response that did not start a job (no marker /
  installer missing) by surfacing the reason instead of polling forever, and
  track an externally started job to completion so the banner does not stick on
  Updating. Shared poll helper used by both paths.

Tests: rocm-gfx / has-rocm derivation, ggml-org CPU marker has no --cpu-fallback,
no --simple-policy, backward-compatible marker without an asset field, refusal
paths, and the maintenance-flag set/clear plus fail-open coverage.
danielhanchen added a commit that referenced this pull request Jun 10, 2026
…#6097)

Adds an in-app "Update llama.cpp" banner and button to Unsloth Studio. When the installed prebuilt is behind the latest published release, a non-invasive banner appears; clicking Update downloads the latest prebuilt for this host and swaps it in place in the background, with no restart.

Detection reuses the freshness check from #5529. The update re-runs install_llama_prebuilt.py the same way setup.sh and setup.ps1 do after #5963: it forwards the published repo and the AMD gfx target derived from the install marker, and does not pass the removed --simple-policy or the arm64-only --cpu-fallback.

While the installer swaps binaries the backend enters a maintenance state (flag set under the serial load lock, active server unloaded) so a concurrent load cannot start a server from a half-swapped binary; the next load uses the new build. The banner also handles refused responses and jobs started in another tab so it never sticks on "Updating...".

Verified end to end on an NVIDIA B200: installed b9493, detected the update, applied it, and confirmed the binary at the same path advanced to b9585 in the same process. Hermetic backend tests and the frontend type-check pass.
danielhanchen added a commit that referenced this pull request Jun 11, 2026
…prebuilt step (#6189)

#5963 folded the manifest resolver into the simple-path resolver,
removed the installer's --simple-policy flag, and moved macOS prebuilts
to the unslothai/llama.cpp fork. The MLX CI prebuilt step still passed
the deleted flag, so argparse exits 2 and the workflow has been red on
every main push since. Point the step at the fork with no extra flags,
exactly like studio/setup.sh on macOS.
LeoBorcherding added a commit that referenced this pull request Nov 12, 2026
…ause the CUDA bundles ship no cudart/cublas (#17463)

Chat-only (no-torch) installs with an NVIDIA GPU run llama.cpp on the
CPU. Reported in the Discord help thread: a 5070 Ti on Windows (driver
591.86) got ~20 tok/s where LM Studio gets ~140, `llama-server
--list-devices` printed `(none)`, and the log showed `n_threads = 2` on
the CPU.

## Why

The `app-*` CUDA bundles Unsloth Studio installs since #5963 ship
`ggml-cuda.dll` but no `cudart`/`cublas`. A full install doesn't need
them: PyTorch already carries the CUDA runtime, and Unsloth Studio puts
it on llama-server's search path, which saves ~400-550 MB per bundle. A
chat-only install skips PyTorch, so there is nothing to borrow,
`ggml-cuda.dll` fails to load, and llama.cpp quietly falls back to the
CPU.

```
.unsloth/
├ llama.cpp/…/Release/          same in every case: ggml-cuda.dll, no cudart
└ studio/unsloth_studio/…/site-packages/
   ├ torch/lib/                 full install: cudart64_12.dll, cublas64_12.dll   → GPU
   ├ (nothing)                  chat-only today                                  → CPU
   └ nvidia/cu13/bin/           chat-only with this PR: cudart64_13.dll, …        → GPU
```

On Windows torch ships these DLLs inside its own wheel (`torch\lib`). On
Linux torch pulls NVIDIA's `nvidia-cuda-runtime` / `nvidia-cublas`
wheels into `site-packages/nvidia/`, which are the same wheels this PR
installs.

## Change

- **Linux, before bundle selection.** Selection only takes a CUDA bundle
whose runtime line is already on disk, so a driver-only host would skip
CUDA and fall back to a source build. On an x64 NVIDIA host with an
`auto`/`cuda` request and no runtime the driver can use, the installer
now installs the wheels for the newest line the driver runs first, then
selects. Pre-Turing GPUs get CUDA 12, and a CUDA 13 runtime already on
disk does not count for them.
- **After install, both OSes.** The install kind and CUDA major come
from the asset name, since the install marker records no install kind.
If the runtime is missing (Linux: `detected_linux_runtime_lines()`, the
same scan selection uses; Windows: `cudart`, `cublas` and `cublasLt` of
that major, each found in the bundle, `torch/lib`, the env's `nvidia/`
wheels, `CUDA_PATH` or the loader's own DLL dirs from
`windows_runtime_dirs()`, checked flat), it installs NVIDIA's wheels:
`nvidia-cuda-runtime` + `nvidia-cublas`, or the `-cu12` names with
cublas pinned to 12.9.2.10 on Windows, the last one with a `win_amd64`
wheel.
- **Repair.** `--check-installed` reports such an install as not ready,
so setup and update reinstall it and fill the gap on machines that are
already broken.
- `llama_cpp.py` already puts the env's `nvidia/*` wheel dirs on `PATH`
/ `LD_LIBRARY_PATH`, so it needs no change.

Full installs and machines with the CUDA toolkit download nothing new.
ARM64 bundles already ship the runtime and are untouched. This replaces
unslothai/llama.cpp#362, which put the runtime in every bundle (+373 to
+552 MiB each).

## Tests

`tests/studio/install/test_no_torch_cuda_runtime_wheels.py`, 30 passed
on macOS at `907e50f558` (code-level, the filesystem, loader and host
are faked). Not run yet on a real Windows or Linux NVIDIA machine with a
chat-only install.

---------

Co-authored-by: oobabooga <[email protected]>
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