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 52 of 62 · Wider ML toolkit

BatchNorm: sharing statistics across examples

Easy

What does BatchNorm normalize, and why is it usually not the right norm inside an autoregressive Transformer?

Practice choosing normalization methods · 8 scenarios ↓

1 · Start with the intuition

Imagine one feature channel becoming much larger than the others. BatchNorm estimates that channel’s mean and variance from many observations, then standardizes it. The important question is which observations it pools: they include other examples, not just the token being processed.

2 · How the mechanism works

Mechanism step 1 of 3 · no question to answer

Choose the channel

For images [B,C,H,W], pool B,H,W separately for each C. For BatchNorm1d on [B,C,T], pool B,T.

Next, we will look at: Center and scale. Move on when this operation makes sense.

Visualize which values share statistics

Derived toy tensor [B=2,T=3,C=4]. Select any cell: orange outlines your selection; teal cells contribute to its normalization statistics. Each cell shows input ↓ output. Training behavior, ε=10⁻⁵, γ=1, β=0; learned affine transforms are omitted.

Across batch B and positions T, separately per channel C.

Sample 0 · rows = positions T

c0c1c2c3t0t1t2

Sample 1 · rows = positions T

c0c1c2c3t0t1t2

Selected: sample 0, position 0, channel 0 · 6 values share statistics

Channel c across both samples and every position

(x − mean_B,T) / √(var_B,T + ε)

μ=3.500, variance=3.917, √(variance+ε)=1.979

(1 − 3.500) / 1.979 = -1.263

Try selecting sample 0, then moving “Shift sample 1 only”: only BatchNorm changes sample 0’s output. A global offset cancels in the centered norms but not RMSNorm. Variance uses the population denominator; rounded displays may differ slightly from the full-precision calculation.

# x is [B,T,C]; C=4
nn.BatchNorm1d(C)(x.transpose(1, 2)).transpose(1, 2)

Which one do I need?

Normalization controls the scale seen by sublayers; it does not replace a task loss or an explicit generalization regularizer. Preserve the norm used by a pretrained checkpoint rather than swapping it at inference.

MethodChoose it when…Train → eval
BatchNormCNN feature maps with adequate batch statistics. Not the usual decoder norm: sequence-wide training statistics can leak future-token information.Usually frozen running mean/variance in eval; with track_running_stats=False, uses batch statistics even in eval.
LayerNormA standard Transformer choice when per-token centering and scaling are wanted; independent of batch size and sequence neighbors.Current token statistics in both train and eval; no running averages.
GroupNormCNNs and convolutional diffusion blocks with small batches. Standard sequence-wide GroupNorm is not a causal per-token decoder norm.Current sample/group statistics in both train and eval; no running averages.
RMSNormCommon in modern decoder-only Transformers when controlling activation scale without centering is sufficient; fewer normalization operations, not a guaranteed speedup.Current token RMS in both train and eval; no running averages.

For tensors [B,T,C], token-local LayerNorm(C)/RMSNorm(C) do not read future positions. BatchNorm1d and GroupNorm after transposing to [B,C,T] do. A causal attention mask does not undo leakage introduced by a sequence-wide normalization.