---
title: "Inference Engines, Explained: What Actually Runs Your AI Model"
author: "Ecem Karaman"
source: "https://aiwithecem.com/guides/inference-engines"
published: 2026-11-14
tools: ["Multi-Tool"]
topics: ["Building"]
---

# Inference Engines, Explained: What Actually Runs Your AI Model

A model is a big file of numbers. Something has to load it, take requests from many people at once, manage memory and produce answers one token at a time, as fast and cheaply as the hardware allows. That something is an inference engine. Here's what the four best-known ones optimize for, how to pick one, and what the same ideas mean for your Claude bill.

**Details checked against the [vLLM paper](https://arxiv.org/abs/2309.06180), the [SGLang paper](https://arxiv.org/abs/2312.07104), the [llama.cpp](https://github.com/ggml-org/llama.cpp), [vLLM](https://github.com/vllm-project/vllm) and [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM) repositories, and Claude's [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) and [batch](https://platform.claude.com/docs/en/build-with-claude/batch-processing) docs on November 14, 2026.**

> **In this guide**
>
> 1. [What an inference engine does](#what-an-inference-engine-does)
> 2. [The two things that fill memory](#the-two-things-that-fill-memory)
> 3. [llama.cpp: run big models on the hardware you have](#llamacpp-run-big-models-on-the-hardware-you-have)
> 4. [vLLM: serve many users without wasting memory](#vllm-serve-many-users-without-wasting-memory)
> 5. [SGLang: stop recomputing the same start of every prompt](#sglang-stop-recomputing-the-same-start-of-every-prompt)
> 6. [TensorRT-LLM: get the most out of Nvidia GPUs](#tensorrt-llm-get-the-most-out-of-nvidia-gpus)
> 7. [Pick one](#pick-one)
> 8. [What this means when you use Claude](#what-this-means-when-you-use-claude)
> 9. [Start here](#start-here)

## What an inference engine does

```animation-inference-1
```

Training builds the model. Inference is everything after: every time you send a prompt, the model runs and generates its answer one token at a time, and each new token depends on all the tokens before it.

General-purpose tools like PyTorch can run a model, but they weren't built for that token-by-token pattern at scale. Inference engines specialize in it. They decide which requests run together, where memory goes, how compressed the model is and which GPU code runs. Most of the well-known engines appeared in 2023, once large language models made those decisions worth optimizing.

## The two things that fill memory

Almost every trick below is about memory. Two things compete for it:

| | Model weights | KV cache |
| --- | --- | --- |
| **What it is** | The trained numbers that make up the model | Saved intermediate results for every token so far, so the model doesn't recompute them |
| **Size** | Fixed for a given model and precision | Grows with every token, in every conversation, for every user |
| **Rough example** | 7 billion parameters at 16 bits each is about 14 GB; at 4 bits, about 3.5 GB | Small for one short chat, huge for long chats with many users |

The weights decide whether a model fits at all. The KV cache decides how many people you can serve at once.

```animation-inference-2
```

## llama.cpp: run big models on the hardware you have

**The problem it solves:** big models assume a big GPU, and most people don't have one.

- **Quantization.** It supports 1.5-bit up to 8-bit integer versions of models, which shrink the weights and speed things up at some cost to quality.
- **CPU and GPU together.** If a model is bigger than your GPU memory, it can run part of it on the GPU and the rest on the CPU.
- **Memory mapping.** By default it maps the model file into memory and lets the operating system load pieces as they're needed, instead of copying the whole model up front.
- **Runs almost anywhere.** It's designed for minimal setup, and Apple silicon is a first-class target.

**Best for:** running a model on your own laptop or desktop, offline or for privacy.

## vLLM: serve many users without wasting memory

**The problem it solves:** older serving systems reserved KV cache memory for each request's maximum possible length. Most of that space sat empty. The vLLM paper found only 20.4% to 38.2% of KV cache memory actually held tokens.

- **PagedAttention.** It splits the KV cache into small fixed-size blocks and hands them out as a conversation grows, the way an operating system pages memory. Waste drops to near zero, so more requests fit at once.
- **Continuous batching.** New requests join the batch as soon as others finish, instead of waiting for the whole group.

The paper reported 2 to 4 times the throughput of earlier systems at the same latency, with bigger gains for longer conversations and larger models.

**Best for:** serving an open model to many users on your own GPUs.

## SGLang: stop recomputing the same start of every prompt

**The problem it solves:** many prompts start the same way, with the same system prompt, examples or chat history. Recomputing that shared start for every request wastes work.

- **RadixAttention.** It keeps the KV cache for prompt beginnings in a tree, so any request that starts the same way reuses the stored work. When memory fills up, it evicts the least recently used branches first.
- **Faster structured output.** It also speeds up responses that must follow a format, like JSON.

The SGLang paper reported up to 6.4 times the throughput of other systems, on workloads like agents, multi-turn chat and retrieval. "Up to" matters here: the gain depends on how much your prompts share.

**Best for:** agents and chat apps where many requests share a long prompt beginning.

## TensorRT-LLM: get the most out of Nvidia GPUs

**The problem it solves:** squeezing maximum performance from specific hardware.

Nvidia's library combines specialized GPU code for common operations with an efficient runtime and a Python framework you can extend. Because Nvidia makes the chips too, it can tune for them closely.

**Best for:** teams already on Nvidia GPUs who want peak performance and can handle more setup.

**They overlap more now.** These engines started with different priorities, but the serving engines borrow each other's best ideas. vLLM now lists prefix caching alongside PagedAttention and continuous batching, for example. Choose on your hardware and workload, not on one headline feature.

## Pick one

| Your situation | Start with | Why |
| --- | --- | --- |
| Running a model on your laptop or Mac | llama.cpp | Small quantized models, runs on CPU and Apple silicon |
| Serving an open model to many users | vLLM | Memory efficiency and throughput |
| Agents or chats with long shared prompts | SGLang | Reuses the shared start of prompts |
| Production on Nvidia GPUs, maximum speed | TensorRT-LLM | Tuned for Nvidia hardware |
| You use Claude or another hosted API | None | The provider runs the engine. You can still use its ideas, below |

## What this means when you use Claude

You never choose Claude's inference engine. Anthropic runs it. But three API features expose the same ideas, and they change what you pay:

| Engine idea | Claude feature | What to do |
| --- | --- | --- |
| Reuse the shared start of prompts | **Prompt caching.** Cache reads cost 0.1x the normal input price: 0.05x on Opus 5.5 and Sonnet 5.5, 0.025x on Fable 5.2 | Put what stays the same first: tools, then the system prompt, then messages |
| Let the provider schedule the work | **Message Batches API.** 50% off, and most batches finish in under an hour | Send anything that isn't urgent as a batch |
| Pay more for speed | **Fast mode** on Fable 5.2: up to 2.5x faster at twice the price | Use it only when someone is waiting |

Cache entries last 5 minutes by default and refresh each time they're used. A cached prompt only helps if the next request starts the same way, so a timestamp at the top of your system prompt quietly breaks it.

## Start here

- [ ] **Try one locally.** Install llama.cpp from [its official site](https://llama.app), then run `llama cli -hf ggml-org/Qwen3.5-0.8B-GGUF` to download and chat with a small model
- [ ] **If you use the Claude API:** move tools and the system prompt to the front, turn on prompt caching, and check that cache reads show up in your usage
- [ ] **For the clearest explanation of the KV cache problem,** read the introduction of the [vLLM paper](https://arxiv.org/abs/2309.06180)

**Go deeper:** [Claude prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) · [SGLang paper](https://arxiv.org/abs/2312.07104) · [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM) · [Fable 5.2 vs Gemini 4 Carbon](/guides/fable-5-2-vs-gemini-4-carbon)
