Ollama vs llama.cpp: Differences, Speed Question and Which to Use
By LLM Hardware team · Methodology ·
LLM Hardware team
The short answer
Ollama and llama.cpp are closely linked: Ollama's README lists the llama.cpp project under "Supported backends", so yes, Ollama builds on it. llama.cpp is the inference library with its own command line tools and a server. Ollama wraps a background server, a model download flow and Modelfile packaging around that kind of engine. For the same GGUF file the memory math is the same: an 8B model at Q4 needs about 6.8 GB (8 x 0.5 x 1.2 + 2), whichever tool loads it. This site does not test hardware and has no speed comparison between the two, so it does not claim that either one is faster.
If you want the quickest path from install to a chat prompt, start with Ollama. If you want direct control over layers, GPU splits, cache types and build flags, use llama.cpp. The rest of this page backs those two sentences with the official docs and shows how to move a GGUF file from one to the other. For a broader view of local tools, see how to run LLMs locally, and for the desktop app side of the story, see LM Studio vs Ollama.
Is Ollama based on llama.cpp?
The Ollama README has a short section titled "Supported backends". It contains one entry: the llama.cpp project founded by Georgi Gerganov, linked to the ggml-org repository. That is the primary statement of the relationship, and it is why "Ollama is built on llama.cpp" is a fair summary.
The picture has more detail than that one line. Ollama's development doc says the native runtime is built with CMake, and that you can tune GGML build options by setting GGML_* values during configure. The llama.cpp README says that project is built on top of the ggml library, so the shared ggml layer shows up in both repositories. The same Ollama doc also describes an MLX engine that runs safetensors-based models, enabled by default on macOS arm64. So for some models on some machines, llama.cpp may not be the code path at all.
The docs this guide read do not publish a per-model table that says which engine serves which model, and they do not describe how far Ollama's own engine work has gone. Treat any claim of the form "Ollama is only a wrapper" or "Ollama has fully replaced llama.cpp" as unverified. The verified statement is narrower: Ollama lists llama.cpp as a supported backend, and its repository also documents an MLX engine for safetensors models.
What each tool is
Ollama
The Ollama README opens with "Start building with open models. Access the latest releases locally or in the cloud with complete privacy." You install it with a script or installer on macOS, Windows or Linux, or use the ollama/ollama Docker image. Running ollama run gemma4 opens a chat with that model, and the REST API answers at http://localhost:11434/api/chat. The repository uses the MIT license. Python and JavaScript client libraries exist as pip install ollama and npm i ollama. The server keeps models in memory for 5 minutes by default, and the Ollama keep alive guide covers changing that. Day-to-day commands are collected in the Ollama cheat sheet.
llama.cpp
The llama.cpp README states the main goal as "to enable LLM (and MLLM) inference with minimal setup and state-of-the-art performance on a wide range of hardware - locally and in the cloud." You can install it with the llama.app script, run it in Docker, download pre-built binaries from the releases page, or build from source using the build guide. The README quick start shows two commands: llama cli -hf ggml-org/Qwen3.5-0.8B-GGUF downloads a model from Hugging Face and runs it, and llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF launches an OpenAI-compatible API server. The server README still uses the older llama-server spelling in its examples, so you will see both names in the docs.
The server README lists parallel decoding with multi-user support, continuous batching, multimodal support, a reranking endpoint, schema-constrained JSON output, speculative decoding and a built-in chat app. The tool exposes most of its behavior as flags, which is the main practical difference from Ollama, where much of the same behavior sits behind environment variables and Modelfile parameters.
Ollama vs llama.cpp feature comparison
Every row below comes from the official pages listed in the Sources table at the bottom. The last column gives the source numbers for each row. Where a row says "as displayed", the figure is what GitHub showed on the day this page was checked.
| Feature | Ollama | llama.cpp | Sources |
|---|---|---|---|
| Model format | Imports a GGUF file or a safetensors directory through a Modelfile FROM line. Does not quantize a GGUF during import. | Loads GGUF files with -m model.gguf, or downloads a GGUF repo from Hugging Face with -hf. | 3, 4, 2, 9 |
| GPU and CPU backends | NVIDIA CUDA (compute capability 5.0+, driver 550+), AMD ROCm v7 on Linux, Apple Metal, Vulkan on Windows and Linux. CPU also works. | Build docs cover CPU, BLAS, Metal, SYCL, CUDA, MUSA, HIP, Vulkan, CANN, ZenDNN, Arm KleidiAI, OpenCL, WebGPU, OpenVINO and Hexagon. | 5, 11 |
| Server API | REST API on port 11434 plus OpenAI-compatible routes under /v1/: chat completions, completions, models, embeddings, responses. | llama serve or llama-server with OpenAI-compatible chat completions, responses and embeddings routes, plus a reranking endpoint and a built-in chat app. | 1, 8, 2, 9 |
| Multi-GPU | Automatic: loads on one GPU if the model fits, otherwise spreads across all available GPUs. | Manual control with --split-mode, --tensor-split, --main-gpu, --device. Layer split is the default and tensor split is experimental. | 7, 10 |
| Context controls | OLLAMA_CONTEXT_LENGTH, an app slider, and num_ctx in a Modelfile. Default depends on VRAM (4k under 24 GiB). | -c or --ctx-size. The default of 0 means the length is loaded from the model. | 6, 4, 9 |
| KV cache type | OLLAMA_KV_CACHE_TYPE with f16 (default), q8_0 or q4_0. Applies globally and needs flash attention. | --cache-type-k and --cache-type-v, both default f16. A quantized V cache needs flash attention. | 7, 10 |
| How models are fetched | Pulls models from the Internet over HTTPS with ollama run , or imports a local file you already have. | Downloads from Hugging Face with -hf (Q4_K_M by default), or loads a local path. | 1, 7, 9 |
| Concurrency | OLLAMA_NUM_PARALLEL for requests per model and OLLAMA_MAX_LOADED_MODELS for models in memory. Idle models unload after 5 minutes by default. | -np or --parallel for slots, with continuous batching enabled by default. | 7, 9 |
| Install and license | Install script or installer on macOS, Windows and Linux, plus a Docker image. MIT license. | Install script, Docker, pre-built binaries or a source build. | 1, 2 |
| Release cadence | Tags v0.40.10 to v0.40.17 listed across about 18 days as displayed. | Build tags b12641 to b12648 listed within about two hours on one day. | 13, 14 |
Reading the table
Three rows show the style difference. On multi-GPU, Ollama decides for you: one GPU if the model fits, all GPUs if it does not. llama.cpp hands you the controls, including --tensor-split 3,1, which sets the proportions of the model placed on each GPU. On context, Ollama picks a default from your VRAM tier (4k under 24 GiB, 32k from 24 to 48 GiB, 256k at 48 GiB or more), while llama.cpp defaults -c to 0, which loads the length from the model. That second default matters for memory, covered in the VRAM section below. On backends, llama.cpp documents the longer list because it is a build-it-yourself project with a CMake flag per backend, whereas Ollama's GPU page lists CUDA, ROCm, Metal and Vulkan.
One caution on documentation: Ollama's context-length page lists a 4k default for machines under 24 GiB of VRAM, while its Modelfile page lists the num_ctx default as 2048. The two pages disagree. Check the CONTEXT column in ollama ps to see the value your install uses.
Ollama vs llama.cpp speed
Searches for "llama.cpp vs Ollama speed" want a winner. This site has none to offer. It does not benchmark hardware, and the official pages checked for this guide do not publish a head-to-head figure. No dated third-party benchmark was fetched for this page either, so no tokens-per-second number appears here.
What the docs do support is a list of factors that change speed between any two runs, whichever tool you use:
- Where the model sits. Ollama reports it in the PROCESSOR column of
ollama psas 100% GPU, 100% CPU or a split. A split means part of the model was offloaded to system memory. In llama.cpp,-nglsets the maximum number of layers stored in VRAM, with a default of auto. - Context length. A larger context allocates more KV cache. Ollama's docs say larger contexts use more memory, and its context page recommends 100% GPU at the context you need.
- KV cache type and flash attention. Ollama enables flash attention automatically when the backend and devices support it, and its cache type setting applies only when flash attention is on. llama.cpp's multi-GPU doc says a quantized V cache and tensor split mode both require flash attention. See KV cache quantization in Ollama and llama.cpp.
- Build and backend. A llama.cpp build compiled without your GPU backend runs on the CPU. Ollama's development doc says that on platforms other than macOS arm64 the default source build is CPU-only unless you pick a GPU backend.
- Parallel requests. Ollama's
OLLAMA_NUM_PARALLELdefaults to 1 on non-MLX backends, and llama.cpp's-npdefaults to auto. Throughput under several users depends on those settings. - The model file. A Q4 file and a Q8 file of the same model differ in size and speed. The LLM quantization guide explains the tiers.
To compare them for your hardware, load the same GGUF in both, set the same context size (-c in llama.cpp, OLLAMA_CONTEXT_LENGTH or num_ctx in Ollama), confirm all layers sit on the GPU in both, and time the same prompt several times.
When to choose Ollama
- You want install, pull and chat with one command, and you want a background server already listening on port 11434.
- You use client libraries or integrations that expect the Ollama API or its OpenAI-compatible
/v1/routes. The README links Python and JavaScript libraries. - You want multi-GPU placement without tuning. The FAQ says it loads on one GPU if the model fits and spreads across all GPUs if it does not.
- You keep several models and want them to load on demand and unload after idle time, controlled by
OLLAMA_MAX_LOADED_MODELSand the keep-alive setting.
When to choose llama.cpp
- You want to choose the split mode, tensor proportions, main GPU, device list and cache types yourself. The multi-GPU doc documents each flag.
- You need a backend Ollama's GPU page does not list, such as SYCL, CANN, OpenCL or WebGPU. The build doc shows a CMake flag or a separate doc for each.
- You want to build from source with specific options, or build several backends together. The build doc says multiple backends can be built together and that
-DGGML_BACKEND_DLbuilds them as dynamically loaded libraries. - You want to offload specific parts of a model between GPU and CPU. For mixture-of-experts models, the MoE hybrid GPU and CPU offloading guide covers the approach.
- You want a download straight from a Hugging Face repo with
-hf user/model:quantand no Modelfile step.
You can use both: Ollama for daily chat and tool integrations, llama.cpp when a model needs flags the Ollama settings do not expose. Nothing in either set of docs stops you from keeping both installed. They use separate server ports (11434 for Ollama, 9931 by default for llama.cpp's server as listed in its README), so they can run side by side.
Move a GGUF file between Ollama and llama.cpp
From llama.cpp or Hugging Face into Ollama
Ollama's import docs describe a Modelfile whose FROM line points at the GGUF file. The Modelfile reference says the path can be absolute or relative to the Modelfile location. Create a file named Modelfile next to the weights:
FROM ./model.gguf Then build and run it, using the commands from the import page:
ollama create my-model
ollama run my-model For a model split across several files, the import page says to keep the original shard names and use a wildcard that matches every shard, as in FROM /path/to/model-*.gguf. The same page states that Ollama does not quantize GGUF models during import, so the quantization level you import is the level you get. If you need a smaller file, quantize it beforehand with a tool such as llama.cpp's llama-quantize. See GGUF vs GPTQ for what the format holds and how it differs from GPU-first formats.
From a GGUF file into llama.cpp
The server and CLI READMEs list -m, --model FNAME for a local model path and -hf for a Hugging Face repository:
llama-server -m ./model.gguf -c 4096
llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF The -hf value takes the form <user>/<model>[:quant]. The quant tag is optional and case-insensitive, and it defaults to Q4_K_M or falls back to the first file in the repository. If a multimodal projector is available, -hf downloads it automatically.
One direction this guide does not cover: pointing llama.cpp at the copy of a model that Ollama already downloaded. The docs read for this page describe the model storage folder (set by OLLAMA_MODELS) but not the layout inside it. Download the GGUF from its original source and keep it in a folder you manage.
VRAM fit: the same GGUF, the same estimate
Memory depends on the weights you load, not on the launcher. The site formula is GB = params (billions) x bytes per parameter x 1.2 + 2, with Q4 at 0.5, Q8 at 1.0 and FP16 at 2.0 bytes per parameter. For an 8B model at Q4 that is 8 x 0.5 x 1.2 + 2 = 6.8 GB. At Q8 it is 8 x 1.0 x 1.2 + 2 = 11.6 GB, and a 32B model at Q4 comes to 21.2 GB. The 1.2 and the extra 2 GB cover activations and a context of about 4K tokens. Run other sizes in the VRAM calculator, or check a specific card and model in Can I Run.
The default context is where the tools differ. Ollama's default is 4k under 24 GiB of VRAM, which matches the formula's assumption. llama.cpp's -c default of 0 means the context length is loaded from the model, and a model trained for a long context can request more KV cache than the formula includes. Set -c yourself when you size a llama.cpp run. Ollama's OLLAMA_CONTEXT_LENGTH works the other way: raising it above the default adds memory on top of the estimate.
If the estimate exceeds your VRAM, both tools can split a model between GPU and system memory. Ollama shows a split in ollama ps. llama.cpp lets you set -ngl directly, and its multi-GPU doc lists a --fit option that fits unset arguments to device memory, on by default. The run an LLM on CPU guide covers the RAM side of the same math.
FAQ
Is Ollama based on llama.cpp?
Ollama's README lists the llama.cpp project under "Supported backends", so llama.cpp is one of the engines Ollama uses. Ollama's development doc also describes an MLX engine for safetensors-based models, so llama.cpp is not the only path in the repository. The docs this guide read do not give a full per-model breakdown.
Is llama.cpp faster than Ollama?
This site has no speed comparison for the two, so it does not name a faster one. Speed depends on the model file, quantization, context length, how many layers sit on the GPU, the backend build and the hardware. Run both on the same GGUF and the same context setting on your own machine to get a number that applies to you.
Can Ollama run the same GGUF file as llama.cpp?
Yes. Ollama's import docs show a Modelfile with FROM /path/to/file.gguf followed by ollama create my-model. llama.cpp loads the same kind of file with -m model.gguf. Ollama does not quantize a GGUF during import, so quantize it first with a tool such as llama.cpp's llama-quantize.
Does Ollama or llama.cpp support multiple GPUs?
Both do. Ollama's FAQ says it loads a model on a single GPU when the model fits there and spreads it across all available GPUs when it does not. llama.cpp exposes the choice through --split-mode (none, layer, tensor, with row deprecated), --tensor-split and --main-gpu. Its tensor mode is marked experimental.
Which one has an OpenAI-compatible API?
Both. Ollama serves /v1/chat/completions, /v1/completions, /v1/models, /v1/embeddings and /v1/responses at http://localhost:11434/v1/. llama.cpp's server README lists OpenAI-compatible chat completions, responses and embeddings routes.
How much VRAM does an 8B model need in Ollama or llama.cpp?
The site formula gives about 6.8 GB at Q4 (8 x 0.5 x 1.2 + 2) and about 11.6 GB at Q8 (8 x 1.0 x 1.2 + 2) for a short context of about 4K tokens. The same file needs about the same memory in either tool. A longer context adds KV cache on top.
Sources
| # | URL | Claim it supports | Date checked (PT) |
|---|---|---|---|
| 1 | https://github.com/ollama/ollama | README: Ollama description; ollama run gemma4 example; "Supported backends" lists the llama.cpp project; MIT license; REST API at http://localhost:11434/api/chat; links to import and Modelfile docs | 2026-11-22 |
| 2 | https://github.com/ggml-org/llama.cpp | README: main goal quote; built on the ggml library; install via llama.app, Docker, pre-built binaries or source build; llama cli -hf and llama serve -hf quick start; Multi-GPU usage doc link | 2026-11-22 |
| 3 | https://docs.ollama.com/import | GGUF import with FROM /path/to/file.gguf and split files FROM /path/to/model-*.gguf; ollama create my-model; Ollama does not quantize GGUF models during import; safetensors directory import | 2026-11-22 |
| 4 | https://docs.ollama.com/modelfile | GGUF path in FROM is absolute or relative to the Modelfile location; num_ctx default listed as 2048 on this page | 2026-11-22 |
| 5 | https://docs.ollama.com/gpu | NVIDIA compute capability 5.0+ with driver 550 or newer; AMD ROCm v7 on Linux; Apple Metal; Vulkan on Windows and Linux; GPU selection variables CUDA_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES, GGML_VK_VISIBLE_DEVICES | 2026-11-22 |
| 6 | https://docs.ollama.com/context-length | Default context 4k under 24 GiB VRAM, 32k from 24 to 48 GiB, 256k at 48 GiB or more; OLLAMA_CONTEXT_LENGTH; app slider; ollama ps CONTEXT and PROCESSOR columns | 2026-11-22 |
| 7 | https://docs.ollama.com/faq | Model storage paths and OLLAMA_MODELS; OLLAMA_MAX_LOADED_MODELS; OLLAMA_NUM_PARALLEL; 5 minute keep-alive default; OLLAMA_HOST; OLLAMA_FLASH_ATTENTION; OLLAMA_KV_CACHE_TYPE (f16, q8_0, q4_0); multi-GPU placement rule; models pulled over HTTPS | 2026-11-22 |
| 8 | https://docs.ollama.com/api/openai-compatibility | OpenAI-compatible base URL http://localhost:11434/v1/ and the supported endpoint list; /v1/responses is non-stateful | 2026-11-22 |
| 9 | https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md | llama-server features (OpenAI-compatible chat completions, responses, embeddings; parallel decoding; continuous batching; multimodal; reranking); flags -m, -hf, -c, -ngl, -sm, -ts, -np; -hf quant default Q4_K_M; --port default 9931 | 2026-11-22 |
| 10 | https://github.com/ggml-org/llama.cpp/blob/master/docs/multi-gpu.md | Split modes none, layer (default), row (deprecated), tensor (experimental); --tensor-split, --main-gpu, --device, --fit; --cache-type-k and --cache-type-v default f16; flash attention requirements | 2026-11-22 |
| 11 | https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md | Documented backends and CMake flags: CPU, BLAS, Metal, SYCL, CUDA, MUSA, HIP, Vulkan, CANN, ZenDNN, Arm KleidiAI, OpenCL, WebGPU, OpenVINO, Hexagon; multiple backends can be built together | 2026-11-22 |
| 12 | https://github.com/ollama/ollama/blob/main/docs/development.md | Build from source with Go and CMake 3.24+; Metal default on macOS arm64; GPU backends such as CUDA, ROCm, Vulkan selected explicitly elsewhere; GGML_* build options; MLX engine runs safetensors-based models | 2026-11-22 |
| 13 | https://github.com/ollama/ollama/releases | Releases page listed tags v0.40.10 to v0.40.17 with dates between 23 Oct and 10 Nov as displayed (no year shown on the page) | 2026-11-22 |
| 14 | https://github.com/ggml-org/llama.cpp/releases | Releases page listed build tags b12641 to b12648, all dated 23 Nov as displayed, within about two hours | 2026-11-22 |