On this page
llama.cpp and vLLM both run open models behind an OpenAI-compatible API, so they can look interchangeable. They were built for different jobs, and picking the wrong one shows up as either a slow server or a painful laptop setup.
This guide covers what each engine was designed for, how they handle memory and concurrency differently (with worked numbers), how to run and benchmark both, and how to move a project from one to the other.
#The short version
| llama.cpp | vLLM | |
|---|---|---|
| Built for | One user or a handful, on whatever hardware you have | Many concurrent users on data-centre or workstation GPUs |
| Hardware | CPUs, NVIDIA, AMD, Apple (Metal), Intel, Vulkan devices | NVIDIA first; AMD, Google TPU and some other accelerators; no Apple GPU |
| Model format | GGUF, with many quantisation levels (Q2 to Q8, K-quants, i-quants) | Hugging Face weights; BF16, FP8 and common 4-bit formats (AWQ, GPTQ) |
| Partial GPU offload | Yes: put some layers on the GPU, the rest in system RAM | Has a CPU-offload option, but it's slow; designed for models that fit in GPU memory |
| KV cache | One fixed context, split across parallel slots | Paged blocks, allocated on demand, shared by prefix |
| Concurrency | Parallel slots with continuous batching; good for a few users | Designed for high concurrency |
| Start-up | Seconds, memory-mapped file | Slower: loads weights, profiles memory, captures CUDA graphs |
| Written in | C and C++ | Python over C++, CUDA and Triton kernels |
Ollama and LM Studio are built on llama.cpp, so this comparison also covers them for most purposes (Ollama vs llama.cpp).
#Two different design goals
llama.cpp was built to make large models run at all on ordinary hardware. Its priorities are portability (one C++ codebase for CPUs and every GPU vendor), small memory footprints (aggressive quantisation, memory-mapped files) and flexibility (offload as many layers to the GPU as fit, run the rest on the CPU).
vLLM was built to make serving cheap per request on GPUs. Its priorities are throughput at a latency target: batching many requests together every step (continuous batching explained), wasting as little KV cache memory as possible (PagedAttention explained), and features that only matter at scale, such as prefix caching, multi-LoRA and multi-GPU parallelism.
Neither goal is better. They're optimised for different points on the same curve.
#The key difference: how KV cache memory is managed
Every request needs memory for its KV cache, which grows with the length of its conversation (KV cache explained). The two engines manage it very differently.
llama.cpp reserves one context of a fixed size (-c) and splits it evenly between parallel slots (-np):
llama-server -m Llama-3.1-8B-Instruct-Q4_K_M.gguf -ngl 99 -c 32768 -np 4That gives 4 slots of 8,192 tokens each. A slot can never use more than its share, even if the other three are idle, and up to 4 requests run at once. A fifth waits.
vLLM turns all free GPU memory into a pool of small blocks (16 tokens each by default) and hands them out as requests grow:
vllm serve meta-llama/Llama-3.1-8B-Instruct --max-model-len 8192 --gpu-memory-utilization 0.9A short request uses a few blocks; a long one uses many; finished requests return their blocks immediately. The number of concurrent requests is limited only by total memory (and a cap you can set).
#Worked example: an 8B model on a 24 GB GPU
A Llama-class 8B model has 32 layers and 8 KV heads of dimension 128. In 16-bit precision, its KV cache costs:
On a 24 GB GPU with BF16 weights (about 16 GB), vLLM at 90% memory utilisation has roughly 5 GB left for KV cache after activations: about 40,000 tokens. That's 40 requests of 1,000 tokens each, or 5 of 8,000, mixed however traffic arrives.
Switch to FP8 weights (about 8 GB) and the KV room grows to roughly 13 GB, about 100,000 tokens. Memory, not compute, is usually what limits concurrency on a single GPU.
llama.cpp with a 4-bit GGUF (about 4.9 GB) has even more room, but its fixed slots use it less flexibly: if you set -np 16 with -c 131072, every slot gets 8,192 tokens whether a request needs 200 or 8,000.
#Speed: what to expect
- One user: both engines are bound by memory bandwidth, and speed is similar for similar file sizes. A 4-bit GGUF is smaller than a BF16 checkpoint, so llama.cpp can actually be faster at batch 1 simply because it reads fewer bytes per token (why memory bandwidth decides LLM speed).
- A few users: llama.cpp's parallel slots batch requests together and hold up well.
- Dozens to hundreds of users: vLLM pulls far ahead. Its batching, memory management and optimised kernels are built for exactly this, and total tokens per second keeps rising with load long after llama.cpp's slots are full.
- Long shared prompts: vLLM's automatic prefix caching reuses the KV cache of a repeated system prompt across all requests. llama.cpp can reuse the cache within a slot but doesn't share it across slots in the same way.
#How to benchmark both
Test at the load you actually expect, not with one request at a time (how to benchmark an LLM server).
For vLLM, the built-in benchmark sends requests at a fixed arrival rate:
vllm bench serve --model meta-llama/Llama-3.1-8B-Instruct \
--dataset-name random --random-input-len 1024 --random-output-len 256 \
--request-rate 4 --num-prompts 200For llama.cpp, llama-bench measures single-stream speed, and any OpenAI-compatible load generator can drive llama-server at a fixed rate. Use the same tool against both servers for a fair comparison, and report P50 and P95 time to first token and time per output token (serving metrics), not just averages.
#Choose llama.cpp when
- You run on a laptop, a Mac, a CPU-only server or a mixed CPU and GPU machine.
- The model doesn't quite fit in GPU memory and you need to offload some layers to system RAM.
- You want the widest choice of quantisation levels to trade quality for memory.
- You serve yourself or a small team, or ship a model inside a desktop or edge application.
- You need grammar-constrained output on modest hardware.
#Choose vLLM when
- You serve many users at once and need throughput at a latency target.
- You have GPUs with enough memory for the whole model (or several GPUs with tensor parallelism).
- Requests share long prefixes (system prompts, documents, agent tool definitions).
- You need features such as multi-LoRA serving, disaggregated prefill or integration with Kubernetes serving stacks (Dynamo vs llm-d).
#Moving from one to the other
A common path is to prototype with llama.cpp or Ollama on a workstation, then serve with vLLM (or SGLang) in production. Plan for these differences:
- Formats change. GGUF files don't carry over; use the original Hugging Face checkpoint or an FP8, AWQ or GPTQ version of it.
- Quality can shift slightly between quantisation methods. Re-run your evaluation on the new format before switching traffic.
- Chat templates come from the model's tokenizer config in vLLM and from GGUF metadata in llama.cpp. Check that system prompts, tool calling and stop tokens behave the same.
- Sampling defaults differ. Set temperature, top-p and maximum tokens explicitly in every request rather than relying on server defaults.
- Memory planning changes. Set
--max-model-lento what your traffic needs, not the model's maximum, so vLLM can plan for more concurrent requests. - Benchmark at your real concurrency (concurrency and load testing). A single-user test says little about a server.
#Common mistakes
- Serving a team of 50 from Ollama on one GPU, then blaming the hardware when requests queue.
- Running vLLM on a laptop GPU with
--max-model-lenleft at 128K, which leaves too little memory for even one request. - Comparing a 4-bit GGUF against a BF16 vLLM model and calling the result an engine comparison.
- Forgetting
-nglin llama.cpp, so everything runs on the CPU.
#FAQ
Can vLLM run GGUF files? vLLM has experimental GGUF loading for some architectures, but it isn't the main path and is usually slower than its native formats. Use Hugging Face weights in production.
Can llama.cpp serve many users? Yes, with parallel slots and continuous batching, up to a point. For a handful of concurrent users it's fine; for dozens or hundreds, a server engine is far more efficient.
Does vLLM run on a Mac? Not on the Mac's GPU in the main project. On a Mac, use llama.cpp or MLX (MLX vs llama.cpp).
What about SGLang? It's a server engine like vLLM, with particular strengths in prefix-heavy and structured-output workloads; see vLLM vs SGLang.
#Go deeper
comparisonruntimesllama.cppvllm
Found this useful?
Send it to someone who is learning the same thing.
Preparing for an interview?
Next: learn it step by step, free
Engines compared from the inside
How vLLM, SGLang, TensorRT-LLM and llama.cpp schedule, batch and cache, side by side. A free lesson with step-through diagrams and a quiz.