Skip to Content
Chapter 10

Hardware: The physics of tokens

Tomas Reimers 13 minute read

It’s one of history’s better jokes that the machine underneath the most important technology of the decade was built for video games. GPUs exist because rendering pixels is millions of small, independent, identical calculations, and by lucky coincidence (nudged along by a decade of co-evolution), so is a neural network. Chapter 1 showed you that a model is essentially a pile of matrix multiplies; this chapter is about the machine that does them, because its physics — not the math — sets the price of every token you buy. Four steps:

  1. The machine: what a GPU is, and the three numbers that describe one.
  2. The roofline: a one-line performance model that explains nearly everything in this chapter and the next, built from the ratio of those numbers.
  3. The transformer’s two lives: training is compute-bound; generating is memory-bound, and that one asymmetry is the industry’s cost structure.
  4. Memory and parallelism: why one GPU is never enough, and the four standard ways to split the work.

A GPU, for people who know computers

A CPU is a few dozen brilliant cores optimized to make one thread fast: caches, branch prediction, speculative execution. A GPU inverts every priority: tens of thousands of simple cores that are individually slow but collectively enormous, organized (on an NVIDIA H100) into ~132 streaming multiprocessors, each containing tensor cores — silicon whose only job is multiplying small matrices. If your workload is “do the same arithmetic on huge regular arrays,” nothing else comes close. If it has branches and pointer-chasing, keep your CPU.

The numbers that matter, using the H100 as the reference machine of the era:

  • Compute: on the order of 1,000 teraFLOPs (10¹⁵ operations/sec) at 16-bit precision. This is the part that does the actual work — every attention lookup and MLP from Chapter 3 bottoms out as matrix multiplies executed on the tensor cores, and it’s what you think you’re paying for.
  • Memory: 80 GB of high-bandwidth memory (HBM) at ~3.35 TB/s. This is where everything waits to be worked on: the model’s weights, the KV cache (Chapter 5), and the activations in flight all live here, and every number must cross the bus to the cores to participate in a single FLOP. The capacity (80 GB) decides what fits on the card at all; the bandwidth (3.35 TB/s) decides how fast the cores can be fed. The bandwidth is what you’re actually paying for, as the rest of the chapter will argue.
  • On-chip SRAM: tens of megabytes, ~10× faster than HBM. The scratchpad sitting next to the cores, holding only the small tiles of data being multiplied right now — thousands of times too small for the weights, so data constantly shuttles HBM → SRAM → cores and back. The best GPU kernels (the individual GPU programs a model’s code launches, one per operation) play one game — maximize work done per shuttle: FlashAttention (Chapter 5) is famous precisely for keeping attention’s intermediate score matrix in SRAM instead of round-tripping it through HBM.

Do the division (compute rate over memory rate, the seconds cancelling) and you get the ratio the rest of this chapter runs on:

∼1015 FLOP/s3.35×1012 bytes/s  ≈  300 FLOPs per byte\frac{\tip{compute: about 1000 teraFLOPs per second}{\sim 10^{15}\ \text{FLOP/s}}}{\tip{bandwidth: about 3.35 terabytes per second}{3.35 \times 10^{12}\ \text{bytes/s}}} \;\approx\; 300\ \text{FLOPs per byte}

Read it as a deadline: in the time HBM delivers one byte, the tensor cores can complete ~300 operations. So unless every byte fetched from memory participates in ~300 FLOPs once it arrives, the cores finish early and idle, waiting on the bus.

The roofline: are you feeding the beast?

That ratio is the whole performance model. For any computation, count its arithmetic intensity — FLOPs performed per byte of memory traffic. Above ~300, you’re compute-bound: the tensor cores are the bottleneck and you’re getting your money’s worth. Below it, you’re memory-bound: the cores idle, waiting on bytes, and adding FLOPs is free because you weren’t using the ones you had. (Horace He’s Making Deep Learning Brrrr From First Principles  is the canonical tour of this mental model — most “why is my model slow” questions die on its first page.)

1101001K10K1101001000arithmetic intensity (FLOPs per byte, log)TFLOPs achieved (log)~300memory-bound (3.35 TB/s)compute-bound (~1 PFLOP roof)decode, batch = 1decode, batchedprefill / training
The roofline of an H100: below ~300 FLOPs per byte, performance is capped by memory bandwidth, not compute. Prefill and training live on the roof; single-stream decode is pinned to the far left of the slope.

Now apply it to the transformer’s two lives:

Training is compute-bound. You process billions of tokens in huge batches; every weight fetched from memory is reused across the whole batch, so arithmetic intensity is high. Efficiency is reported as MFU (model FLOPs utilization, the fraction of theoretical FLOPs doing useful work); frontier runs fight for 40–50%. If compute is the bottleneck, shouldn’t that be 100%? No — “compute-bound” is a claim about the big matrix multiplies, and those do run near the roof; MFU is an audit of the whole wall clock. Between the matmuls sit operations with low arithmetic intensity (normalization layers, attention’s softmax, elementwise ops, all memory-bound), waiting on other GPUs (gradient averaging, pipeline bubbles; the parallelism section below), and the long tail of kernel-launch overhead and stragglers across thousands of machines. The roofline caps each kernel; MFU averages over everything between the kernels too. 40–50% means the tensor cores have well-shaped work roughly half the time — and that’s the well-engineered case.

Inference (specifically, generating) is memory-bound. Chapter 2’s confession comes due: generation is one token at a time. To emit a single token, every parameter must travel from HBM to the cores — for a 70B model in 16-bit, ~140 GB moved while each weight does only ~2 FLOPs (one multiply-add) on its 2 bytes. Arithmetic intensity: 2 ÷ 2 ≈ 1, against the chip’s ~300 FLOPs-per-byte ratio — and below the roof, utilization is just intensity over that ratio: 1/300 ≈ 0.3%. The GPU that trained at 50% utilization generates at a third of a percent. The speed at which a model talks to you is set by memory bandwidth, not compute. Here is one token step, with the time drawn to scale:

HBM — weights: 140 GBtensor cores~1 PFLOP/sbus: 3.35 TB/seach weight: ~2 FLOPs, then discarded1 tokenone token step ≈ 42 ms× every tokencores waiting on bytes: ~41.7 mscores busy: 0.14 ms (0.3% — drawn wider than life)
to emit one token, every weight must visit the cores: all 140 GB cross the bus, and each weight does ~2 FLOPs (one multiply-add) before being discarded
One decode step, to scale in time: emitting a single token from a 70B model (bf16, one H100) means moving all 140 GB of weights from HBM to the cores — ~42 ms at 3.35 TB/s — while the arithmetic those bytes feed takes ~0.14 ms. The cores idle ~99.7% of every step, and the entire read repeats for every token: that division is where the ~24 tokens/sec ceiling comes from.

The decode speed limit, derived.

For a single conversation, each token requires one full read of the active weights, so the ceiling is just a division:

tokens/sec  ≤  bandwidthbytes of weights\text{tokens/sec} \; \le \; \frac{\tip{memory bandwidth in bytes per second}{\text{bandwidth}}}{\tip{active parameters times bytes per parameter}{\text{bytes of weights}}}

Run the book’s own models through it on one H100. The 8B you trained in Chapter 7, in bf16: 16 GB of weights → 3.35 TB/s ÷ 16 GB ≈ 200 tokens/sec, tops. A 70B in bf16: 140 GB → ~24 tokens/sec (and it doesn’t fit on one card anyway). Quantize the 70B to 4-bit (next chapter): 35 GB → ~95 tokens/sec. FLOPs appear nowhere in the formula. The tensor cores could go a thousand times faster; they’re waiting on the bus. The formula is also why batching is magic: the weights are read once per step, not once per conversation, so 100 concurrent requests share one read and the per-request ceiling barely moves while throughput goes up ~100×. Every serving trick in Chapter 11 is visible in this one fraction. The numerator is physics: bandwidth only grows when you buy a different machine. So the attacks come in exactly two shapes. Shrink the denominator: quantization cuts the bytes per weight; MoE reads only the active experts. Or get more than one token out of each read: batching shares a single weight-read across a hundred conversations; speculative decoding commits several tokens per read for even one.

One refinement to file: processing your prompt (prefill) handles all input tokens in parallel — that’s a big batch, so it’s compute-bound and fast. Generating the response (decode) is the memory-bound crawl. This asymmetry is why long inputs are cheap relative to long outputs, and why APIs price them differently.

Memory math: why one GPU is never enough

The other physical constraint is capacity — and like the roofline, it treats the transformer’s two lives differently, so take them in turn.

Training is the extreme case. Count a training run’s residents, at mixed precision with Adam (Chapter 1’s foreshadowing pays off):

ResidentBytes per parameter
Weights (bf16)2
Gradients (bf16)2
Adam moments + master weights (fp32)~12

(The ~12 decomposes: Adam keeps two fp32 running statistics per parameter — Chapter 1’s momentum average and magnitude average, 4 bytes each — plus an fp32 “master copy” of the weight itself, another 4, kept because repeatedly adding tiny updates to a bf16 number rounds them away. That split-precision arrangement is what “mixed precision” means.)

Roughly 16 bytes per parameter — a 70B model needs ~1.1 TB before a single activation is stored, versus 80 GB on the card. Training a frontier model on one GPU isn’t slow; it’s impossible. So: parallelism, in four standard flavors:

  • Data parallel: replicate the model, split the batch, average gradients. Simplest — and the memory-hungriest, tamed by sharding optimizer state across replicas (ZeRO — the Zero Redundancy Optimizer — and FSDP, Fully Sharded Data Parallel).
  • Tensor parallel: split individual matrices across GPUs, necessary once a single layer’s weights outgrow one card. The split is chosen so GPUs work alone as long as possible. For the MLP (Chapter 3’s expand-then-project pair of matrices), split the expansion matrix by columns, say 8 ways. Each GPU computes an eighth of the hidden activations with no coordination, and the elementwise nonlinearity needs none either. Then split the projection back down by rows, which leaves each GPU holding a partial sum of the output vector. One all-reduce (every GPU sends its partial result to the others, and all of them add) reassembles the token’s vector before the next operation needs it. Attention splits even more naturally: heads are already independent lookups, so each GPU just takes a few — though recombining their outputs through the output matrix costs the block its second all-reduce. The price is those all-reduces: activation-sized traffic, twice per block, for every token in the batch, at every layer — which is why tensor parallelism is bandwidth-brutal and stays within a tightly-coupled node (NVLink, ~900 GB/s — and even that is a quarter of HBM’s speed).
  • Pipeline parallel: put different layers on different GPUs. The hazard is the bubble (later GPUs idle while the first batch works its way up the stack), shrunk (never eliminated) by slicing each batch into micro-batches that keep every stage busy.
  • Expert parallel: mixture-of-experts’ gift (Chapter 5’s MoE) — experts live on different GPUs and tokens are routed over the network to whichever experts they need.
data parallelmodelbatch ¼modelbatch ¼modelbatch ¼modelbatch ¼full copy each; batch ÷ 4; average gradientstensor parallel¼ of everymatrix¼ of everymatrix¼ of everymatrix¼ of everymatrixevery matrix ÷ 4; talk every layer (NVLink)pipeline parallellayers1–20layers21–40layers41–60layers61–80layers in stages; micro-batches keep it fullexpert parallelexperts1–16experts17–32experts33–48experts49–64tokens routed over the network to their experts
The four ways to split a run, composable and composed. Data parallelism copies the model and splits the batch (cheap to coordinate, memory-hungry). Tensor parallelism splits every matrix (communication on every layer — kept inside a node). Pipeline parallelism splits by layer (an assembly line kept full with micro-batches). Expert parallelism is MoE's gift: tokens travel to whichever GPU holds their experts.

A frontier run composes all four across tens of thousands of GPUs — which is why the interconnects (NVLink within a node, InfiniBand across the cluster) are as much the computer as the GPUs are, and why “the network is the bottleneck” is a sentence you’ll hear in both datacenter engineering and MoE papers. Here’s the machine those sentences are about:

spine switchesleaf switchesleaf switchesInfiniBand fabric — ~50 GB/s per GPU(400 Gb/s links)inside each GPU: HBM — 3,350 GB/snode 1 — 8× GPUNVLink switch — 900 GB/snode 2 — 8× GPUNVLink switch — 900 GB/snode 4,000 — 8× GPUNVLink switch — 900 GB/stensor parallel stays inside a node — data, pipeline, and expert parallelism cross the fabric
A frontier cluster is a bandwidth ladder. Inside each GPU: HBM at ~3,350 GB/s. Between the 8 GPUs of a node: NVLink at ~900 GB/s. Between nodes: an InfiniBand leaf/spine fabric at ~50 GB/s per GPU (400 Gb/s links) — each step outward several times slower than the last. Parallelism placement follows the ladder: tensor parallelism's twice-per-block all-reduces stay on NVLink; data, pipeline, and expert parallelism, which communicate less often, cross the fabric.

Inference memory is a smaller but sharper story. The optimizer and gradients are gone, leaving 2 bytes per parameter, but what remains must fit with no slack. The weights alone are 140 GB for our 70B model, two GPUs before anyone connects. Then comes the KV cache, Chapter 5’s monster, which grows with every token of every concurrent conversation and competes with the weights for the same 80 GB. Managing that competition is half of the next chapter.

The numbers to carry in your head

Every LLM engineer eventually internalizes a small table; here’s a starter (order-of-magnitude, per the H100 era):

  • Weights in 16-bit: 2 bytes/param → a model needs ~2× its parameter count in GB just to exist. Run it at both ends: an 8B model is 16 GB and fits on one card; a hypothetical 2.5T-parameter model is 5,000 GB, 63 H100s of memory before a single token of KV cache. That’s why frontier models are born sharded. MoE doesn’t help here: its active-parameter discount applies to reads, not residence, so DeepSeek-V3’s 671B must all sit in memory even though each token touches only 37B.
  • Decode speed ceiling: memory bandwidth ÷ bytes-of-active-weights (MoE’s “active” distinction now cashes out: DeepSeek-V3 reads 37B parameters per token, not 671B).
  • Training cost: ~6 FLOPs per parameter per token (the classic estimate: 2 forward + 4 backward) — multiply by N params and D tokens, divide by cluster FLOPs × MFU, and you can sanity-check any lab’s claimed training time from your armchair.
  • Power: an H100 draws up to 700 W. Your 1,000-GPU month is ~0.5 GWh at the chips alone, closer to 0.8 GWh once servers, networking, and cooling are counted: roughly what 75 American homes use in a year. Frontier clusters are now planned in hundreds of megawatts to gigawatts, which is why the binding constraint on new datacenters is increasingly the power grid rather than the GPU supply.
  • Failure rate: at 16K GPUs, expect an interruption every few hours (Chapter 7). Do the arithmetic: Llama 3’s run logged 419 unexpected interruptions over 54 days (one per ~3 hours), which, divided out, means each individual GPU failed about once every six years. The hardware is good; reliability just divides by fleet size. And the blast radius is total: a training step is synchronous, so one dead GPU stalls the other 16,383 until the job recovers from a checkpoint — which is why checkpoint cadence, restart speed, and hot spares are first-class design parameters of a frontier run, not ops afterthoughts. (The nastiest failures don’t crash at all: silent data corruption, a GPU quietly miscomputing, is caught — if at all — by the loss curve misbehaving.)

Before we climb back up the stack: in this field the constraint is almost never “can we compute it” but “can we feed it” — bytes, not FLOPs. Which leaves a paradox sitting on your API invoice. This chapter just proved a 70B model on dedicated hardware crawls at ~24 tokens/sec with its cores 99.7% idle — yet providers sell those same tokens for fractions of a cent, at scale, profitably. Someone is extracting two orders of magnitude from somewhere. The next chapter is the art of moving fewer bytes — and it’s where that invoice gets reverse-engineered.

Further reading

Last updated on