Run a local LLM with llama.cpp

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.

Size your own model and hardware for llama.cpp

3. The settings that decide memory use

Set the context window

-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

Command
Qwen 3 0.6B0.4 GB
Llama 3.2 1B Instruct0.8 GB
Gemma 3 1B0.8 GB
SmolLM2 1.7B1.0 GB
LFM3 1.7B1.0 GB
DeepSeek R1 Distill Qwen 1.5B1.0 GB
Qwen 3 1.7B1.2 GB
Gemma 2 2B1.6 GB
SmolLM3 3B1.8 GB
Qwen 2.5 3B1.8 GB
Qwen 3.5 2B1.8 GB
Granite 4.0 H Micro 3B1.8 GB
Llama 3.2 3B Instruct1.9 GB
Granite 4.2 3B2.1 GB
Phi-4 Mini 3.8B2.3 GB
Phi-4 Mini Reasoning 3.8B2.3 GB
Qwen 3 4B Instruct 25072.3 GB
Nemotron 3 Nano 4B2.7 GB
Ministral 3 3B2.8 GB
Gemma 3n E2B2.8 GB
Gemma 3 4B3.1 GB
Qwen 3.5 4B3.5 GB
MedGemma 4B3.9 GB
Granite 4.0 H Tiny 7B A1B (MoE)4.0 GB
Mistral 7B Instruct v0.34.1 GB
Gemma 4 E2B4.1 GB
Olmo 3 7B Think4.2 GB
Olmo 3 7B Instruct4.2 GB
Gemma 3n E4B4.2 GB
Falcon3 7B Instruct4.3 GB
Qwen 2.5 Coder 7B4.4 GB
Qwen 2.5 7B4.4 GB
DeepSeek R1 Distill Qwen 7B4.4 GB
EXAONE 3.5 7.8B Instruct4.4 GB
EXAONE Deep 7.8B4.4 GB
DeepSeek R1 Distill Llama 8B4.6 GB
Llama 3.1 8B Instruct4.6 GB
Llama 3 8B Instruct4.6 GB
Granite 3.3 8B4.6 GB
Qwen 3 8B4.7 GB
Aya Expanse 8B4.7 GB
CodeGemma 7B5.0 GB
LFM2.5 8B A1B (MoE)5.0 GB
Granite 4.2 8B5.0 GB
InternLM3 8B Instruct5.0 GB
Gemma 2 9B5.4 GB
Qwen 2.5 VL 7B5.6 GB
Falcon3 10B Instruct5.9 GB
Nemotron Nano 9B v26.1 GB
Gemma 4 E4B6.4 GB
Ministral 3 8B6.4 GB
Gemma 4 12B6.8 GB
Qwen 3 VL 8B6.8 GB
Mistral Nemo 12B7.0 GB
Qwen 3.5 9B7.0 GB
Gemma 3 12B7.6 GB
Phi-4 14B8.3 GB
DeepSeek R1 Distill Qwen 14B8.4 GB
Qwen 2.5 14B8.4 GB
Qwen 2.5 Coder 14B8.4 GB
Qwen 3 14B8.4 GB
Phi-4 Reasoning Plus 14B8.4 GB
Phi-4 Reasoning 14B8.4 GB
Ministral 3 14B9.3 GB
DeepSeek Coder V2 Lite (16B MoE)9.7 GB
gpt-oss-20b (MoE)10.8 GB
Codestral 22B12.4 GB
ERNIE 4.5 21B A3B (MoE)12.4 GB
LFM2.5 24B A2B (MoE)13.5 GB
Mistral Small 3.2 24B15.0 GB
Devstral Small 24B15.0 GB
Magistral Small 24B15.0 GB
Mistral Small 3.1 24B15.0 GB
Devstral Small 2 24B15.0 GB
Gemma 2 27B15.5 GB
Gemma 3 27B16.2 GB
Granite 4.2 30B16.5 GB
Qwen 3 Coder 30B A3B16.8 GB
MedGemma 27B17.0 GB
GLM-4.7 Flash (30B-A3B MoE)17.1 GB
Qwen 3 30B A3B (MoE)17.3 GB
Qwen 3.5 27B17.3 GB
Gemma 4 26B A4B (MoE)17.9 GB
EXAONE 3.5 32B Instruct18.0 GB
EXAONE Deep 32B18.0 GB
Olmo 3.1 32B Instruct18.1 GB
Granite 4.0 H Small 32B A9B (MoE)18.2 GB
GLM-4 32B 041418.3 GB
Qwen 3 32B18.4 GB
Command R 35B18.4 GB
Aya Expanse 32B18.4 GB
Qwen 2.5 Coder 32B18.5 GB
QwQ 32B18.5 GB
DeepSeek R1 Distill Qwen 32B18.5 GB
Qwen 2.5 32B18.5 GB
Qwen 3.8 27B18.9 GB
Qwen 3.6 27B18.9 GB
Gemma 4 31B19.2 GB
Qwen 3 VL 30B A3B (MoE)19.3 GB
Qwen 3.6 35B A3B (MoE)20.0 GB
Seed-OSS 36B20.3 GB
Qwen 4 35B A3B (MoE)20.5 GB
Nemotron 3 Nano 30B A3B (MoE)20.9 GB
Qwen 3.5 35B A3B (MoE)22.2 GB
Nemotron Cascade 2 30B A3B (MoE)23.0 GB
Nemotron 3.5 Lightning 30B A3B23.5 GB
Llama 3.3 Nemotron Super 49B v1.528.1 GB
DeepSeek R1 Distill Llama 70B39.6 GB
Llama 3.3 70B Instruct39.6 GB
Llama 3 70B Instruct39.6 GB
Llama 3.1 Nemotron 70B Instruct39.6 GB
Qwen 2.5 72B44.2 GB
Qwen3 Next 80B A3B (MoE)45.2 GB
Hunyuan A13B (80B MoE)45.4 GB
Qwen 2.5 VL 72B45.5 GB
Qwen3 Coder Next 80B A3B (MoE)45.9 GB
Command R+ 104B58.4 GB
gpt-oss-120b (MoE)58.5 GB
GLM-4.5 Air (106B MoE)59.3 GB
Llama 4 Scout (109B MoE)62.5 GB
Command A 111B62.5 GB
Nemotron 3.5 Super 120B A12B66.9 GB
Mistral Large 2 (123B)68.2 GB
Devstral 2 123B69.8 GB
Mistral Small 4 (119B)70.3 GB
Qwen 3.5 122B A10B (MoE)73.0 GB
Nemotron 3 Super 120B A12B (MoE)76.9 GB
Mistral Medium 3.5 (128B)79.7 GB
MiniMax M2.5 (229B MoE)129 GB
MiniMax M2.7 (229B MoE)131 GB
Qwen 3 235B A22B (MoE)132 GB
ERNIE 4.5 300B A47B (MoE)168 GB
MiMo V2 Flash (309B MoE)174 GB
GLM-4.7 (355B MoE)202 GB
Llama 4 Maverick (400B MoE)228 GB
Qwen 3.5 397B A17B (MoE)229 GB
MiniMax M3 (428B MoE)247 GB
Qwen 3 Coder 480B A35B270 GB
Nemotron 3 Ultra 550B A55B (MoE)335 GB
DeepSeek R1 (671B MoE)377 GB
DeepSeek V3.2 (671B MoE)378 GB
DeepSeek V3.1 (671B MoE)378 GB
Kimi K2 Thinking (1T MoE)579 GB
Mistral Large 4 (1T MoE)594 GB