Skip to content

feat: make llama.cpp a deferred backend on macOS/Windows#737

Merged
doringeman merged 2 commits into
docker:mainfrom
doringeman:llamacpp-on-demand
Jul 8, 2026
Merged

feat: make llama.cpp a deferred backend on macOS/Windows#737
doringeman merged 2 commits into
docker:mainfrom
doringeman:llamacpp-on-demand

Conversation

@doringeman

@doringeman doringeman commented Mar 5, 2026

Copy link
Copy Markdown
Contributor
$ make build-dmr
CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=v0.1.0-4-gf8b8e764 -X github.com/docker/model-runner/cmd/cli/desktop.Version=v0.1.0-4-gf8b8e764" -o dmr ./cmd/dmr
$ ./dmr serve smollm2
$ ./dmr run smollm2 hi
Installing llama.cpp backend...
llama.cpp backend installed successfully
Hi, I'm SmolLM, your AI assistant. How can I help you today?
$ ./dmr status
Docker Model Runner is running

BACKEND    STATUS         DETAILS
llama.cpp  Running        llama.cpp v0.0.34-metal (sha256:aa3e239c5737a7fa56f3908a865eb75dfae214b9cfec2cdd929e4d5353c2d714) ac4cdde
diffusers  Not Installed
mlx        Not Installed  package not installed
sglang     Not Installed  only supported on Linux
vllm       Not Installed

@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 the llama.cpp backend to support deferred installation on macOS and Windows, which is a great improvement. The changes are well-structured, introducing a unified installDir and a BackendUpdater interface for managing binary updates. My main concern is with error handling in main.go where a failure to determine the llama.cpp server path is logged but not treated as a fatal error, which could lead to issues later on. I've added a critical comment with a suggestion to address this.

Comment thread main.go Outdated
On macOS/Windows the llama.cpp server binary is now downloaded on demand
into a single, writable per-user install directory
(~/.docker/model-runner/llama.cpp/bin) instead of relying on a binary
vendored by Docker Desktop. This removes the vendored/updated storage
split and the requirement for a bundled com.docker.llama-server.digest.

- Collapse vendoredServerStoragePath/updatedServerStoragePath into a
  single installDir; default to ~/.docker/model-runner/llama.cpp/bin when
  no path is configured.
- Add llamacpp.NeedsDeferredInstall() (true on macOS/Windows) and mark the
  backend Deferred in the routing defs so it installs on first use instead
  of blocking startup.
- Reuse main's mirror-aware dockerhub download path and the existing
  docker/docker-model-backend-llamacpp {version}-{variant} image tags; the
  download no longer hard-fails when there is no Desktop-bundled binary.
- Linux keeps bundling the binary in the container image (not deferred);
  ensureLatestLlamaCpp remains a no-op that reports the bundled binary.
- LlamaServerPath() no longer defaults to the read-only Docker Desktop
  bundle path; it returns the env override or empty.
- Add a `docker model install-runner --backend llama.cpp` trigger for the
  deferred install, mirroring the vllm-metal path.

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@doringeman doringeman force-pushed the llamacpp-on-demand branch from a2db150 to 7469d77 Compare July 8, 2026 09:13
@doringeman doringeman marked this pull request as ready for review July 8, 2026 09:47

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

By default the deferred macOS/Windows download now fetches a specific
llama.cpp version pinned to this model-runner build instead of the mutable
`latest` tag, so a given release always installs the version it was tested
against and doesn't silently move when Docker Hub publishes a new build.

- Add a pinnedServerVersion constant (a docker-model-backend-llamacpp tag)
  used as the default DesiredServerVersion; bump it together with the Linux
  bundle (Dockerfile LLAMA_SERVER_VERSION) when llama.cpp is upgraded.
- Allow opting into another version on demand, via LLAMA_SERVER_VERSION or a
  new `--llama-server-version` flag on install-runner/reinstall-runner
  (e.g. `--llama-server-version latest`). The flag threads through the
  InstallBackend API and a new inference.BackendVersionSelector interface,
  keeping the scheduler decoupled from the concrete backend.
- Skip the registry digest round-trip when a pinned (immutable) version is
  already installed, recording {tag,digest} in .llamacpp_version. This makes
  startup work offline for pinned versions and removes the per-launch Docker
  Hub call; only `latest` is always re-resolved. Also report the on-disk
  binary as running when updates are disabled.

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@doringeman doringeman force-pushed the llamacpp-on-demand branch from f8b8e76 to 4e6fb00 Compare July 8, 2026 10:06
@doringeman doringeman merged commit 23d40b5 into docker:main Jul 8, 2026
11 checks passed
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.

2 participants