Why a GPU?
Almost all the work in a neural network is matrix multiplication: billions of multiply-and-add steps that do not depend on each other. A CPU has a few dozen strong cores, built to run complicated programs one step after another. A GPU has thousands of simple lanes that all do the same thing to different numbers at the same time, which is exactly what matrix multiplication needs.
Since 2017, NVIDIA’s GPUs have also had tensor cores: units that multiply a small block of numbers by another block in one step. They do nearly all of a language model’s maths. Other makers have their own versions: AMD calls them matrix cores, and Google’s TPUs are built around large matrix units.
132 SMs × 4 tensor cores = 528 tensor coresAn SM (streaming multiprocessor) is one of the GPU’s small processors.
peak ≈ 989 trillion operations per second in BF16Counting each multiply and each add as one operation. In 8-bit FP8 it is twice that: 1,979 trillion.
Quick check
Inside an H100
NVIDIA’s H100 is the data-centre GPU behind many of today’s models. Here is what is inside it.
| How many, or how big | What it does | |
|---|---|---|
| Streaming multiprocessors (SMs) | 132 | Small processors that each run many threads at once |
| Tensor cores | 4 per SM, 528 in all | Multiply blocks of matrices |
| Registers | 256 KB per SM | The numbers being worked on right now |
| Shared memory and L1 cache (SRAM) | 256 KB per SM, up to 228 KB of it as shared memory | Fast scratch space that a program manages itself |
| L2 cache | 50 MB | Shared by all SMs; saves trips to HBM |
| HBM3 memory | 80 GB at 3. | Holds the weights and the KV cache |
| NVLink | 900 GB/ | Links to the other GPUs in the server |
| Power | Up to 700 W | About seven old 100-watt light bulbs |
From NVIDIA’s Hopper architecture article and H100 data sheet.
- On-chip SRAMAbout 19 TB/s, but only 20 MB in all: 192 KB in each of 108 SMs
- HBM beside the chip1.5 TB/s, 40 GB
- The computer’s main memory (CPU DRAM)12.8 GB/s from the GPU’s side, more than 1 TB
Each step closer to the maths units is ten to a hundred times faster and far smaller. Every program that runs on a GPU, called a kernel, loads its inputs from HBM, computes, and writes its results back to HBM. For many kernels, the loading and writing take longer than the maths. Most of the speed tricks in this course are really about moving fewer bytes.
The roofline: memory or maths?
Every job on a chip needs two things: operations (maths) and bytes (data moved from memory). Whichever runs out first sets the speed. The arithmetic intensity of a job is how many operations it does for each byte it reads.
ridge point = peak operations per second ÷ memory speedAbove this intensity the maths units are the limit; below it, memory is.
989 trillion ÷ 3.35 trillion bytes per second ≈ 295 operations per byteThe H100 needs 295 operations for every byte it reads, or its maths units wait.
decode for one user: 2 operations per weight ÷ 2 bytes per weight = 1 operation per byteEach 16-bit weight is read once and used for one multiply and one add. That is 1/295 of what the chip could do: about 0.3 % busy.
Drawn on a graph, this gives the roofline: a slope where memory speed sets the limit, then a flat roof where computing power does. The picture comes from a 2009 paper by Williams, Waterman and Patterson at Berkeley, and chip designers and kernel writers still think with it.
Batching helps, because one read of the weights serves every user in the batch: 100 users give about 100 operations per byte. But each user also has a KV cache, and it is read for that user alone. With 2,000-token chats on Llama 3.1 8B, the intensity can never pass about 65 operations per byte, however many users you add. So decode stays memory-bound. Prefill uses each weight for every token of the prompt, which puts it at thousands of operations per byte, under the flat roof.
Start with one user: about 205 tokens per second, and the maths units under 1 % busy. Raise it to 200 users: each still gets about 49 tokens per second and the total is near 10,000, but the dot stays on the slope. Now pick 100-token contexts and 1,000 users, and the dot reaches the roof. Then try 32,000 tokens: only 13 users fit on an H100.
This interactive part needs JavaScript.
This one picture explains a lot. Chips for serving chase memory speed and size: the H200 has exactly the H100’s maths but 43 % more memory speed. Tricks that shrink the bytes, such as GQA, MLA and quantization, speed up decode. And speculative decoding works because idle maths can check several draft tokens for the price of one read of the weights.
Quick check
Is each job limited by memory speed or by computing power?
-
One person chatting with an 8B model
Answer: Memory speed
-
Reading a 20-page document before the first word appears
Answer: Computing power
-
Pretraining, with millions of tokens in every step
Answer: Computing power
-
200 users decoding at once, each with a 32,000-token chat
Answer: Memory speed
-
1,000 users with very short chats on one H100
Answer: Computing power
-
The big model checking 4 draft tokens in speculative decoding
Answer: Memory speed
FlashAttention: same maths, fewer trips
Attention compares every token with every other token. Done the simple way, the kernel writes the whole table of scores to HBM, reads it back for the softmax, writes the result, and reads it again. For one head with 8,000 tokens the table has 64 million entries, 128 MB in 16 bits, and there is one for every head in every layer.
- Cut the queries, keys and values into tiles small enough to fit in SRAM.
- Load one tile, compute its scores and its part of the softmax, and add its share to the output, all on the chip.
- Move to the next tile. Keep a running maximum and a running total, and rescale what you have so far when the maximum changes.
- Write only the final output to HBM. In training, recompute the scores in the backward pass instead of storing them: that is faster than reading them back.
softmax(xᵢ) = e^(xᵢ − m) ÷ Σⱼ e^(xⱼ − m)m is the largest score so far. Subtracting it stops the numbers from overflowing and does not change the answer.
new maximum m′ ⇒ total′ = total × e^(m − m′) + Σ e^(x − m′)When a tile brings a bigger score, the old total is rescaled, not recomputed. The partial output is rescaled the same way.
result = exact attentionNot an approximation: the same numbers as the simple way, up to rounding.
FlashAttention came from Tri Dao and colleagues at Stanford and the University at Buffalo in 2022. It made attention 7.6 times faster on GPT-2 and whole training runs 3 times faster. Long contexts became affordable, because the memory it needs grows with the length of the text, not with its square.
The upper end of what each paper reports, for 16-bit maths. FlashAttention-3 also reaches close to 1.2 quadrillion operations per second in FP8.
Quick check
Many chips, one model
A 405-billion-parameter model is 810 GB in 16 bits. Training it needs much more than the weights.
2 + 2 + 12 = 16 bytes per parameter16-bit weights (2), 16-bit gradients (2), and 32-bit copies of the weights plus Adam’s two running averages (12).
405 billion × 16 bytes ≈ 6,480 GBBefore counting activations, the values saved for the backward pass.
6,480 GB ÷ 80 GB ≈ 81 H100s, just to hold itAnd thousands more to finish in weeks rather than decades.
| What is split | What travels between chips | Where it is used | |
|---|---|---|---|
| Data parallel | The data: each chip has a copy of the model and its own share of the batch | Gradients, once per step, to average them | Everywhere. ZeRO and FSDP also split the copies of the weights and optimizer state |
| Tensor parallel | Each big matrix, across chips | Partial results, twice per layer, for every token | Inside one server, over NVLink (Megatron-LM, NVIDIA, 2019) |
| Pipeline parallel | The layers, into stages on different chips | Activations, from one stage to the next | Across servers. Chips sit idle in “bubbles” while the pipeline fills (GPipe, Google, 2018) |
| Expert parallel | The experts of an MoE model | Every token, to its experts and back (all-to-all) | MoE models such as DeepSeek-V3 (64-way) |
| Context parallel | A long sequence, into pieces | Keys and values, between the pieces | Long-context training, as in Llama 3 |
Llama 3 405B (Meta, 2024)
- Up to 16,384 H100s at 700 W each, 8 per server, joined by NVLink
- “4D” parallelism: tensor, context, pipeline and data
- Tensor parallel 8 ways: exactly one server
- 38–43 % of the chips’ peak maths spent on the model
DeepSeek-V3 (DeepSeek, 2024)
- 2,048 H800s, whose NVLink was cut from 900 to 400 GB/s for export rules
- 16-way pipeline (its own DualPipe design), 64-way expert parallel across 8 servers, ZeRO-1 data parallel
- No tensor parallel at all, to avoid the slow links
- Trained in FP8, with 20 of each GPU’s 132 SMs set aside for communication
The last line of the Llama 3 card is called MFU, model FLOPs utilization: the share of the chips’ peak maths spent on the model’s own calculations. The rest is lost to waiting for memory, for other chips, and for restarts. Around 40 % is good for a training run of this size.
Quick check
The wires between chips
Splitting a model only works if the pieces can talk quickly. Links come in two kinds: scale-up links that join a few chips into what acts like one big GPU, and scale-out networks that join many servers into a cluster.
| Speed | Joins | |
|---|---|---|
| An H100 to its own HBM | 3,350 GB/ | The chip and its memory |
| NVLink, H100 | 900 GB/ | The 8 GPUs in one server |
| NVLink, H800 | 400 GB/ | The same, cut for export rules |
| NVLink, GB200 NVL72 | 1,800 GB/ | 72 GPUs in one rack |
| Google ICI, Ironwood TPU | 1,200 GB/ | Up to 9,216 chips in one pod |
| InfiniBand, 400 Gb/s | 50 GB/ | Servers in a cluster |
NVLink figures count both directions together. The GB200 figure is the rack’s 130 TB/s spread over 72 GPUs, from 3.6 TB/s per two-GPU superchip.
DeepSeek’s hardware paper (2025) shows how much this matters. In MoE decode, every token travels to its experts and back in every layer, so the network, not the chip, sets the top speed.
(1 + 2 bytes) × 32 tokens × 9 experts × 7,000 numbers ÷ 50 GB/s ≈ 121 µsSending tokens out in FP8 (1 byte) and back in BF16 (2 bytes), 32 tokens per chip, to 8 routed experts and 1 shared one, over 400 Gb/s InfiniBand.
2 × 121 µs × 61 layers ≈ 14.8 ms per token ≈ 67 tokens per secondTwo micro-batches take turns, and there are 61 layers. This is the best case, before any other delay.
the same sum at 900 GB/s (GB200 NVL72) ≈ 6.7 µs ⇒ about 1,200 tokens per secondDeepSeek’s own estimate, which it says has not been tested.
Huawei took the other road and made the wires huge. Its CloudMatrix384 joins 384 Ascend 910 NPUs and 192 Kunpeng CPUs across 16 racks with one Unified Bus, so any chip can reach any other directly. Serving DeepSeek-R1 with its experts spread over 320 chips, Huawei reported 1,943 tokens per second per NPU in decode, at under 50 ms per token. It used INT8, since the Ascend 910 has no FP8 units.
Google’s TPUs use a third design: chips wired straight to their neighbours. An Ironwood pod joins up to 9,216 chips, 42.5 exaflops of FP8 maths in all, and draws nearly 10 MW.
Quick check
The chips, side by side
| What it is | BF16, trillion operations per second | Memory | Memory speed | Power | |
|---|---|---|---|---|---|
| NVIDIA RTX 4090 | Gaming card | 165 | 24 GB | 1,008 GB/ | 450 W |
| NVIDIA H100 SXM | Data-centre GPU | 989 | 80 GB | 3,350 GB/ | 700 W |
| NVIDIA H200 | The H100 with more, faster memory | 989 | 141 GB | 4,800 GB/ | 700 W |
| NVIDIA B200 (in a GB200 NVL72) | Data-centre GPU, sold in racks of 72 | 2,500 | 186 GB | 8,000 GB/ | – |
| AMD MI300X | Data-centre GPU | 1,307 | 192 GB | 5,300 GB/ | 750 W |
| AMD MI355X | Data-centre GPU | 2,500 | 288 GB | 8,000 GB/ | 1,400 W |
| Google Ironwood TPU | Google’s own chip, rented in Google Cloud | 4,614 in FP8 | 192 GB | 7,370 GB/ | – |
| Apple M5 Max | Laptop chip | Not published | Up to 128 GB, shared | 614 GB/ | – |
| Apple M5 Ultra | Mac Studio chip | Not published | Up to 512 GB, shared | 1,200 GB/ | – |
Dense figures from each maker’s spec sheet. The B200 row is the GB200 NVL72 rack divided by 72. Google gives Ironwood’s peak only in FP8, so it cannot be compared directly with the BF16 column.
What fits: a 70B model in 8 bits (about 70 GB) fits on one H100. In 16 bits (140 GB) it needs two H100s or one MI300X.
Apple’s chips use unified memory: the CPU and GPU share one pool. A Mac Studio with 512 GB can hold a 4-bit version of a 671B model, which no single data-centre GPU can. But at 1.2 TB/s it reads memory more slowly than one H100, so it suits one person at home, not thousands of users.
# Which GPU is this, and how busy is it?
nvidia-smi --query-gpu=name,memory.total,memory.used,utilization.gpu,power.draw --format=csv
# Refresh every second while a model runs
nvidia-smi -l 1
# How are the GPUs in this machine connected?
nvidia-smi topo -m
utilization.gpumeans some kernel was running during the sample, not that the maths units were full. A decode job can show 100 % while its tensor cores are nearly idle.- In
topo -m,NV18means 18 NVLink links between two GPUs, as in an H100 server.PIX,PHBandSYSmean the path goes over PCIe or through the CPU, which is much slower. - On AMD GPUs,
rocm-smishows the same things. On a Mac, open Activity Monitor and choose Window, then GPU History.
Power, failures and cost
- A gaming RTX 4090: 450 W.
- One H100: up to 700 W. One MI355X: 1,400 W.
- One 8-GPU DGX B200 server: about 14.3 kW.
- One Ironwood pod of 9,216 chips: nearly 10 MW.
At this scale, power is a design problem of its own. Meta reports that when all of Llama 3’s GPUs paused together, for a checkpoint or a restart, the data centre’s power use swung by tens of megawatts, “stretching the limits of the power grid”.
419 unexpected stops in 54 days on up to 16,384 H100s: about one every three hours. About 78 % were confirmed or suspected hardware faults. Only three needed a person to step in; automatic restarts handled the rest.
180,000 GPU hours per trillion tokens ÷ 2,048 GPUs ≈ 88 hours ≈ 3.7 daysIt was trained on 14.8 trillion tokens, so pretraining took under two months.
2.788 million GPU hours × $2 per hour = $5.576 millionPretraining, context extension and post-training together, at a rental price DeepSeek assumed.
Remember
- A GPU is thousands of simple lanes plus tensor cores. An H100 has 132 SMs and 528 tensor cores, and does 989 trillion BF16 operations per second (dense).
- Memory is a ladder: tiny, fast SRAM on the chip, bigger and slower HBM beside it. Most speed tricks move fewer bytes.
- Roofline: ridge point = peak ÷ memory speed (295 operations per byte on an H100). Chat decode sits far below it, so it is limited by memory; prefill and training are limited by maths.
- FlashAttention computes exact attention tile by tile in SRAM. FlashAttention-3 uses 75 % of an H100’s peak.
- Big models are split by data, tensor, pipeline and expert. Tensor parallel stays inside a server because it needs the fastest links, and the network can set the top speed of MoE decode.
- Read spec sheets carefully: dense or sparse, which precision, per chip or per rack. DeepSeek shows how to design a model around the hardware you have.
Words to know
- GPU
- A chip with thousands of simple maths lanes working at once. First made for graphics.
- SM (streaming multiprocessor)
- One of a GPU’s small processors. An H100 has 132.
- Tensor core
- A unit inside an SM that multiplies small blocks of matrices in one step.
- HBM
- High-bandwidth memory: the GPU’s main memory, stacked beside the chip. Large, but slower than on-chip memory.
- SRAM
- Small, very fast memory on the chip itself, a few hundred kilobytes per SM.
- Kernel
- A program that runs on the GPU, such as one matrix multiplication or one attention step.
- Memory bandwidth
- How many bytes per second can move between memory and the processor.
- Arithmetic intensity
- Operations done for each byte read from memory.
- Ridge point
- The intensity where a chip stops being limited by memory and starts being limited by maths: peak operations ÷ memory speed.
- Memory-bound, compute-bound
- Waiting for memory, or waiting for maths.
- Sparsity (on spec sheets)
- A trick that needs 2 of every 4 weights to be zero. Figures “with sparsity” are twice the usual rate.
- NVLink
- NVIDIA’s fast links between GPUs, inside a server or a rack.
- InfiniBand
- A fast network between servers.
- Parallelism
- Splitting work across chips: by data, by matrix (tensor), by layer (pipeline), or by expert.
- MFU
- Model FLOPs utilization: the share of the chips’ peak maths spent on the model itself.
- TPU, NPU
- Chips built only for AI, such as Google’s TPUs and Huawei’s Ascend NPUs.
- Unified memory
- One pool of memory shared by the CPU and GPU, as on Apple’s chips.
Go to the source
This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.
-
Roofline: An Insightful Visual Performance Model for Multicore Architectures
The original roofline paper, from Berkeley. Short, and the source of this lesson’s main picture.
-
NVIDIA Hopper Architecture In-Depth
NVIDIA’s own tour of the H100: SMs, tensor cores, memory, the Tensor Memory Accelerator and NVLink.
-
FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
Figure 1 shows the memory ladder and the tiling idea. Section 3 is readable once you have this lesson.
-
FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
How dividing the work differently between parts of the GPU doubled the speed.
-
FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision
Writing a kernel for the H100’s new features, and for FP8.
-
Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism
Tensor parallelism, with only two exchanges per layer in the forward pass.
-
ZeRO: Memory Optimizations Toward Training Trillion Parameter Models
Where the 16 bytes per parameter come from, and how to split them across GPUs.
-
GPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelism
Pipeline parallelism, and how small batches shrink the idle bubbles.
-
The Llama 3 Herd of Models
Section 3.3 is a frank account of a 16,384-GPU run: the parallelism, the failures and the power swings.
-
DeepSeek-V3 Technical Report
Section 3 covers the cluster, DualPipe, FP8 training and the cost.
-
Insights into DeepSeek-V3: Scaling Challenges and Reflections on Hardware for AI Architectures
DeepSeek on the limits of today’s hardware and what chips should do next. Section 2.3.2 has the speed-limit sum.
-
Serving Large Language Models on Huawei CloudMatrix384
Huawei’s 384-chip system and how it serves DeepSeek-R1.
-
FlashMLA
DeepSeek’s attention kernels, now for NVIDIA’s Blackwell GPUs and Huawei’s Ascend NPUs. The news section dates each release.
Check yourself
5 questions. Tap the answer you think is right.
0 of 5 answered
Lesson complete
Answer every question above to complete this lesson.
Your progress is saved on this device only.
Next lessonServing: one model, millions of people