deep · 6 min
Local models
Running an open model on your own machine: the file, the engine, the memory it needs and the speed you get.
updated 29 Sept 2026
Here's a bug that's easy to walk into. Say we build a little chat-with-your-documents app on a laptop, with an open model running locally. The first few questions go fine. Then, a few turns in, the answers get vague. The model seems to forget what was said at the start. No error anywhere. The API returns 200 every time.
We'll come back to what's going on. To see it, we need to know what "running a model locally" actually involves, so let's build it up from the file on disk.
A file, an engine, a server
First you need weights you're allowed to download, which means an open-weights model. Let's use Llama 3.1 8B.
The file. Models are trained in something like PyTorch, then converted
for local use. The engine we'll use, llama.cpp, wants a GGUF file: one
file holding the weights plus everything needed to load them, written so
it can be mapped straight into memory and loaded fast. The name tells you
what's inside. Llama-3.1-8B-Instruct-Q4_K_M.gguf is the model, its
size, the fine-tune, and the encoding, which is how many bits each weight
got squeezed into. That last part is quantization, and it decides most
of what follows. (Models that see images ship the image part as a second
file starting with mmproj.)
The engine. llama.cpp is plain C/C++ with no dependencies. It runs on Apple's Metal, NVIDIA's CUDA, AMD's HIP, Vulkan and plain CPUs, and it can split a model between GPU and CPU when the model is too big for the GPU.
The server. Your app talks to the engine over HTTP. llama serve -hf <repo> downloads a GGUF from Hugging Face and starts a server that
speaks the OpenAI API, in one command. Ollama wraps the same idea with a
model manager and a server on localhost:11434. The examples below use
those two because their docs are open and specific; we didn't find a
neutral comparison of the local tools, so we won't rank them.
Will it fit?
Before speed, the model has to fit in memory. Two things take space.
The weights are a fixed cost. Llama 3.1 8B at 16 bits is a 14.96 GiB
file; at 4 bits (Q4_K_M) it's 4.58 GiB. For the 70B model at 4 bits,
llama.cpp lists 43.1 GB. So the 8B fits on a lot of laptops, and the 70B
needs a serious machine before it has stored a single token of
conversation.
The KV cache is the other part, and it grows with the context window. Every token of context you allow reserves room for its keys and values. Ask for a longer window, use more memory. Serve requests in parallel and it multiplies: in Ollama, a 2K context with 4 parallel requests takes the memory of an 8K one. You can shrink the cache by storing it in fewer bits too; at 8 bits it's about half the size with a very small loss, at 4 bits about a quarter, with a loss that shows more on long contexts.
And if it doesn't fit? The engine puts some layers on the CPU and in
system RAM. It still runs, just slower. ollama ps shows the split,
something like 48%/52% CPU/GPU. Ollama's own advice is to keep the
model fully on the GPU if speed matters.
How fast will it be?
Remember prefill and decode: the model reads the whole prompt in one go, then writes one token at a time. Writing each token means reading every weight once from memory. So you'd guess decode speed depends on how fast memory can be read, more than on how fast the chip does math. Let's check that guess.
People have been running the same test on Apple chips for years, same model (Llama 2 7B), same 2023 build of llama.cpp. Here's generation speed at 4 bits against each chip's memory bandwidth:
The guess holds. And here's the cleanest proof: two M2 Ultras with the same 800 GB/s of bandwidth, one with 60 GPU cores and one with 76. The extra cores made reading the prompt 24% faster, and generating only 3% faster.
You can even work out a ceiling yourself. The 16-bit version of that model is about 13.5 GB. Reading 13.5 GB at 800 GB/s takes about 17 milliseconds, so the best you could hope for is about 59 tokens a second. It measured 41. Under the ceiling, as it should be, since real code never gets the full bandwidth.
These are community numbers from one old build, so treat them as the shape, not a prediction. The same M2 Ultra went from 94 to 109 tokens a second at 4 bits a year later, just from software updates.
Prefill is the other half, and it follows the cores. It matters when prompts are long, like in retrieval apps. On a base M1, the prompt was read at about 118 tokens a second. So a 4,000-token prompt would take over half a minute before the first word appears. On the M2 Ultra, about 3 seconds. That wait is your time to first token, and on small machines it's often what people notice most.
Calling it from code
Both servers speak the OpenAI API format, so existing code often works
after changing one line. With the OpenAI SDK and Ollama, you set the base
URL to http://localhost:11434/v1/ and pass any string as the API key
(the SDK needs one, Ollama ignores it).
Compatible isn't identical, though. As of 2026-09, Ollama's chat endpoint
in that format doesn't support logprobs, or tool_choice (so you can
offer tools but can't force one), or image URLs (send
base64 instead). If your code leans on one of those, test it rather than
assuming.
And there's one more default worth knowing: Ollama unloads a model after
5 minutes idle, so the next request waits while it loads again.
keep_alive set to -1 keeps it in memory.
Back to the forgetful chat
So, what happened to our app? A model might support 128K tokens of context, but the server decides how much it actually allocates, and the default is small. Ollama's FAQ says 4,096 tokens.
Our chat sends the whole conversation each turn, with retrieved chunks added. After a few turns it's longer than 4,096 tokens. What does the server do?
According to a bug report filed on the Ollama repo in 2026-02 (still open when we read it), it drops the oldest messages from the front. The API response says nothing about it. The only trace is a debug-level log line. The embeddings endpoint quietly cuts long inputs by default too. So the model answers without the start of the conversation, and the answer just looks worse. That's our bug.
Note this comes from a user's report, not from Ollama's docs, so it could change. And the docs themselves don't agree on the default: 4,096 in the FAQ, a number that depends on GPU memory on another page (4K under 24 GiB, 32K up to 48, 256K above), and 2,048 in a reference table.
So don't trust any of them. Set the context length on purpose (for
code using the OpenAI SDK, that means a Modelfile with
PARAMETER num_ctx 16384 and ollama create, or OLLAMA_CONTEXT_LENGTH
for the whole server). Then check the CONTEXT column in ollama ps to
see what you actually got. Ollama suggests at least 64,000 tokens for
agents and coding tools, and the KV cache from earlier is what pays for
it. Counting your own prompt tokens and failing loudly when they don't
fit is the only way to be sure the model sees what you sent.
Further reading
- llama.cpp, ggml-org. The engine: what hardware it runs on, the CPU and GPU split, and the one-line server.
- GGUF, ggml-org. The file format spec, and how to read a model's file name.
- llama.cpp quantize README, ggml-org. Sizes and speeds for Llama 3.1 at every bit width.
- Performance of llama.cpp on Apple Silicon M-series, Georgi Gerganov and contributors, 2023, still updated. The bandwidth numbers. Find your chip in the table.
- FAQ, Ollama docs. Context size, GPU and CPU split, keep-alive, parallel requests, cache in fewer bits.
- Context length, Ollama docs. How the default is picked, and how to check what you got.
- OpenAI compatibility, Ollama docs. Pointing existing SDK code at a local model, and what doesn't work.
- Chat history and embedding truncation happens silently, GitHub issue, 2026. The bug report behind the forgetful chat. Worth a read before you ship anything on Ollama.