Why hide the future
The cheating problem
Seven lessons from one forward pass
The mask itself
Building the triangle row by row
mask[i, j] = 0 if j ≤ i, −∞ if j > i scores ← scores + mask
Mask before softmax, not after
A live causality test
More masks
Causal + padding = combined mask
Three mask shapes, three model families
Exceptions and sharp edges
Off by one on the diagonal
use torch.triu(…, diagonal=1) for the masked part.Suspiciously low loss
run the causality test from fig 8.5 on your model.Pad rows with nothing to see
let pad rows see something, and mask them out of the loss.Generation needs no triangle
pass the right mask for prefill vs decode, see chapter 11.Sliding windows
combine masks by AND, never by overwriting.