The journey of one answer
Between pressing Enter and seeing the first word, your question crosses oceans, becomes numbers, wakes up billions of weights and comes back one token at a time. Here is every step, and the simple rule that sets the speed.
You type a question and press Enter. Perhaps half a second later, the first word appears. Then the rest of the answer flows out, word by word, faster than you can read it.
In that half-second, a remarkable amount happens. Your question leaves your device as encrypted light and radio, crosses cities and perhaps oceans, lands in a data centre, is cut into tokens, is turned into numbers, and passes through billions of weights on a GPU that was made from purified sand. Every chapter of this book is quietly at work.
This chapter follows one answer from start to finish. Along the way we will meet the handful of ideas that decide how fast and how cheap an AI answer can be, and we will learn to work out a model's speed on the back of an envelope.
Training and inference are different jobs
Chapter 14 was about training: the long, expensive process that finds the weights. It happens once for each model version, on a large cluster, over weeks or months.
Inferenceusing a trained model to produce answers; the model's weights stay fixed is what happens afterwards. It uses the finished weights to answer questions, and it happens every time anyone sends a message. A popular model runs inference billions of times a day. Over a model's life, all that inference can use more computing than the original training did.
| Property | Training | Inference |
|---|---|---|
| Purpose | Find the weights | Use the weights |
| How often | Once for each model version | Every question, all day |
| Hardware | 10,000 to 100,000+ GPUs together | From one GPU to a few racks for each copy of the model |
| Main limit | Arithmetic and network | Memory size and memory speed |
| Arithmetic for each token | about 6 × parameters | about 2 × active parameters |
The journey of one answer
You type "Explain how a transistor works" into a chat window. Here is what happens next.
YOUR DEVICE INTERNET DATA CENTRE
┌──────────┐ HTTPS (encrypted) ┌───────────────┐ ┌─────────────────────────────────────┐
│ 1. You │──────────────────────►│ 2. Load │──►│ 3. Inference server │
│ type the │ undersea cables, │ balancer │ │ │
│ question │ fibre, mobile towers │ (chooses a │ │ 4. Tokenizer: text → token IDs │
└──────────┘ │ free server) │ │ │ │
▲ └───────────────┘ │ ▼ │
│ │ 5. PREFILL: GPU reads all prompt │
│ │ tokens at the same time │
│ │ (limited by arithmetic) │
│ │ │ │
│ │ ▼ │
│ │ 6. DECODE LOOP, one token per step │
│ │ ┌─► read weights from memory ─┐ │
│ │ │ calculate probabilities │ │
│ │ │ 7. SAMPLING: choose token │ │
│ │ └── add token to the text ◄───┘ │
│ │ (limited by memory speed) │
│ │ │ │
│ 9. STREAM: words appear one by one │ 8. Detokenizer: token IDs → text │
└─────────────────────────────────────────────────┴────────────┘ │
└─────────────────────────────────────┘Step 1. You type the question
Your phone or laptop wraps your text in a message. It adds the earlier messages of the conversation, because the model has no memory of its own between requests. A chat service usually adds a system prompthidden instructions, written by the service, that are sent to the model along with every conversation too.
Step 2. The message crosses the internet
Your device encrypts the message with HTTPSthe secure version of the web's basic protocol; it scrambles the message so only the destination can read it. It travels as radio to a mobile tower or as light down a fibre, through internet exchangesbuildings where many networks plug into each other to swap traffic and often through undersea cables. At the data centre, a load balancera traffic director that sends each incoming request to a server with spare capacity passes it to a server that has room.

Step 3. The inference server takes the request
The inference serverthe software that receives requests, queues them, groups them and runs the model on the GPUs puts your request in a queue alongside other people's, and decides which requests go to the GPUs together. More on that clever grouping below.
Step 4. The tokenizer turns text into token IDs
The tokenizer cuts your text into tokens (chapter 14). "Explain how a transistor works" becomes about six tokens, and each becomes an ID number.
Step 5. Prefill: the model reads the whole prompt
In prefillthe first phase of an answer, in which the GPU processes every prompt token at once, the GPU processes all the prompt tokens at the same time. A prompt can be long: the system prompt, a pasted document, the whole conversation so far and finally your question.
Prefill is limited by arithmetic. The GPU reads each weight once but uses it for every prompt token, so it does a lot of calculation for each byte it fetches. That keeps its calculating units busy. Prefill produces the first output token and fills the KV cache, which we will meet shortly.
The wait from pressing Enter to seeing the first word is the time to first tokenTTFT: how long you wait between sending a request and seeing the first token of the answer. For chat it is typically somewhere between 0.2 and 2 seconds.
Step 6. The decode loop: one token for each step
Now the model writes its answer, and it can only write one token at a time, because each new token depends on the ones before it. For every token, the GPU must:
- Read all the active weights from GPU memory.
- Read the KV cache for this conversation.
- Calculate the probabilities for the next token.
This decodethe second phase of an answer, in which the model writes one token at a time phase is limited by memory speed, also called memory bandwidthhow many bytes per second can flow between memory and the processor. For each byte it reads, the GPU does only a tiny amount of calculation, so its calculating units spend most of their time waiting for data to arrive.
Picture a brilliant chef who can cook any dish in seconds. But for every single plate, an assistant has to fetch every ingredient from a storeroom at the far end of the building. The number of plates per hour depends on how fast the assistant can walk, not on how fast the chef can cook. In decode, the GPU is the chef and memory is the storeroom.
Step 7. Sampling: choose the next token
The model produces a probability for every token in its vocabulary. Samplingchoosing one token from the model's list of probabilities picks one.
- At a temperaturea setting that controls how adventurous sampling is; zero always picks the most likely token of 0, the model always takes the most likely token, and the answer is the same every time.
- At a higher temperature, it sometimes takes less likely tokens, and the answers become more varied and creative.
The chosen token is added to the text, and the loop goes round again, until the model writes a special "stop" token or reaches a length limit.
Step 8. The detokenizer turns IDs back into text
Each token ID becomes text again, for example " transistor".
Step 9. Streaming to your screen
The server sends each token to your device the moment it is ready, which is why answers appear word by word. Somewhere between 30 and 100 tokens per second for each person feels comfortable; most people read much more slowly than that. A reasoning model may first write thousands of tokens of working before its visible answer, and those tokens take time and computing too.
The KV cache: the memory of the conversation
In attention, each new token looks back at all the earlier ones (chapter 14). It would be wasteful to recalculate everything about the earlier tokens every time. So the model saves two lists of numbers for every earlier token, in every layer, called the "keys" and the "values." This store is the KV cachethe saved keys and values for every earlier token in a conversation, kept in GPU memory so they need not be recalculated.
The KV cache grows with every token, and it stays in GPU memory for every person currently being served.

How big does it get? For a typical 70-billion-parameter dense model such as Llama 3 70B, each token of conversation needs about a third of a megabyte. A long conversation of 32,000 tokens needs about 10 GB. A hundred people having conversations that long need about a terabyte, more than the model's own weights.
Go deeper: the KV cache sum for Llama 3 70B
Llama 3 70B has 80 layers, and each layer keeps 8 key-value "heads" of 128 numbers each.
| Item | Calculation | Result |
|---|---|---|
| KV cache for each token | 2 (K and V) × 80 layers × 8 heads × 128 numbers × 2 bytes | about 0.33 MB |
| One conversation of 32,000 tokens | 0.33 MB × 32,000 | about 10.5 GB |
| 100 people at 32,000 tokens each | 10.5 GB × 100 | about 1 TB |
Long documents and many users fill GPU memory fast. That is why model designers work so hard to shrink the cache. DeepSeek's multi-head latent attention, introduced in 2024, compresses keys and values into a much smaller form, and the original paper reported a cache more than 90% smaller than its predecessor's. Ideas like this are some of the most valuable in the whole field right now.
Batching: many users share one read of the weights
In decode, the GPU reads all the active weights for every token. If it serves just one person, it fetches gigabytes of weights to produce a single token, then does it all again for the next one. That is a waste of a superb machine.
Batchingprocessing the next tokens of many users in one step, so one read of the weights serves them all fixes it. The GPU gathers the next token of many people into one step, reads the weights once and uses them for 32, 64 or more people at the same time.
| Batch size | Weight reads for each step | Tokens for each step | Effect |
|---|---|---|---|
| 1 person | 1 | 1 | Fast for that person, but the GPU is mostly idle |
| 32 people | 1 | 32 | Each person is a little slower; total output is far higher |
| 256 people | 1 | 256 | Arithmetic starts to become the limit; the KV cache needs lots of memory |
A refinement called continuous batchingadding and removing users from the batch at every step, so nobody waits for anybody else to finish lets people join and leave the batch at every step, so nobody waits for a long answer to finish. The open-source vLLM project made this approach popular in 2023, and it is now standard.
Batching is the quiet reason AI answers are cheap. One GPU serves many people at once, and the cost of reading the weights is shared among all of them.
Quantization: smaller numbers, less memory, more speed
Quantizationstoring each weight in fewer bits, for example 4 instead of 16 stores each weight in fewer bits (chapter 4). It brings two gifts at once:
- The model needs less memory.
- The GPU reads fewer bytes for each token, so decode gets faster.
| Format | Bytes for each weight | Memory for a 284B model | Quality loss |
|---|---|---|---|
| BF16 | 2 | about 570 GB | none (the reference) |
| FP8 | 1 | about 284 GB | very small |
| 4-bit (NVFP4, MXFP4, GGUF Q4) | about 0.55 | about 156 GB | small for most tasks |
| 2- to 3-bit | about 0.3 to 0.4 | about 85 to 115 GB | can be noticeable |
NVIDIA's Blackwell GPUs include special hardware for 4-bit numbers, and many labs now publish official 4-bit versions of their models, or train with low precision from the start. It is one of the great quiet wins of recent years: models four times smaller that most people cannot tell apart from the originals.
Parallelism: one model on many GPUs
A large model often does not fit on one GPU, so the serving software splits it across several. There are four main ways to do it.
| Type | How it splits the model | Kitchen analogy | Needs |
|---|---|---|---|
| Tensor parallelsplitting each layer across several GPUs so they all work on every token together | Each layer is divided across GPUs; all of them work on every token | Four cooks prepare one dish together | A very fast link between GPUs, such as NVLink |
| Pipeline parallelgiving different layers to different GPUs, like stations on an assembly line | Different layers go to different GPUs | An assembly line, one stage per cook | Less link speed, but more delay |
| Expert parallelplacing different experts of a mixture-of-experts model on different GPUs | Different MoE experts live on different GPUs | Each specialist has their own room | Suits MoE models |
| Data parallelrunning separate full copies of the model, each serving its own users | A full copy of the model on each GPU or group | Two kitchens with the same menu | Enough memory for each copy |
Workstation GPUs connect to each other through PCIe 5, at roughly 64 GB/s in each direction. Data-centre GPUs use NVLink, at 900 GB/s to 1.8 TB/s. So on workstation cards, tensor parallel loses a good deal of speed to the slow link. If a model fits on one card, it is often better to run separate copies, one per card.
Serving software
The software that runs models has improved as dramatically as the hardware, much of it built in the open.
| Software | From | What it is known for |
|---|---|---|
| vLLM | Started at UC Berkeley (2023); now an open project with many contributors | The most widely used open serving software; continuous batching and "PagedAttention," which manages the KV cache like an operating system manages memory pages |
| SGLang | Started by researchers at UC Berkeley and the LMSYS group | Fast serving, especially for complex multi-step programs |
| TensorRT-LLM and Dynamo | NVIDIA | Very fast serving on NVIDIA GPUs |
| llama.cpp | Georgi Gerganov and open-source contributors (2023) | Runs models on ordinary computers, Macs and small GPUs; uses the GGUF file format |
| Ollama | Ollama | A friendly tool built on llama.cpp for one person or a small team |
How to measure inference
| Measure | Meaning | Good value (roughly) |
|---|---|---|
| Time to first token | Wait before the first token appears | under 1 second for chat |
| Tokens per second, per person | Speed of one answer | 30 to 100+ for chat |
| Total throughput | All tokens the system produces each second, for everyone | as high as possible: it sets the cost per token |
| Concurrent users | People served at the same time | depends on memory left for the KV cache |
| Cost for each million tokens | (Hardware + electricity + operation) ÷ tokens | lower is better |
There is always a balance to strike. Big batches give high total throughput and a low cost per token, but each person's answer arrives a little more slowly. Small batches feel snappier and cost more. Every service chooses its own point on that curve.
Worked example 1: gpt-oss-120b on two workstation GPUs
Now for the fun part: working out a real model's speed with nothing but division. Take the office AI box from chapter 13, with two NVIDIA RTX PRO 6000 Blackwell Max-Q workstation GPUs.
The model. gpt-oss-120b has about 117 billion parameters in total but only about 5.1 billion active for each token. Most of its weights are stored in a 4-bit format, and the whole file is about 65 GB.
The hardware. Each card has 96 GB of memory and about 1.8 TB/s of memory bandwidth. Two cards have 192 GB and about 3.6 TB/s in total.
Does it fit? Easily. The weights (about 65 GB) fit on one card, leaving about 30 GB on that card for the KV cache. So the best plan is two separate copies, one per card.
The fastest possible speed for one person. For each token, the card must read the active weights. 5.1 billion parameters, most at 4 bits and some at 16 bits, come to roughly 3.5 GB (an estimate). So:
Upper limit = memory bandwidth ÷ bytes read for each token ≈ 1.8 TB/s ÷ 3.5 GB ≈ 510 tokens per second.
The real speed. Real systems fall short of the limit. The GPU also reads the KV cache, the software has overheads, and nothing starts and stops perfectly. As a rough estimate, real single-person speed lands at about 20% to 50% of the upper limit, so around 100 to 250 tokens per second: several times faster than anyone can read.
With batching, each card can serve many people at once. The box as a whole might produce something like 1,000 to 5,000 tokens per second in total (an estimate), depending on batch size and conversation length.
Worked example 2: DeepSeek V4 Flash on four workstation GPUs
Now a bigger model. DeepSeek V4 Flash (2026) has about 284 billion parameters in total and about 13 billion active for each token.
- Weights at about 4 bits: 284 billion × 0.55 bytes ≈ 156 GB.
- Memory on four cards: 4 × 96 GB = 384 GB.
- Left for the KV cache and software: about 228 GB, plenty of room for many users.
- Bytes read for each token: 13 billion × 0.55 ≈ 7.2 GB.
- Total memory bandwidth across four cards: about 7.2 TB/s, if the model is split so that all four work on every token.
- Upper limit for one person: 7.2 TB/s ÷ 7.2 GB ≈ 1,000 tokens per second.
- Realistic estimate: perhaps 15% to 40% of that, because the cards share data over the slower PCIe link, so roughly 150 to 400 tokens per second.
On only two cards, the weights would still fit, but with little room left for conversations. That is the kind of trade-off the calculator below lets you explore.
A simple rule
Two lines of arithmetic tell you most of what you need:
- Will it fit? Total parameters × bytes per parameter must be less than the GPU memory, with something like 20% to 30% to spare for the KV cache and software.
- How fast can it be? Memory bandwidth ÷ (active parameters × bytes per parameter) gives the upper limit of speed for one person.
Energy for each token, and the electricity bill
How much energy does one token take? Let us estimate it for the two-GPU office box, which uses about 1.1 kW at full load.
| Item | Calculation | Result |
|---|---|---|
| Energy each second | 1.1 kW | 1,100 joules |
| Total throughput (estimate) | 2,000 tokens per second | |
| Energy for each token | 1,100 ÷ 2,000 | about 0.55 joules |
| Energy for 1 million tokens | 0.55 × 1,000,000 ÷ 3,600,000 | about 0.15 kWh |
| Electricity for 1 million tokens, at an assumed USD 0.15 per kWh | 0.15 × 0.15 | about 2 US cents |
| Electricity for a year at full load | 1.1 kW × 8,760 hours ≈ 9,600 kWh | about USD 1,450 |
All of these are estimates built on the assumptions in the table. A 500-token answer, at 0.55 joules a token, would use about 0.08 watt-hours, the same order as the 0.24 Wh that Google measured in 2025 for a median prompt across its entire data-centre fleet, including cooling and idle machines (see the 20-watt brain for that comparison).
For a machine like this, the electricity is cheap compared with the hardware. If such a box cost about USD 40,000 (an assumption) and were used for four years, the hardware would cost about USD 10,000 a year, roughly seven times its electricity bill even at full load. The lesson for anyone running their own AI hardware is simple: keep it busy.
Every chapter inside one answer
When you read one AI answer, you are using every part of this book at once.
| Step of the journey | What it uses | Chapter |
|---|---|---|
| Your phone sends the question | Copper, gold, tantalum and lithium in the device and the network | 1 |
| Every chip on the way | Silicon wafers made from ultra-pure polysilicon | 2 |
| Every calculation | Transistors switching on and off | 3 |
| Tokens, weights, 4-bit formats | Bits, bytes, numbers and logic gates | 4 |
| The GPU and network chips | Chip design and its software | 5 |
| The GPU chip itself | A leading-edge fab | 6, 7 |
| The machines that made the GPU | Lithography, etch and deposition tools and their parts | 7, 8 |
| The price of the GPU | Yield and fab economics | 9 |
| The weights and the KV cache | HBM or GDDR7 memory | 10 |
| GPU and memory in one unit | Advanced packaging and test | 11 |
| The decode loop | The GPU or AI accelerator | 12 |
| Power, cooling, network | Servers and data centres | 13 |
| The weights themselves | Training | 14 |
Four sizes of machine
The same two rules explain why AI hardware comes in the sizes it does. Here are four typical sizes for running open models on your own premises.
| Size | Hardware | GPU memory | What fits comfortably |
|---|---|---|---|
| A | 2 workstation GPUs (RTX PRO 6000 class) | 192 GB | Models up to roughly 150–250 billion parameters at 4 bits, such as gpt-oss-120b |
| B | 4 workstation GPUs | 384 GB | Models up to roughly 500 billion parameters at 4 bits, such as DeepSeek V4 Flash with lots of room for users |
| C | 8 server-edition GPUs | 768 GB | Models up to about a trillion parameters at 4 bits |
| D | 8 data-centre GPUs (H200 or B200) joined by NVLink | about 1.1 to 1.4 TB | Trillion-parameter models at 8 bits, with many users |
The jump from C to D is not just more memory. Size D has HBM memory at about 4.8 to 8 TB/s for each GPU, and NVLink between GPUs, so tensor parallel works properly and every person gets a much faster answer. It also costs several times more.
Why this is hard
- Memory is the wall. Every token needs gigabytes read from memory, and memory speed has improved more slowly than arithmetic speed.
- The KV cache grows. Long documents and many users need a lot of memory, and it competes with the weights.
- Trade-offs everywhere. Low cost per token and high speed for each person pull in opposite directions; every operator picks a balance.
- Software moves fast. Serving software, model formats and drivers change every month, and a model can be fast in one version and slow in the next.
- Demand comes in waves. People do not arrive at a steady rate. A system sized for the busiest hour sits partly idle at night.
A short history
- 2016 to 2017: NVIDIA introduces TensorRT for fast inference on its GPUs.
- 2020: OpenAI offers GPT-3 through an online API. Inference becomes a service you can buy.
- November 2022: ChatGPT launches, and demand for inference grows extraordinarily fast.
- March 2023: llama.cpp lets people run language models on a laptop.
- June 2023: vLLM introduces PagedAttention and popularises continuous batching.
- 2023 to 2024: Groq and Cerebras show very fast inference using large amounts of on-chip SRAM memory.
- 2024: DeepSeek's multi-head latent attention shrinks the KV cache dramatically. Reasoning models start using many more tokens for each answer.
- 2025 to 2026: 4-bit formats such as MXFP4 and NVFP4 become standard. Inference becomes the largest use of AI computing.
Open questions
- Can we climb the memory wall? Decode speed is set by memory bandwidth. Will the answer be ever-faster HBM, much more memory on the chip itself, or new designs that compute inside memory?
- How small can the KV cache get? Compression tricks have already cut it by large factors. Could long conversations one day cost almost no extra memory at all?
- Can models write several tokens at once? Techniques that guess a few tokens ahead and check them together already speed up decode. How far can that idea go?
- How much does reasoning cost, and is it worth it? Reasoning models write long chains of working. When does extra thinking pay for itself, and can models learn to think only as long as a question deserves?
- What is the true energy of one answer? Very few providers publish it, and those that do measure in different ways. A shared, open method would let everyone compare fairly.
What to remember
- An answer has two phases: prefill reads the prompt and is limited by arithmetic; decode writes one token at a time and is limited by memory speed.
- Upper-limit speed = memory bandwidth ÷ bytes read for each token. Real systems reach roughly 20% to 50% of it.
- The KV cache holds the conversation in GPU memory, and it can grow larger than the weights.
- Batching lets one read of the weights serve many people, and quantization shrinks every read. Together they make AI answers cheap.
- For your own hardware, the machine usually costs far more than its electricity, so keep it busy.
Sources
- OpenAI (2025). gpt-oss-120b model card: 117B total, 5.1B active; MXFP4 MoE weights; fits a single 80 GB GPU. https://huggingface.co/openai/gpt-oss-120b
- DeepSeek-AI (2026). DeepSeek-V4-Flash model card: 284B total, 13B activated; FP4 + FP8 mixed weights; MIT licence. https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash
- DeepSeek-AI (2024). "DeepSeek-V2: a strong, economical, and efficient mixture-of-experts language model" (multi-head latent attention; KV cache reduced by 93.3%). arXiv:2405.04434. https://arxiv.org/abs/2405.04434
- Meta (2024). "The Llama 3 Herd of Models" (Llama 3 70B: 80 layers, 8 key-value heads, head size 128). arXiv:2407.21783. https://arxiv.org/abs/2407.21783
- Lenovo Press, ThinkSystem NVIDIA RTX PRO 6000 Blackwell Max-Q product guide (96 GB GDDR7, 512-bit, 300 W, PCIe 5.0 x16), and retailer specification listing 1,792 GB/s. https://lenovopress.lenovo.com/lp2364-thinksystem-nvidia-rtx-pro-6000-blackwell-max-q-workstation-edition-gpu
- NVIDIA H200 product page (141 GB HBM3e, 4.8 TB/s). https://www.nvidia.com/en-us/data-center/h200/
- NVIDIA DGX B200 page (eight GPUs, 1,440 GB total, 64 TB/s). https://www.nvidia.com/en-us/data-center/dgx-b200/
- Kwon, W. et al. (2023). "Efficient memory management for large language model serving with PagedAttention." SOSP 2023. arXiv:2309.06180. https://arxiv.org/abs/2309.06180 ; vLLM launch blog (June 2023): https://blog.vllm.ai/2023/06/20/vllm.html
- llama.cpp repository (first released March 2023). https://github.com/ggml-org/llama.cpp
- SGLang project. https://github.com/sgl-project/sglang
- NVIDIA TensorRT-LLM and Dynamo. https://github.com/NVIDIA/TensorRT-LLM ; https://github.com/ai-dynamo/dynamo
- OpenAI (June 2020), "OpenAI API." https://openai.com/index/openai-api/
- Elsworth, C., Patterson, D., Dean, J. et al. (2025). "Measuring the environmental impact of delivering AI at Google scale." arXiv:2508.15734 (median Gemini text prompt 0.24 Wh). https://arxiv.org/abs/2508.15734
Estimates in this chapter: the bytes read per token for gpt-oss-120b (about 3.5 GB); the 20–50% and 15–40% real-speed fractions; total throughput of the office box; its 1.1 kW power, energy per token and electricity cost (at an assumed USD 0.15 per kWh); the assumed USD 40,000 box price; time-to-first-token and reading-speed ranges; and the model sizes that fit each machine size.
Previous: 14. What a language model is, and how it learns · Next: 16. Who makes what: the company map