Skip to content

Docker Studio: keep the base image's CUDA llama.cpp instead of the CPU prebuilt - #10495

Merged
danielhanchen merged 3 commits into
mainfrom
docker-arm64-studio-keep-cuda-llama
Sep 8, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
docker-arm64-studio-keep-cuda-llama

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The published unsloth/unsloth:latest / :studio images ship a CPU-only llama.cpp while :core ships the CUDA one. #10491 found it on a DGX Spark (arm64); this PR shows it is arch independent and the amd64 image has the same defect.

Mechanism: docker/Dockerfile.studio points Studio's llama.cpp directory at the base image's baked CUDA bundle (/opt/unsloth/llama.cpp, marker .unsloth-studio-owned) and then runs install.sh --local. No GPU is visible during the image build, so studio/setup.sh hands off to install_llama_prebuilt.py, whose host detection (nvidia-smi -L or /proc/driver/nvidia/gpus) finds nothing and resolves a CPU asset (linux-x64-cpu on amd64, linux-arm64 on arm64). That asset name does not match the installed CUDA bundle, so the installer replaces it. The Studio install layer of both published images carries whiteouts for opt/unsloth/llama.cpp/libggml-cuda.so and build/bin/libggml-cuda.so.

Confirmed on both architectures without a full pull, by streaming the Studio install layer from the registry:

arch layer whiteouts kept
arm64 sha256:7940d6e4... .wh.libggml-cuda.so (both paths) libggml-cpu-armv8*, armv9*
amd64 sha256:615f58a8... .wh.libggml-cuda.so (both paths) libggml-cpu-alderlake, zen4, sapphirerapids, ...

And on a B200 host with the local amd64 images:

unsloth/unsloth:latest  llama-server --list-devices  ->  Available devices: (none)
unsloth/unsloth:core    llama-server --list-devices  ->  CUDA0: NVIDIA B200 (182633 MiB, 147310 MiB free)

latest's marker reads bundle_profile: linux-cpu-x64, backend: cpu, asset: app-b10798-mix-659e406-linux-x64-cpu.tar.gz.

Change

  • studio/setup.sh: new _keep_installed_gpu_prebuilt() and an elif in the llama.cpp branch chain, placed after the local-dir, explicit-backend, force-compile and PR branches so none of them is hijacked. Gated on UNSLOTH_LLAMA_KEEP_PREBUILT=1|true|yes|on; keeps the installed bundle only when its marker records a GPU backend, the same fork and the same tag (the normalized base build, so b10840 matches b10840-mix-d5c17a0) and llama-server is present. A stale, CPU or foreign bundle is still replaced. The arm64 CPU last resort gets the same guard.
  • docker/Dockerfile.studio: passes UNSLOTH_LLAMA_KEEP_PREBUILT=1 into install.sh --local, then fails the build if libggml-cuda.so is missing from either path, printing the marker, mirroring the base Dockerfile's own check.
  • docker/unsloth_llama_update.sh and docker/fetch_llama_prebuilt.py already resolve the CUDA portable bundles per arch; unchanged.

Tests

  • New tests/studio/install/test_docker_studio_keep_cuda_prebuilt.py: 22 passed. Two pin the CPU resolution on both arches through the real selector; seventeen drive _keep_installed_gpu_prebuilt sliced out of the live setup.sh under a stub PATH (uname -m reports aarch64, nvidia-smi exits 9) against real marker files: keep for the base image's CUDA marker at the pinned tag, the base build and latest, the installer-written backend: cuda marker and ROCm; replace for the shipped backend: cpu marker, a CPU platform, force_cpu, a stale tag, another fork, no marker, broken JSON, no llama-server, knob unset or 0, and an explicit backend request. Three pin the wiring: branch ordering, the arm64 guard, the Dockerfile knob and assertion.
  • tests/studio/install: 3968 passed, 6 skipped. tests/python/test_docker_llama_prebuilt_probe.py: 5 passed. All 32 tests/sh scripts that read setup.sh exit 0. bash -n studio/setup.sh clean. docker buildx build --check -f Dockerfile.studio: no warnings.

A local amd64 Studio build at this head is running to confirm the assertion passes and llama-server --list-devices reports the GPU; the result will be posted here.

…U prebuilt

docker/Dockerfile.studio symlinks Studio's llama.cpp dir at the base image's baked CUDA bundle and then runs install.sh --local, but no GPU is visible during an image build, so studio/setup.sh hands install_llama_prebuilt.py a host with has_usable_nvidia=False and _linux_published_attempts() resolves the CPU bundle for the arch and installs it over the CUDA one. setup.sh now honours UNSLOTH_LLAMA_KEEP_PREBUILT=1 through a new _keep_installed_gpu_prebuilt(), which keeps an installed bundle whose UNSLOTH_PREBUILT_INFO.json records a GPU backend from the requested fork at the requested tag, and Dockerfile.studio sets that knob and then fails the build if /opt/unsloth/llama.cpp/libggml-cuda.so is gone after install.sh, mirroring the base Dockerfile's own unresolved-library guard. The knob is opt-in and every other path is untouched: an explicit UNSLOTH_LLAMA_CPP_BACKEND, UNSLOTH_LLAMA_PR, UNSLOTH_LLAMA_FORCE_COMPILE and --with-llama-cpp-dir are all decided before it, a stale tag, a different fork, a CPU or force_cpu marker and a tree with no llama-server are all still replaced, and the arm64 CPU last resort is additionally gated so it cannot undo a kept bundle.

Contrary to the report this is not arm64 only. Streaming the Studio install layer of the published unsloth/unsloth:latest straight from the registry shows the same whiteouts on both arches: opt/unsloth/llama.cpp/.wh.libggml-cuda.so and opt/unsloth/llama.cpp/build/bin/.wh.libggml-cuda.so appear in the arm64 child sha256:967df570 and in the amd64 child sha256:177bba4f alike, and the resolver run against the live b10840-mix-d5c17a0 manifest with no GPU picks app-...-linux-arm64-cpu.tar.gz on aarch64 and app-...-linux-x64-cpu.tar.gz on x86_64. The fix is therefore arch independent.

Verification without a GPU: the new tests/studio/install/test_docker_studio_keep_cuda_prebuilt.py adds 22 tests, two of which pin the CPU resolution on both arches through the real selector, seventeen drive setup.sh's keep decision out of the live script under a stubbed aarch64 PATH with a failing nvidia-smi against real base-image and installer-written markers, and three pin the wiring. tests/studio/install passes 3968 tests with 6 skips, tests/python/test_docker_llama_prebuilt_probe.py passes 5, all 32 tests/sh scripts that read setup.sh exit 0, bash -n studio/setup.sh is clean and docker buildx build --check on docker/Dockerfile.studio reports no warnings. docker/unsloth_llama_update.sh and docker/fetch_llama_prebuilt.py already agree on amd64 to linux-x64-cuda12-portable and arm64 to linux-arm64-cuda13-portable and needed no change; a full arm64 Studio image build is left to CI.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T12:38:46.965374Z 37f9e60 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security 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: df4311d93b

ℹ️ 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/setup.sh
recorded.discard("")
if not recorded:
raise SystemExit(1)
if requested and requested.lower() != "latest":

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 exact mix release pins

When UNSLOTH_LLAMA_TAG is pinned to a full release such as b10840-mix-new but the installed marker records b10840-mix-old, this condition accepts the install because both values collapse to b10840. Same-base mix releases are distinct artifact identities, so the keep branch skips the installer and the Docker assertion still passes as long as the old CUDA libraries exist, silently shipping a different release than requested. Require an exact release_tag match for full mix-release pins, reserving the normalized comparison for a bare bNNNN request; the keep decision should also honor an explicit UNSLOTH_LLAMA_RELEASE_TAG.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed. A full mix release pin now has to match the marker's release_tag exactly, an explicit UNSLOTH_LLAMA_RELEASE_TAG is honoured the same way, and the normalized comparison only applies to a bare bNNNN request.

@danielhanchen

Copy link
Copy Markdown
Member Author

Local amd64 Studio build at df4311d on top of unsloth/unsloth:core (B200 host):

llama.cpp      keeping the installed GPU prebuilt (UNSLOTH_LLAMA_KEEP_PREBUILT=1)
OK: Studio kept the base image's CUDA llama.cpp bundle
=== BUILD EXIT 0 ===
llama-server --list-devices  ->  CUDA0: NVIDIA B200 (182633 MiB, 147310 MiB free)
/opt/unsloth/llama.cpp/libggml-cuda.so            365945480 bytes
/opt/unsloth/llama.cpp/build/bin/libggml-cuda.so  365945480 bytes
marker: platform linux-x64-cuda, bundle_profile cuda12-portable

The keep branch ran and the assertion passed. One caveat: this host's Docker daemon exposes the GPU during builds, so the pre-fix CPU replacement does not reproduce here (with a GPU visible the old path would have resolved a CUDA asset anyway). The no-GPU CI builder is where the keep branch matters, and the assertion fails the build if it ever does not hold. The arm64 leg is covered by the same code path and the next scheduled publish.

_keep_installed_gpu_prebuilt() normalized both sides of the tag comparison to
their base build, so UNSLOTH_LLAMA_TAG=b10840-mix-new against a marker recording
b10840-mix-old collapsed to b10840 on both sides and the stale bundle was kept.
A requested tag that is not a bare bNNNN is now required to match one of the
marker's recorded release_tag / tag / upstream_tag exactly, while a bare base
build pin keeps the existing normalized comparison and latest still accepts;
UNSLOTH_LLAMA_RELEASE_TAG is passed in as a fourth argument and must equal the
marker's release_tag exactly, independently of the tag check.
Dockerfile.studio is unaffected: it passes UNSLOTH_LLAMA_TAG=latest by default
and sets no release tag. tests/studio/install/test_docker_studio_keep_cuda_prebuilt.py
covers exact mix match, a different mix from the same base build, a bare base
pin, and a matching and mismatching UNSLOTH_LLAMA_RELEASE_TAG.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 37f9e60c7a

ℹ️ 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 0d5743c into main Sep 8, 2026
9 of 71 checks passed
@danielhanchen
danielhanchen deleted the docker-arm64-studio-keep-cuda-llama branch September 8, 2026 12:39
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.

1 participant