- 1Raw text → Tokenizer → Token IDs
- 2Batch Assembly —
get_batch() - 3Token Embedding Lookup
- 4Position Embedding Lookup — a SECOND, separate table
- 5Combine:
x = tok_emb + pos_emb - 6Single-Head Attention
- 7Multi-Head: Concat + Project
- 8Transformer Block
- 9Stack ×n_layer
- 10Final LayerNorm + LM Head → Logits
- 11Loss — Cross-Entropy
- 12Backward Pass + Optimizer Step
- 13Prefill — Process the Whole Prompt in Parallel
- 14Incremental Decode — One New Token at a Time
- 15Softmax → Probability Distribution
- 16Sample Next Token
- 17Append & Loop
- 18KV Cache — Reuse Instead of Recompute
- 19Sliding Window — Cap at block_size
- 20Loop Back to Decode