llama.cpp is the inference engine that Ollama and LM Studio build on. Running it directly gives you every setting: which quantization, how many layers on the GPU, how the KV cache is stored. llama-server downloads a GGUF file from Hugging Face and serves it.
macOS, Linux, Windows · model sizes synced 2026-11-30
Pick llama.cpp when
You want exact control over quantization, context and GPU layers.
You need a quantization that Ollama does not publish.
You want a single binary with no background service.
Look elsewhere when
You want models to load and unload on their own: Ollama does that.
You serve many users at once: vLLM batches far better.
1. Install
macOS and Linux
Homebrew ships current builds.
Windows and others
Download a prebuilt binary for your GPU backend from the releases page of github.com/ggml-org/llama.cpp, or build from source.
Check that it worked
2. Run a model
Example: Qwen 3.8 27B as Q4_K_M on NVIDIA GeForce RTX 4090 (24 GB). With a 16K context it needs 21.5 GB of 22.8 GB usable memory and should generate about 32–43 tok/s.
-c sets the context size in tokens. Left out, llama.cpp uses the size stored in the model file, which for most models is the maximum and can cost many gigabytes of KV cache.
Halve the KV cache
Store keys and values in 8 bits instead of 16.
Check what actually loaded
The startup log prints how many layers were offloaded to the GPU and the size of the KV cache. nvidia-smi on NVIDIA or Activity Monitor on a Mac shows the total in use.
4. Connect your tools
Use it from other tools
The server listens on 127.0.0.1:9931 unless you pass --port. It exposes OpenAI-compatible routes under /v1 and an Anthropic-compatible messages API.
Or let your coding agent do it
Paste this into Claude Code, Codex or any agent with a shell. It carries the target, our estimates and the steps, and tells the agent to check the hardware first and to report measured memory and speed against the estimates. The calculator builds the same prompt for any model, hardware and runtime.
Set up a local LLM on this machine and verify that it works.
Target
- Model: Qwen 3.8 27B (Hugging Face: Qwen/Qwen3.8-27B)
- Runtime: llama.cpp
- Build: Q4_K_M, ggml-org/Qwen3.8-27B-GGUF
- Context window: 16,384 tokens (16K)
- Hardware this was sized for: NVIDIA GeForce RTX 4090 (24 GB)
Estimates from llmsizing.com
- Memory: 21.5 GB of 22.8 GB usable (weights 18.9 GB, KV cache 1.0 GB, approximate, overhead 1.6 GB)
- Fit: Tight fit. Uses 94.5% of usable memory. Close other GPU-heavy apps or switch to an 8-bit KV cache.
- Speed: 32–43 tok/s for one request. Scaled from 10 published llama.cpp measurements on this GPU.
Steps
1. Check the hardware before downloading anything (`nvidia-smi`, or the vendor's equivalent). If it is not NVIDIA GeForce RTX 4090 (24 GB), or less than 21.5 GB of memory is free, stop and tell me what you found.
2. Check whether llama.cpp is installed with `llama-server --version`. If it is not, install it:
- macOS and Linux: `brew install llama.cpp`
- Windows and others: Download a prebuilt binary for your GPU backend from the releases page of github.com/ggml-org/llama.cpp, or build from source.
3. Start the model: `llama-server -hf ggml-org/Qwen3.8-27B-GGUF:Q4_K_M -c 16384`
4. Send one short test prompt. Then report, next to the estimates above: memory actually used (the runtime's startup log), tokens per second, and whether everything runs on the GPU.
5. Tell me the base URL and model name to use from other tools. llama.cpp API: http://127.0.0.1:9931/v1.
Rules
- Ask me before using sudo, changing system settings or installing system packages.
- Do not delete or replace models that are already on this machine.
- If the download is larger than the free disk space, stop and tell me.
- If the measured memory or speed is far from the estimates, say so plainly.
Sized with https://llmsizing.com/?m=qwen3-8-27b&hw=rtx-4090-24gb&q=q4_k_m&ctx=16384&rt=llamacpp
Setup guide: https://llmsizing.com/guides/llama-cpp
How to read our numbers for llama.cpp
Weights plus a KV cache allocated for the full context up front. For models with sliding-window attention llama.cpp keeps only the window for those layers unless you pass --swa-full; our numbers assume the default. Sizes come from the GGUF repositories on Hugging Face.
-hf REPO without a quantization suffix downloads Q4_K_M, or the first file in the repo if there is none.
GPU offload defaults to auto. If the model does not fit, layers stay on the CPU without an error.
144 models with a ready Q4_K_M build for llama.cpp