← All articles
Guide · 2026-11-21

Speeding Up Local Model Inference: Key llama.cpp Tuning Parameters

Published 2026-11-21 ·Mentions: Ollama, llama.cpp
Speeding Up Local Model Inference: Key llama.cpp Tuning Parameters
Tuning llama.cpp comes down to a few moves: get the service running with llama serve, set -ngl by VRAM, -c by conversation length, and --temp and --top-p by task, then compare against Ollama quantization levels to find the settings that are enough on your machine.

The Short Answer: Who This Is For

The short answer: tuning local inference is not about swapping in a different model. It is a controlled experiment: the same model and the same prompt set, measured parameter by parameter on speed, VRAM use, and answer quality. Tuned and untuned settings can perform very differently on the same machine; the goal is to find the set that is enough without wasting resources.

It suits people running models locally who want to get the most out of their machine: laptop users with limited memory, people running a larger model on an older computer, and developers wiring a model into their own service. The main route serves the model with llama.cpp and tunes its parameters, using Ollama to compare different quantization levels. Start with a small model to prove the process, then move to a larger one.

What You Need

Prepare three things: a computer with llama.cpp installed — follow the install script or download a prebuilt package from the official README, or follow the guide at llama.app; a model in GGUF format, pulled straight from Hugging Face with llama cli -hf, for example ggml-org/Qwen3.5-0.8B-GGUF; and a record sheet for each parameter set's speed, VRAM use, and answer quality.

Before you start, confirm two things: how much VRAM and memory the machine has free, because that decides how many layers can go on the GPU and how large the context can be; and a fixed prompt set covering question answering, code, and multi-turn conversation. Do not change the prompts during testing, or the results cannot be compared.

Step by Step

First, get the server running. Start a local service with llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF. According to the official README, it offers an OpenAI-compatible API and includes a built-in chat app, Llama Chat, so you can open it and check whether the model answers normally. Do not tune anything yet; record the default behavior as the baseline.

Then tune the GPU layers. -ngl sets how many model layers at most are stored in VRAM; the official default is auto, which adapts to available VRAM. When VRAM runs short and the service will not start, set an exact number and lower it — for example -ngl 20 — then raise it step by step until VRAM is just full. On a CPU-only run, do not worry about this parameter; getting it running comes first.

Next, tune context and batching. -c sets the prompt context size and defaults to what the model loads; when multi-turn conversation keeps losing context, raise it, for example to -c 8192, and check whether VRAM still holds. -b and --ubatch-size control the logical and physical batch sizes, with official defaults of 2048 and 512; when prompt processing is slow, try raising them and measure whether speed improves.

Then tune the sampling parameters. --temp defaults to 0.80, --top-p to 0.95, --top-k to 40, and --min-p to 0.05, all as listed in the official server documentation. Lower the temperature first for coding and reasoning work and raise it for creative writing; change only one parameter at a time, then run the fixed prompt set twice to see whether the answers stay stable.

Finally, tune the KV cache types. -ctk and -ctv set the data types for the key and value caches, both defaulting to f16 in the official docs. When VRAM is tight, try q8_0 so the cache uses less VRAM, then test whether long conversations get worse. Write the full parameter set into the record sheet, then pull the same model at different quantization levels in Ollama for one more comparison, confirming this set is the one that is enough on your machine.

Common Problems and Fixes

Problem one: the service will not start, or it reports out-of-memory as soon as it runs. Check -ngl and the model size first — lower the layer count or switch to a smaller quantization level. Then check whether -c is set too large: every doubling of context grows the cache memory too. Problem two: speed measurements differ every time. Generation speed is affected by background processes and heat, so close unused programs during testing, let the machine cool down between parameter sets, and average several runs.

Problem three: long multi-turn conversations forget earlier turns. Check whether -c is large enough first, then whether the KV cache type was squeezed too hard. If both look fine, consider a larger context or a smaller model. Problem four: answers vary from run to run, and it is unclear whether the parameters or the prompts are to blame. Fix the prompts and sampling parameters, repeat the key questions, and only compare repeated results for the same question.

Things to Watch Out For

A note on figures: parameter names and defaults in this guide follow the official llama.cpp server documentation as of November 21, 2026 — the repository changes over time, so the official pages are the reference. Speed and quality vary by machine, so this guide gives no universal benchmark scores; test on your own machine. llama.cpp is free under the MIT license, and Ollama is a free download whose local prompts are never stored or used for training. When pulling model files from Hugging Face, only use repositories from sources you trust.

These steps were checked against the official pages on November 21, 2026. If platform rules change, the official pages are the reference.

Tools mentioned

AI Infrastructure · Free tier + paid — Ollama is the easiest way to run and build with open AI models locally or in the cloud on macOS, Windows, and Linux.
Coding & Development · Free — Local LLM inference engine, creator of the GGUF format, runs on CPU/GPU, and includes an OpenAI-compatible server.

Sources

This article is compiled from the public sources above and does not reproduce the originals in full; see the official sources for details.

Sign in to Lumo

Sign in with a one-time code sent to your email — no password. Your saved tools will sync across your devices.

The code is only used to sign you in. We store just your email and saved list (privacy policy, in Chinese).

—

Signed in. Your saved tools sync across all your devices.

0saved
View saved tools

Send feedback

Found a mistake, missing something, or have a suggestion? Tell us.