Big-O — how cost grows
Read "order of" or "big O of". It describes how cost grows as the input gets bigger, ignoring constant factors. O(N²) means doubling N roughly quadruples the work.
- : constant, the same at any size.
- : linear, double the input and double the work.
- : quadratic, like building the attention matrix.
- : cubic, like generating tokens while recomputing all attention from scratch each step, with no KV cache.
Constant factors are dropped on purpose, so big-O answers "how does this scale?" and not "how fast is it?". At real sizes, a well-optimized method can beat a poorly written one.
Example
Recomputing the full t×t attention matrix at every step t of generation, for T steps, costs cubic time overall.
Where the course uses it
- 1.5 Embeddings: From a Token to a Vector · Module 1, Shapes and Linear Algebrafirst use
- 5.3 No Parallelism Across Time · Module 5, Sequences Before Transformers
- 5.4 Vanishing and Exploding Gradients · Module 5, Sequences Before Transformers
- 5.6 The First Attention · Module 5, Sequences Before Transformers
- 12.2 The KV Cache · Module 12, Generation
- 16.2 FlashAttention and the Online Softmax · Module 16, Efficient and Long Attention
- 27.3 The CTC Objective and Its Recursion · Module 27, Recognition: OCR and Speech With CTC