llama.cpp and GGUF: Install, Quantize, Run llama-server

By Updated

What is llama.cpp?

llama.cpp is an open-source (MIT) C/C++ library and a set of tools for running language models on CPU and GPU. It reads models from GGUF files, which hold the weights together with metadata. llama-server exposes a model over an OpenAI-compatible HTTP API, llama-quantize compresses weights, and llama-bench and llama-perplexity measure speed and loss.

TL;DR

  • -As of November 29, 2026 the stable version is 1.1.0: there is now a llama command with subcommands and semver releases, the server listens on port 9931, Jinja templates are on from the start, and the --draft-max and --draft-min flags are removed.
  • -Memory is the file plus the KV cache. With Qwen3.5-9B Q4_K_M, the llama-server process took 5.63 GiB at a context of 4,096, 6.51 GiB at 32,768 and 9.51 GiB at 131,072. The growth matched the calculation from the config: 32 KiB per token.
  • -Perplexity on one text: Q8_0 3.6662, Q4_K_M 3.6966, Q3_K_M 3.8122. Q4 is 0.8% worse than Q8, Q3 is 4% worse. This is a rough check on 68.8 KB of text and doesn't replace a test on your own task.
  • -In the test, llama-server with no extra flags returned a function call and JSON that follows a schema on Qwen3.5-9B.
  • -The article has no speed numbers: on a busy machine, repeating the same run gives noticeably different results. Instead there is a llama-bench command and the signs of an invalid run.

llama.cpp is an open-source (MIT) C/C++ library and a set of tools for running language models on CPU and GPU. It reads models from GGUF files: one file contains the weights and the metadata. The llama.cpp engine works inside Ollama and LM Studio, but you can also run it directly. The minimal set of commands:

brew install llama.cpp                                    # macOS and Linux
llama cli   -hf unsloth/Qwen3.5-9B-GGUF:Q4_K_M            # chat in the terminal
llama serve -hf unsloth/Qwen3.5-9B-GGUF:Q4_K_M -c 32768   # HTTP API, port 9931

What was tested and what wasn’t. The test ran on November 29, 2026: llama.cpp 1.1.0 from Homebrew (build 12774), a MacBook with an Apple M4 Max and 36 GB, macOS 27.2.1, the unsloth/Qwen3.5-9B-GGUF model in Q3_K_M, Q4_K_M and Q8_0 quants. The SHA-256 of the files matched those on Hugging Face. The files were built by Unsloth, not by the model’s authors. Server memory, perplexity, a function call and JSON by schema were tested, one run each. Windows, Linux, the router, speculative decoding, multimodality and making your own quant are described from the documentation for tag v1.1.0.

What changed in llama.cpp 1.0 and 1.1

Version 1.0.0 came out on November 13, 2026, and 1.1.0 on November 26. Semver tags started earlier, with 0.x releases; from 1.0.0 on, the major number goes up when the public C API changes incompatibly. Some older instructions no longer apply.

In older instructionsIn 1.1.0
llama-cli, llama-serverstill work; a llama command with cli, serve, bench, quantize and perplexity subcommands now sits next to them
http://localhost:8080default port 9931
--jinja for tool callingon by default, turned off with --no-jinja
--draft-max, --draft-minremoved, replaced by --spec-draft-n-max, --spec-draft-n-min or the --spec-ngram-mod-* parameters
only bNNNN versionssemver for releases, bNNNN for nightly builds

Prebuilt binaries on GitHub Releases are still in the nightly builds. Release 1.1.0 points to build b12774, and the Homebrew package showed the same number. According to the release process description, stable versions reach users through the installer, package managers and building from the tag.

Installing llama.cpp

MethodCommandWhere it works
Homebrewbrew install llama.cppmacOS, Linux
Wingetwinget install llama.cppWindows
conda-forgeconda install -c conda-forge llama.cppWindows, macOS, Linux
Installer from the READMEcurl -LsSf https://llama.app/install.sh | shmacOS, Linux
Dockerghcr.io/ggml-org/llama.cpp:serverLinux/amd64, arm64, s390x

The channels are listed in docs/install.md and docs/docker.md. The installer downloads a prebuilt binary from storage on Hugging Face, and if HF_TOKEN is in the environment, it sends the token in its requests. Read the script before running it.

The Homebrew package weighed 22.2 MB in the test. It installs both llama and separate tools, among them llama-server, llama-bench, llama-quantize, llama-imatrix and llama-perplexity. llama has no imatrix subcommand, so call llama-imatrix.

Metal on macOS is on by default. The number of layers on the GPU is set with -ngl: the default is auto, and a number or all also works.

First run and the model cache

The -hf <author>/<model>[:quant] flag downloads a GGUF from Hugging Face. Without a quant it takes Q4_K_M, and if there is none, the first file in the repository. The image projector (mmproj) is downloaded automatically; for this model F16 and BF16 weigh 0.92 GB each. If you only need text, add --no-mmproj.

The files go to the Hugging Face cache (~/.cache/huggingface/hub); LLAMA_CACHE sets a different directory. llama cli -cl lists what has been downloaded. If Hugging Face is unavailable, a local file will do:

shasum -a 256 models/Qwen3.5-9B-Q4_K_M.gguf     # compare with the hash on the file page
llama serve -m models/Qwen3.5-9B-Q4_K_M.gguf -c 32768
curl -s http://127.0.0.1:9931/health            # {"status":"ok"}, 503 while loading

In the test the server was ready in 2 seconds. The file was already in the OS cache; a cold load takes longer.

GGUF: what’s inside the file and how to read the name

GGUF is a binary format with key-value metadata: architecture, layer sizes, tokenizer. Under the specification, one file is enough to load a model, and it can be memory-mapped with mmap instead of read in full.

Part of the nameMeaning
Qwen3.5-9Bmodel and parameter count
Q4_K_Mquantization scheme
mmproj-...multimodal projector, loaded together with the main model
mtp-...Multi-Token Prediction heads for speculative decoding
-00001-of-00004part of a model split into several files

Quants with the UD- prefix in Unsloth repositories are the publisher’s own scheme; llama.cpp has no type with that name.

Quantization: Q3, Q4, Q8 and quality loss

Quantization reduces the number of bits per weight. The name rounds the real figure: in the llama-quantize table for Llama 3.1 8B, Q3_K_M has 4.00 bits per weight, Q4_K_M 4.89, Q6_K 6.56 and Q8_0 8.50. The “parameters × bits / 8” formula and a table of models for different amounts of memory are in the local LLM guide.

Perplexity shows how well a model predicts the next token; lower is better. In the test the same 68.8 KB English text went through three quants with -c 2048:

Qwen3.5-9B fileSizeModel in memoryPerplexityvs Q8_0
Q8_09.53 GB8.86 GiB3.6662 ± 0.082-
Q4_K_M5.68 GB5.28 GiB3.6966 ± 0.082+0.8%
Q3_K_M4.67 GB4.34 GiB3.8122 ± 0.087+4.0%

Q4_K_M saves 40% of the file size and barely changes the result on this text. Q3_K_M is another 18% smaller than Q4 but loses noticeably more.

The error after ± describes the spread across the text, and the intervals of all three rows overlap. It doesn’t follow that there’s no difference: the models were scored on the same tokens, so the difference has to be estimated pairwise. In the llama.cpp table for Llama 3 8B, the error of Q4_K_M perplexity itself is 0.039, while the error of its difference from FP16 is only 0.005. KL divergence mode does the pairwise comparison:

llama-perplexity -m m/Q8_0.gguf   -f text.txt -c 2048 --kl-divergence-base q8.kld
llama-perplexity -m m/Q4_K_M.gguf -f text.txt -c 2048 --kl-divergence-base q8.kld --kl-divergence

The logit file is large: for Wikitext-2 the documentation gives 37 GiB for Llama 3. On a short text of your own it’s smaller. The author hasn’t run this mode. Don’t compare perplexity between different models: their tokenizers differ, and the documentation warns about this.

Your own quant and imatrix

Quantize from BF16 or F16. The conversion script is in the repository; the Homebrew package doesn’t include it:

git clone --depth 1 --branch v1.1.0 https://github.com/ggml-org/llama.cpp && cd llama.cpp
uv pip install -r requirements.txt --index-strategy unsafe-best-match
python convert_hf_to_gguf.py --outfile m-bf16.gguf --outtype bf16 --remote <author>/<model>
llama-imatrix  -m m-bf16.gguf -f calibration.txt -o imatrix.gguf -ngl 99
llama-quantize --imatrix imatrix.gguf m-bf16.gguf m-Q4_K_M.gguf Q4_K_M

imatrix (importance matrix) is collected on a calibration text and indicates which weights to round more carefully. In the same Llama 3 8B table it cut the perplexity increase of Q3_K_M from 0.66 to 0.50 and of Q4_K_M from 0.18 to 0.15: the coarser Q3 gains more. In 1.1.0 llama-quantize got --target-bpw and --target-size, which choose tensor types for a given budget. --dry-run checks the plan without writing a file.

Context and KV cache: how much memory llama-server takes

Process memory (RSS) with Q4_K_M, -np 1 --fit off:

Context -cllama-server RSSMeasured growthCalculated growth
4,0965.63 GiB--
32,7686.51 GiB0.88 GiB0.875 GiB
131,0729.51 GiB3.88 GiB3.875 GiB

The calculation uses config.json. Qwen3.5-9B has hybrid attention: only 8 of its 32 layers keep a full KV cache. Size per token: 8 layers × 2 (K and V) × 4 KV heads × 256 × 2 bytes (f16) = 32 KiB. Calculation and measurement differ by less than a hundredth of a GiB, so for the full window of 262,144 you can expect about 13.5 GiB (a calculation, not a measurement).

A model with regular attention has a KV cache in every layer and uses more per token. Don’t carry these numbers over to another architecture; calculate from its config.

Flags that affect memory:

  • -c N sets the context size. The value 0 (default) takes the model’s window.
  • --fit on (default) adjusts the parameters you haven’t set to free memory. The --fit-target margin is 1,024 MiB per device, and the lower bound on context, --fit-ctx, is 4,096. It doesn’t touch an explicit -c. llama-fit-params prints the outcome in advance.
  • -np N is the number of slots. Without the flag, server 1.1.0 creates 4 slots with a unified KV cache. If you set -np by hand, the unified cache is off and the context is split: -c 32768 -np 4 gives 8,192 tokens per request.
  • -ctk, -ctv set the KV cache type, f16 by default; there are also q8_0, q4_0 and f8_e4m3, which appeared in 1.0.0. The documentation doesn’t estimate quality loss, and the author didn’t measure it.
  • -cram is the prompt cache in RAM, up to 8,192 MiB. It fills up during operation and didn’t show in the startup measurement.

For a Mac with 36 GB the order is: the file, plus the KV cache, plus a margin for the system and open applications. In the measurement from the local LLM guide, Ollama sees 28.1 GiB on such a machine. This limit wasn’t measured separately for llama.cpp. What goes into the context and why a model forgets the start of a conversation is covered in the context window article.

llama-server: OpenAI API, tool calling and JSON

llama serve and llama-server are the same program. According to the documentation it serves /v1/chat/completions, /v1/responses and /v1/embeddings in OpenAI format, /v1/messages in Anthropic format and a built-in web chat. Reranking is enabled separately with --rerank. For a shared team interface you can connect the server to Open WebUI, and for a terminal agent, to OpenCode.

curl -s http://127.0.0.1:9931/v1/chat/completions \
  -H 'Content-Type: application/json' -d '{
  "messages": [{"role": "user", "content": "What is the weather in Kazan?"}],
  "tools": [{"type": "function", "function": {
    "name": "get_weather", "description": "Weather in a city",
    "parameters": {"type": "object",
      "properties": {"city": {"type": "string"}}, "required": ["city"]}}}]
}'

What the server returned in the test, with no extra flags. The test prompts were in Russian and the request above is a translation, so the values came back in Russian: Казань is Kazan, Токио is Tokyo.

CheckResult
Function callfinish_reason=tool_calls, get_weather {"city":"Казань"}
response_format: json_schema{"capital": "Токио"}, reasoning separate from the answer

Reasoning in the second request took 2,392 characters for a one-word answer. According to the documentation, "reasoning_effort": "none" in the request or --reasoning off at startup turns it off. One successful call shows that the mechanism works but says nothing about how often the model will get your schemas wrong. Validating arguments and deciding when to retry is covered in the article on function calling and structured output.

The function calling page lists native formats, and Qwen3.5 isn’t among them, although the call worked in the test. If the model prints the call as plain text, look for Chat format: Generic in the log and set a template with --chat-template-file. Parallel calls are enabled with "parallel_tool_calls": true.

Server security

  • By default the server listens on 127.0.0.1 and there is no key. Before changing --host, set a key through LLAMA_API_KEY or --api-key-file: a key in the --api-key argument is visible in the process list. The /health endpoint is open even with a key.
  • By default CORS reflects any Origin. If web pages don’t need access, set --cors-origins localhost.
  • --tools and --agent let the model read and write files and run commands. The documentation asks not to enable them in an untrusted environment. Outside loopback without a key, a server with tools refuses to start; only --allow-unauthenticated-tools bypasses this.
  • MCP servers from --mcp-servers-config run with the server’s own permissions.

Several models on one port

llama-server without a model starts as a router: it loads the model named in the request’s model field and unloads the least recently used ones. This is the closest counterpart to Ollama’s background server.

llama-server --models-dir ./models --models-max 2 -c 16384
curl -s http://127.0.0.1:9931/models        # names of available models

By default up to 4 models are kept at once. A limit by count knows nothing about memory, so either fix -c and --models-max or set --models-memory-margin: then the router unloads idle models before loading, to make room. Per-model parameters go into an INI file for --models-preset. Put the projector file in the model’s subdirectory; its name must start with mmproj. --sleep-idle-seconds unloads a model when idle.

Speculative decoding and multimodality

With speculative decoding the server guesses several tokens ahead and verifies them in one pass. The type is set with --spec-type; it’s off by default.

TypeWhat it needsWhen to try it
ngram-modnothing, a pool of about 16 MBcode edits, summarization, repetitive text
draft-mtpMTP heads in the model or an mtp-* filemodels that have such a file
draft-simplea small draft model, -mda large model and its smaller version
draft-eagle3, draft-dflash*a draft trained for the modelsuch a draft is published

The simplest start is --spec-default: it enables ngram-mod. unsloth/Qwen3.5-9B-GGUF has no MTP file; ggml-org/Qwen3.8-27B-GGUF does (from 1.68 GB). The gain depends on the share of accepted tokens and wasn’t measured for this article.

llama-cli and llama-server accept images, audio and video. For a local file, specify the projector explicitly: -m model.gguf --mmproj mmproj.gguf. The documentation advises keeping the projector in BF16 or Q8: it takes little space and directly affects answer quality.

Speed: how to measure it and when not to trust a run

Speed depends on machine load: on a busy machine, repeating the same run gives noticeably different results, so there are no numbers here. The command below measures it on your machine.

uptime
llama-bench -m m/Q3_K_M.gguf -m m/Q4_K_M.gguf -m m/Q8_0.gguf \
  -p 512,4096 -n 128 -r 5 --delay 10 -o md | tee bench-1.md
uptime
# repeat with the files in reverse order, output to bench-2.md

llama-bench reports prompt processing (pp) and generation (tg) separately; tokenization and sampling time isn’t included. What a token is and why non-English text takes more of them is explained in the tokens article.

Three signs give away an invalid run:

  1. The repeat doesn’t reproduce. The difference between runs is larger than the spread inside each of them. The ± value in the llama-bench table refers to repetitions within a run and doesn’t show this error.
  2. The order of quants is implausible. Generation on a GPU is limited by reading weights from memory, so a smaller file of the same model shouldn’t lose badly to a larger one. If it does, look for interference first, not for a property of the quant.
  3. Load average is rising. Something else was running during the test: a build, an emulator, indexing. Record uptime before and after each run.

When the numbers can be compared

Close builds, emulators and heavy tabs, plug in power and check that swap isn’t growing. Run the whole set twice in a different order and keep the result if the runs agree within their internal spread. Record the llama.cpp version, file name, context and KV cache type: without them the numbers can’t be compared with anything. Application measurements on an M4 Max with 36 GB, with the method, are in the LM Studio and Ollama comparison. They can’t be carried over to plain llama-server.

llama.cpp, Ollama or LM Studio

  • llama.cpp when you need a specific GGUF, control over the KV cache and slots, your own quant, loss measurement or a server without extra layers.
  • Ollama when a library of ready models and a background service are enough. Installation and Modelfile are described in the Ollama guide.
  • LM Studio when a graphical interface and a catalog are more convenient.

Don’t expect a speedup just from switching to llama.cpp: both applications run GGUF on the same engine, and the difference comes down to version and settings.

Common errors

SymptomCauseWhat to do
localhost:8080 doesn’t respondthe default port is 9931fix the address or set --port 8080
The --draft-max flag isn’t acceptedremoved--spec-draft-n-max
Context smaller than expected-c not set and --fit kicked in, or the context was split between slotsset -c, check n_ctx_slot in the log
-hf downloaded an extra filethe projector loads automatically--no-mmproj
Memory grows during operationprompt cache, -cram up to 8,192 MiBreduce -cram, 0 turns it off
The model prints a function call as texttemplate not recognized--chat-template-file, check Chat format
Your quant answers worse than expectedan already quantized file was quantizedtake BF16 or F16

Limitations of the test

One run each, one model, one machine. Perplexity was computed on a short English text from the author’s own articles: the picture may differ for other languages, code and long context. The reference was Q8_0, not F16. RSS shows the process right after startup, without load or parallel requests. The function call and JSON were checked with one request each.

Where to start

  1. Install llama.cpp and check the version: llama version.
  2. Download the Q4_K_M of your model and compare the SHA-256.
  3. Calculate the KV cache from config.json and set -c explicitly.
  4. Run llama serve, then check /health, a function call and JSON on your schemas.
  5. Compare Q4 with Q8 on 20-30 of your own requests, and through KL divergence if you need a figure.
  6. Measure speed twice on an idle machine.
  7. Open the port to the outside only with a key and behind an HTTPS proxy.

Frequently Asked Questions

How is llama.cpp different from Ollama?
llama.cpp is an engine and tools: you choose the GGUF file, the context, the KV cache type and the server flags yourself. Ollama is a separate server with its own model library and Modelfile that uses llama.cpp for GGUF. People use llama.cpp directly when they need a specific quant, flag or tool such as llama-quantize or llama-perplexity.
What is the default llama-server port?
In version 1.1.0 it is port 9931 on address 127.0.0.1. Older guides give 8080. The port is set with the --port flag or the LLAMA_ARG_PORT variable.
Which GGUF quantization should I choose?
Start with Q4_K_M: it is the default for -hf. In the author's test on Qwen3.5-9B, Q4_K_M perplexity was 0.8% worse than Q8_0 with a 5.68 GB file against 9.53 GB, and Q3_K_M was 4% worse. If memory allows, compare Q4, Q6 and Q8 on your own requests. Take Q3 when Q4 doesn't fit.
How much memory does llama.cpp need?
The GGUF file size plus the KV cache of the context plus buffers. Qwen3.5-9B Q4_K_M with a 5.68 GB file took 5.63 GiB at a context of 4,096 and 9.51 GiB at 131,072. Models without hybrid attention usually have a larger KV cache per token, which is calculated from config.json.
Does llama-server support tool calling?
Yes, through the OpenAI-compatible /v1/chat/completions. In the test on Qwen3.5-9B, server 1.1.0 with no extra flags returned finish_reason=tool_calls and a city argument. If the model's template isn't recognized, the documentation says the Generic format is used, which spends more tokens.
Why did llama-server load less context than the model supports?
Without -c the context comes from the model, and --fit, which is on by default, shrinks unset parameters to fit free memory. The lowest it can go is 4,096 tokens. Set -c explicitly and check n_ctx_slot in the log: with -np N and no unified KV cache, the context is split between slots.
Can I quantize an already quantized GGUF?
Technically yes, with the --allow-requantize flag, but the documentation warns that quality can drop severely. The source should be BF16 or F16.