Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Local inference | Running a model on your own laptop, workstation or device, usually for one user. |
| Edge device | A computer away from the data centre: a phone, a car, a factory controller, a camera. |
| Unified memory | One pool of memory shared by CPU and GPU (Apple Silicon, NVIDIA GB10). The GPU can use most of the machine’s RAM. |
| GGUF | llama.cpp’s single-file model format: weights, tokenizer and metadata together, quick to load. |
| Quantization | Storing weights in fewer bits (8, 4, even 2) to save memory and bandwidth, at some cost in quality (10.l). |
| Offload | Putting part of a model on the GPU and the rest on the CPU when it does not all fit. |
| NPU | Neural processing unit: a small, power-efficient AI accelerator in phones and laptops. |
| MoE | Mixture of experts: a model that uses only a few of its sub-networks (“experts”) for each token (14.g). |
1. What is it?#
Not every model runs in a data centre. Laptops, workstations, phones, cars, factory machines and browsers run models too, usually for one user at a time, on hardware with limited memory and no data-centre GPU. The engines built for this differ from vLLM and SGLang because the problem differs.
This lesson covers the main local and edge engines (llama.cpp, Ollama, LM Studio, MLX) and the local modes of the data-centre engines: what each optimises for and how to choose. 7.f covers the hardware they run on.
Versions on 12 November 2026: llama.cpp build b12302, Ollama v0.40.16, LM Studio 0.4.26, MLX v0.32.4, mlx-lm v0.32.2, vllm-metal v0.33.0. Facts checked on 12 November 2026.
2. Why does it exist?#
Four reasons people run models locally:
- Privacy and data control. The data never leaves the device.
- Latency and offline use. No network round trip; works on a plane or a factory floor.
- Cost. Hardware you already own has no per-token bill.
- Development. Engineers test prompts, agents and fine-tunes on a laptop before deploying.
The constraints flip compared with the data centre:
| Data centre | Local / edge | |
|---|---|---|
| Users per engine | hundreds to thousands | usually one |
| Goal | throughput at a latency target, cost per token | fast single-user decode, low memory, easy install |
| Memory | 80–288 GB of HBM per GPU | 8–128 GB, often shared between CPU and GPU |
| Bandwidth | 3–22 TB/s | 0.1–1.8 TB/s |
| Hardware | a few kinds of NVIDIA or AMD GPU | everything: x86 and Arm CPUs, Apple Silicon, consumer GPUs, NPUs, phones |
With one user, batching barely helps, so decode speed is set almost entirely by memory bandwidth (2.e). The one big lever left is reading fewer bytes per token: aggressive quantization.
3. Simple analogy#
A data-centre engine is a bus company: it wins by filling every seat on every trip. A local engine is a bicycle: one rider, and what matters is that it is light, fits where you are, and starts the moment you get on.
4. Tiny example: the arithmetic of local decode#
With one user, every generated token reads all the active weights once:
tokens per second ≈ memory bandwidth ÷ bytes of weights read per token| Machine (approximate bandwidth) | 8B model, 4.5 bits/weight (~4.5 GB) | 70B model, 4.5 bits/weight (~40 GB) |
|---|---|---|
| Laptop CPU, dual-channel DDR5 (~80 GB/s) | ~18 tok/s | ~2 tok/s |
| Apple M-series Max (~400–600 GB/s) | ~90–130 tok/s | ~10–15 tok/s |
| RTX 5090 (~1.8 TB/s, 32 GB) | ~400 tok/s | does not fit |
| DGX Spark / GB10 (~273 GB/s, 128 GB unified) | ~60 tok/s | ~7 tok/s |
These are ceilings; real engines reach roughly 60–85% of them. Two conclusions:
- Unified-memory machines (Apple Silicon, GB10) run models that do not fit in a consumer GPU, at moderate speed.
- Consumer GPUs are fast but small. A model that spills from GPU memory into system RAM slows to near the CPU line.
MoE models change the arithmetic in local inference’s favour. A model with 35B total parameters and 3B active reads only the active experts for each token, so it decodes like a 3B model, as long as all 35B fit in memory. That is why MoE models such as Qwen3.5-35B-A3B are popular on Macs.
5. Technical explanation#
llama.cpp#
llama.cpp (from the ggml-org project) is the foundation of most local inference. It is a C/C++ engine with no Python dependency, and it runs nearly everywhere: x86 and Arm CPUs, NVIDIA (CUDA), AMD (HIP), Apple (Metal), Intel and others (SYCL, Vulkan). It ships continuously, as numbered builds, several a day.
What makes it the default for local use:
GGUF, a single-file, memory-mappable format, so a model starts in seconds.
A family of quantization formats designed for CPU and small-GPU decode:
Format Bits per weight (approx.) Use Q8_08.5 near-lossless reference Q6_K6.6 very close to FP16 Q5_K_M5.7 high quality Q4_K_M4.8 the usual default: good quality, about half the size of Q8 IQ3_XS,IQ2_*2–3.5 when the model otherwise does not fit; noticeable quality loss The
Kformats quantize weights in blocks with per-block scales, the same idea as group-wise quantization in 10.l, laid out for fast unpacking on CPUs. TheIQformats use an importance matrix measured on sample text to spend bits where they matter.Partial offload.
--n-gpu-layersputs as many layers on the GPU as fit and runs the rest on the CPU, so a model larger than GPU memory still runs (slowly).llama-server, an OpenAI-compatible HTTP server with a few parallel slots (continuous batching for a handful of users), prefix caching, speculative decoding and grammar-constrained output.
# download a GGUF model from Hugging Face and serve it on port 8080
llama-server -hf <org>/<model>-GGUF:Q4_K_M --n-gpu-layers 999 --ctx-size 16384 --port 8080
curl http://localhost:8080/v1/chat/completions -d '{"messages":[{"role":"user","content":"hi"}]}'It is not built for many-user throughput: no paged KV cache across hundreds of requests and no tensor parallelism across a cluster. For that you use vLLM or SGLang.
Ollama#
Ollama packages local inference as a product: a background service, a model registry
(ollama pull), a CLI and an OpenAI-compatible API on localhost:11434. It is written in Go and
runs models through engines:
- llama.cpp (ggml) for GGUF models, on every platform.
- MLX on Apple Silicon, in preview since 30 March 2026 (Ollama 0.19) and developed since. Ollama’s own launch benchmark showed decode roughly doubling (58 to 112 tokens per second on Qwen3.5-35B-A3B, NVFP4 on MLX against Q4_K_M on the old path); treat that as a vendor figure. The MLX path also runs NVFP4 checkpoints, so a model quantized for the data centre runs unchanged on a Mac.
Ollama’s value is operational: one command to install, models that “just work”, sensible defaults. The cost is control: fewer knobs and a layer between you and the engine.
LM Studio#
LM Studio is a desktop application (macOS, Windows, Linux) with a model browser, a chat
interface and a local OpenAI-compatible server, plus the lms command-line tool. It runs
llama.cpp for GGUF models and MLX on Apple Silicon. It suits people who want a graphical tool;
the engines underneath are the same ones above.
MLX and Apple Silicon#
MLX is Apple’s array framework for Apple Silicon, with mlx-lm for language models. Apple’s chips have unified memory and high bandwidth, which makes them good single-user inference machines (7.f). MLX uses the GPU through Metal, has its own quantized formats, and on M5-generation chips uses the GPU’s neural accelerators to speed up prefill.
For several users sharing one Mac (a small team on one Mac Studio, or several coding agents on one laptop), vllm-metal, announced by the vLLM project on 22 September 2026, brings vLLM’s paged KV cache and continuous batching to Apple Silicon on top of MLX, so latency stays flat as concurrent requests are added.
6. Under the hood: the data-centre engines, locally#
The big engines increasingly run on small machines too:
- vLLM runs on consumer NVIDIA GPUs, on Arm and x86 CPUs, on Apple Silicon through vllm-metal, and on DGX Spark / GB10 with NVFP4 checkpoints.
- SGLang v0.5.23 added an opt-in “paged experts” mode that runs MoE models larger than GPU memory on a single consumer GPU (a project claim of up to 30x over CPU offload).
- TensorRT-LLM has beta support for single-node DGX Spark (since v1.2), and NVIDIA’s packaged containers target RTX PCs, workstations and Jetson edge modules.
- ONNX Runtime GenAI and vendor runtimes (Qualcomm QNN, Intel OpenVINO, Apple Core ML) target the NPUs in laptops and phones (15.d).
- ExecuTorch (PyTorch) targets phones and embedded devices; WebLLM and other WebGPU runtimes run models inside a browser.
The trade-off is the usual one: a data-centre engine gives you the same behaviour locally as in production, at the price of a heavier install.
7. Performance implications#
- Bandwidth, then size. Faster memory or a smaller (more quantized, or MoE) model are the only big decode levers. Compute rarely limits single-user decode.
- Prefill is compute-bound even locally. A 20,000-token prompt on a laptop can take tens of seconds before the first token. Agents and RAG feel this most; that is what Apple’s M5 neural accelerators and NPUs help with.
- Context costs memory. A 32k context on an 8B model adds several GB of KV cache. Set
--ctx-sizeto what you need, and quantize the KV cache if the engine supports it (13.h). - A few parallel slots help. With 2–4 concurrent requests, total throughput rises nearly linearly, because each weight read now serves several users; per-user speed drops a little.
8. Production implications#
- Quantization quality varies by model.
Q4_K_Mis usually fine for chat and often not for code or maths at small model sizes. Evaluate the quantized model on your task (13.b). - Pin model files, not just names. A tag such as
model:latestin a registry can change under you. Record the file hash. - Local endpoints are servers. An Ollama or llama.cpp port exposed to a network is an unauthenticated model API. Bind to localhost or put authentication in front (23.i).
- Fleet devices need updates. An engine shipped inside an app or a device has to receive security fixes; plan the update path.
9. Common mistakes#
- Comparing local tokens per second without fixing the quantization and context length.
- Expecting a 70B dense model to be usable on a 16 GB laptop. It runs from swap, at a token every few seconds.
- Using a local engine for multi-user production serving. It works until the second user arrives; continuous batching with a paged KV cache is what data-centre engines are for.
- Ignoring prefill time when testing with short prompts, then deploying an agent with long ones.
- Exposing
localhost:11434to the network “just for testing”.
10. Hands-on exercise#
- Measure your machine’s memory bandwidth (for example with a STREAM-style benchmark), then
predict the decode speed of an 8B model at
Q4_K_Musing section 4. Run it with llama.cpp and compare. - Run the same model at
Q8_0,Q4_K_Mand anIQ3format. Plot tokens per second against file size. Is the relationship close to linear? Why? - Start
llama-serverwith 4 parallel slots and send 1, 2 and 4 concurrent requests. How does per-request speed change, and why does total throughput rise? - On a Mac, run one model through Ollama’s llama.cpp path and its MLX path. Compare time to first token on a 10,000-token prompt and decode speed.
11. Interview questions#
- Why does batching help much less for local inference than in a data centre?
- Estimate the single-user decode speed of a 14B model at 4.5 bits per weight on a machine with 500 GB/s of memory bandwidth.
- Why do MoE models suit unified-memory machines?
- What does partial GPU offload in llama.cpp do, and what limits its speed?
- When would you run vLLM (or vllm-metal) rather than Ollama on a developer’s machine?
12. Further reading#
Checked on 12 November 2026.