Pidoku

Where AI Data Lives

Module 8 Lesson 8.c 45 min Difficulty 3/5

Prerequisites 4.d, 12.q, 8.b


Before you start: words you need#

WordPlain meaning
Memory tierOne level of the memory and storage stack: registers, caches, HBM, CPU memory, local SSD, shared file system, object storage. Each level down is bigger, slower and cheaper per byte.
ActivationsThe intermediate results a layer produces and the next layer consumes (2.a).
Optimizer stateExtra numbers the training algorithm keeps per weight. Adam keeps two running averages plus a full-precision copy of each weight.
ZeRO / FSDPWays of splitting (sharding) optimizer state, gradients and weights across data-parallel GPUs so no single GPU holds all of it.
OffloadMoving data from HBM to a lower tier (CPU memory, NVMe) and bringing it back when needed.
CheckpointA saved copy of a training job’s full state, so it can restart after a failure.
Object storageCheap, huge, slow storage reached over HTTP (S3, GCS, Azure Blob).
NVMeFast solid-state drives attached over PCIe (3.g).

1. What is it?#

An AI system moves six kinds of data, and each has a natural home in the memory hierarchy:

DataLives inSpills or moves to
Activationsregisters and shared memory, briefly; HBM between layersrecomputed instead of stored
WeightsHBMCPU memory, only when desperate
KV cacheHBMCPU memory, local NVMe, a store shared across replicas
Optimizer stateHBM, sharded across GPUsCPU memory or NVMe (offload)
Checkpointslocal NVMe or CPU memory firstparallel file system, then object storage
Training dataobject storagelocal NVMe cache, CPU memory, then HBM

Most performance work in AI infrastructure comes down to keeping the hot data one tier higher than it would otherwise be.

Facts checked on 12 November 2026.

WHERE AI DATA LIVES · THE MEMORY AND STORAGE HIERARCHYper GPU unless noted · H100-B300 era · checked 16 Oct 2026Registers + shared memory~33 + 33 MBtens of TB/sL2 cache50-130 MBseveral x HBMHBM80-288 GB3.35-22 TB/sCPU memory0.5-2 TB per node64 GB/s PCIe · 900 GB/s C2CLocal NVMe30-120 TB per node25-50 GB/s per nodeParallel file systempetabytesTB/s across the clusterObject storagepetabytes to exabytescheapest; highest latencybigger, slower, cheaper per byteActivationstiles live in SRAM during a kernel; recomputed to save HBMWeightsmust be in HBM to run fast; offload only when desperateKV cachegrows with context × users; offloaded and shared acrossreplicasOptimizer stateAdam: ~12-16 bytes per parameter; sharded (ZeRO/FSDP) oroffloadedCheckpointswritten every N steps: TBs, in seconds, without stallingTraining datastreamed, shuffled, cached near the GPUswhere it normally liveswhere it spills or moves
Solid lines: where each kind of data normally lives. Dashed: where it spills or moves.

2. Why does it matter?#

Because each tier down is roughly ten times slower, and a GPU that waits for data is an expensive machine doing nothing.

  • A decode step that has to fetch weights from CPU memory over PCIe instead of HBM runs about 100x slower (9.b).
  • A training run whose checkpoint takes a minute to write either checkpoints rarely (and loses more work on each failure) or stalls thousands of GPUs every time.
  • A serving fleet that throws away KV caches it could have kept in CPU memory recomputes the same prompts again and again (12.m).

Knowing where each kind of data lives tells you which tier to buy more of.


3. Simple analogy#

A kitchen:

  • Registers and shared memory: the chef’s hands and chopping board.
  • HBM: the counter. Everything for tonight’s dishes must be here.
  • CPU memory: the fridge in the same room.
  • Local NVMe: the walk-in cold store down the corridor.
  • Parallel file system: the restaurant’s central warehouse.
  • Object storage: the supplier’s depot across town.

Good kitchens plan so the chef never walks to the cold store mid-dish. Good AI systems plan so the GPU never waits on a lower tier mid-step.


4. Tiny example#

Full training state for a 70B model with mixed precision and Adam:

BF16 weights          2 bytes × 70e9 =  140 GB
BF16 gradients        2 bytes × 70e9 =  140 GB
FP32 master weights   4 bytes × 70e9 =  280 GB
Adam moment 1 (FP32)  4 bytes × 70e9 =  280 GB
Adam moment 2 (FP32)  4 bytes × 70e9 =  280 GB
total                16 bytes × 70e9 = 1,120 GB   before any activations

No GPU holds 1.1 TB. Sharded across 64 GPUs it is about 18 GB each.


5. Technical explanation#

The tiers, with numbers#

TierSize (per GPU unless noted)BandwidthTypical latency
Registers + shared memory~33 MB + ~30 MB across an H100’s 132 SMstens of TB/s1–30 cycles
L2 cache50 MB (H100); larger on Blackwellseveral x HBM~200 cycles
HBM80–288 GB3.35–22 TB/s (H100 to Rubin)~500 ns
CPU memory0.5–2 TB per node32–64 GB/s over PCIe 4/5; 900 GB/s over Grace’s NVLink-C2C; 1.8 TB/s on Vera~1 µs from the GPU
Local NVMe30–120 TB per node~25–100 GB/s per node (several drives)~100 µs
Parallel file systempetabytesTB/s across a cluster~1 ms
Object storagepetabytes to exabytestens to hundreds of GB/s aggregate~10–100 ms

Lesson 4.d covers the on-chip tiers; 3.g covers storage and model loading.

Training data: the full pipeline#

A training run reads its tokenised dataset from object storage, caches shards on local NVMe, loads batches into CPU memory and copies them to HBM, with prefetching so the GPU never waits. Text is small: a 15-trillion-token dataset is tens of terabytes once tokenised. Images and video are not, which is why multimodal training is often storage-bound.

Optimizer state: the hidden multiplier#

Mixed-precision Adam keeps 16 bytes per parameter before activations (section 4). ZeRO and FSDP shard it across the data-parallel GPUs:

  • Stage 1 shards the optimizer state (the 12 bytes of FP32 master weights and moments).
  • Stage 2 also shards the gradients.
  • Stage 3 (FSDP) shards the weights too, gathering each layer just before it is used.

When even that does not fit, offload moves optimizer state to CPU memory or NVMe. On Grace and Vera superchips the NVLink-C2C link makes CPU offload far less painful than over PCIe (7.c).

Activations: recompute instead of store#

The backward pass needs the forward pass’s activations. Storing them all for long sequences can exceed the weights. Activation checkpointing stores only some and recomputes the rest during the backward pass: spend FLOPs to save HBM. FlashAttention applies the same idea inside a kernel: it never writes the full attention matrix to HBM (13.l).

KV cache: the inference memory problem#

During serving the KV cache grows with context length times concurrent users and often exceeds the weights (12.f). It now has its own hierarchy:

  • hot blocks in HBM, managed in pages (12.l);
  • warm blocks offloaded to CPU memory (14.k);
  • cold or shared prefixes on local NVMe or in a store every replica can reach, such as LMCache, NVIDIA Dynamo’s KV block manager or Mooncake-style designs (14.l, 21.j).

Reusing a cached prefix saves recomputing it, which is why fast tiers below HBM pay for themselves. Moving those blocks between machines is a networking problem (9.e). CXL-attached memory (9.b) is a possible extra tier between CPU memory and NVMe, but most fleets in 2026 still use plain DRAM and SSD.

Checkpoints: the burst#

A training job writes its full state every N steps: for a 1T-parameter model, about 14 TB of weights and optimizer state. Writing it must not stall thousands of GPUs, so it goes first to CPU memory or local NVMe asynchronously, then drains to the parallel file system and finally to object storage. How fast you can checkpoint sets how often you can afford to, and so how much work a failure throws away.


6. Under the hood#

Per-GPU training memory for a 70B model under each ZeRO stage, and how long a checkpoint takes to write at different storage speeds.

Go
// state.go — where a training run's bytes live, per GPU.
package main

import "fmt"

func main() {
	const params = 70e9
	const gb = 1e9
	weights, grads, optim := 2*params, 2*params, 12*params // bytes: BF16, BF16, FP32 master+Adam

	fmt.Println("data-parallel GPUs   ZeRO-0   ZeRO-1   ZeRO-2   ZeRO-3/FSDP   (GB per GPU, before activations)")
	for _, n := range []float64{8, 64, 512} {
		z0 := weights + grads + optim
		z1 := weights + grads + optim/n
		z2 := weights + (grads+optim)/n
		z3 := (weights + grads + optim) / n
		fmt.Printf("%18.0f %8.0f %8.0f %8.0f %13.0f\n", n, z0/gb, z1/gb, z2/gb, z3/gb)
	}

	ckpt := weights + optim // a resumable checkpoint: weights + optimizer state
	fmt.Printf("\ncheckpoint size: %.2f TB\n", ckpt/1e12)
	for _, s := range []struct {
		where string
		gbs   float64
	}{
		{"object storage, 20 GB/s", 20},
		{"parallel file system, 500 GB/s", 500},
		{"local NVMe on 64 nodes, 64 × 30 GB/s", 64 * 30},
	} {
		fmt.Printf("  %-40s %7.1f s\n", s.where, ckpt/gb/s.gbs)
	}
}

Output:

data-parallel GPUs   ZeRO-0   ZeRO-1   ZeRO-2   ZeRO-3/FSDP   (GB per GPU, before activations)
                 8     1120      385      262           140
                64     1120      293      155            18
               512     1120      282      142             2

checkpoint size: 0.98 TB
  object storage, 20 GB/s                     49.0 s
  parallel file system, 500 GB/s               2.0 s
  local NVMe on 64 nodes, 64 × 30 GB/s         0.5 s

How to read it:

  • Without sharding, every GPU needs 1.1 TB: impossible on any GPU sold today.
  • ZeRO-1 and ZeRO-2 stop improving once the unsharded weights (and gradients) dominate; only FSDP keeps shrinking with more GPUs.
  • FSDP across 64 GPUs brings it to about 18 GB each, leaving the rest of HBM for activations.
  • The checkpoint numbers explain the layered write path: almost a minute straight to object storage, two seconds to a parallel file system, half a second to NVMe spread across the nodes.

7. Performance implications#

  • Weights and KV cache must be in HBM to run fast. Everything else can be pushed down a tier with planning.
  • Each tier is about 10x slower. A design that touches a lower tier on every step inherits its speed.
  • Overlap hides tiers. Prefetching data, writing checkpoints asynchronously and streaming KV blocks layer by layer all hide a slower tier behind computation.
  • The CPU–GPU link decides offload. 64 GB/s over PCIe 5 makes optimizer or KV offload painful; 900 GB/s–1.8 TB/s over NVLink-C2C makes it practical.

8. Production implications#

  • Budget CPU memory and NVMe for KV caching. For chat and agent workloads with shared prefixes, a terabyte of host memory per node often saves more GPU time than another GPU.
  • Stage checkpoints. Write locally first, drain later; test restore time, not only write time.
  • Watch the data loader. If GPU utilisation dips at the start of each step, the input pipeline, not the GPU, is the bottleneck.
  • Model loading is a tier problem too. Cold starts are bound by the slowest tier the weights come from (3.g, 20.g).

9. Common mistakes#

  1. Forgetting optimizer state. Training needs about 16 bytes per parameter, not 2.
  2. Using ZeRO-1 and expecting FSDP savings. Only stage 3 shards the weights.
  3. Offloading over PCIe without doing the arithmetic. Divide the bytes by 64 GB/s first.
  4. Writing checkpoints straight to object storage. It stalls the job.
  5. Dropping KV caches that could be reused. Recomputing a prefix costs more than keeping it in CPU memory.

10. Hands-on exercise#

  1. Run state.go. Change the model to 405B. How many GPUs do you need under FSDP to stay under 100 GB per GPU?
  2. Using 12.f’s KV numbers (163,840 bytes per token for a 70B model at FP8), how much CPU memory would hold 10,000 distinct, recurring 4k-token prefixes?
  3. On a Grace-Blackwell machine, compare optimizer offload time over NVLink-C2C (900 GB/s) with PCIe Gen 5 (64 GB/s) for a 70B model’s 840 GB of optimizer state.
  4. Add a “CPU memory, 2 TB/s across 64 nodes” row to the checkpoint list. When does it beat NVMe?

11. Interview questions#

  1. What are the 16 bytes per parameter of mixed-precision Adam?
  2. What does each ZeRO stage shard?
  3. Why do checkpoints go to local NVMe before the parallel file system?
  4. Name three places a KV cache block can live, from fastest to slowest.
  5. Why does NVLink-C2C change the case for CPU offload?

12. Further reading#

Checked on 12 November 2026.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in