TensoriumInterview preparation
← Home

Core concepts · 62 topics

A guided path through the ideas behind modern LLMs.

Read the stages in order: how text becomes a prediction, what happens inside the Transformer block, how a model learns, then serving, scale, and post-training. Every topic names what to know first, then gives the intuition, the math with concrete numbers, the common misconception, and a self-check. Already comfortable with the basics? Switch to By area and jump straight to a topic.

New to machine learning? Start here instead.

These topics work best as a refresher; they assume ideas like probability and loss. Begin with three short beginner lessons (tokens, embeddings, next-token prediction), then the visual walkthrough for attention and the Transformer.

Finish line: You can explain how text becomes a prediction and what training does to improve that prediction.

Topic 39 of 62 · Training at scale

FSDP, ZeRO, and training memory

Hard

What do ZeRO-1, ZeRO-2, and ZeRO-3 / FSDP shard, and why is peak GPU memory higher than the sharded floor?

Why this mattersZeRO and FSDP replace replicated model state with sharded ownership plus on-demand collectives, making it possible to train models that are many times larger than a single GPU.

1 · Start with the intuition

In standard DDP, every GPU holds an identical copy of the optimizer states, gradients, and weights—wasting (D − 1)/D of your cluster’s memory on duplicates. ZeRO (and PyTorch FSDP) eliminates that redundancy in three stages across D data-parallel ranks: ZeRO-1 shards the optimizer states (cutting the 12 bytes/param of FP32 master weights + Adam moments by D); ZeRO-2 also shards the gradients (using reduce-scatter instead of all-reduce); and ZeRO-3 / FSDP FULL_SHARD also shards the parameters themselves, all-gathering a layer’s weights just before its forward or backward pass and freeing them immediately after.

2 · How the mechanism works

Mechanism step 1 of 3 · no question to answer

Shard persistent state

Each rank permanently stores only 1/D of the optimizer state (ZeRO-1), + gradients (ZeRO-2), + parameters (ZeRO-3 / FSDP).

Next, we will look at: All-gather per layer. Move on when this operation makes sense.

Visualizing the behavior

Persistent memory per rank: 1B params, 4 data-parallel ranks

Derived
DDP (fully replicated)16 GB
2
2
12
ZeRO-1: shard optimizer states7 GB
2
2
3
ZeRO-2: + shard gradients5.5 GB
2
3
ZeRO-3 / FSDP full shard4 GB
3
  • BF16 weights (2 B/param)
  • BF16 gradients (2 B/param)
  • FP32 master + Adam m, v (12 B/param)
The ZeRO formulas: (2 + 2 + 12)Ψ → (2 + 2 + 12/N)Ψ → (2 + 14/N)Ψ → 16Ψ/N. Excludes activations, temporary all-gather buffers and fragmentation, which often decide whether a run actually fits.