The map
The complete route, with the logic that holds it together. Each stage exists because the previous one ran into a concrete wall. That is the structure of the project and the real history of the field.
The chain of problems
I want a machine to "learn"
│
├─ [00] What is learning? -> adjusting numbers to bring an error down
│ WALL: a linear model cannot even solve XOR
│
├─ [00.3] Solution: layers + non-linearity
│ WALL: differentiating by hand does not scale past 20 parameters
│
├─ [03] Solution: autograd (the chain rule, automated)
│ WALL: and how does TEXT get into any of this?
│
├─ [01] Solution: tokenization (text -> integers)
│ WALL: what exactly is "a language model"?
│
├─ [02] Answer: P(next token | context). Counting already works.
│ WALL: counting does not scale. 5 characters of context = 600 GB
│
├─ [04] Solution: embeddings + dense network (grows linearly, not exponentially)
│ WALL: concatenation is rigid; it does not choose WHAT to look at
│
├─ [05] Solution: ATTENTION (each token chooses where it gets information from)
│ WALL: it all has to be assembled and actually train
│
├─ [06] Solution: the complete TRANSFORMER. And it works.
│ WALL: at a certain scale, training runs break
│
├─ [07] Solution: AdamW, warm-up, init, clipping, regularization
│ WALL: generating is painfully slow and the model does not fit on the laptop
│
├─ [08] Solution: KV cache, sampling, quantization
│ WALL: the model continues text, it does not answer questions
│
├─ [09] Solution: SFT with loss masking (+ LoRA to make it cheap)
│ WALL: it imitates whatever you give it, it does not know which answer is BETTER
│
├─ [10] Solution: preference alignment (DPO)
│ WALL: how does any of this reach a chat box?
│
├─ [11] Solution: server, template, streaming, context management
│ WALL: it knows nothing new and it cannot act
│
├─ [12] Solution: RAG (data) and tools (action)
│ WALL: how do I know whether any of this works?
│
└─ [13] Solution: evaluate specific capabilities, against a chance baseline
What each stage proves (measured results)
| Stage | Claim | How it is checked | Result |
|---|---|---|---|
| 00.2 | The learning rate has an exact limit | Compute 2/λmax of the Hessian and try just above and just below | 0.04175 converges · 0.04428 explodes |
| 00.3 | A linear model cannot do XOR | Train it to the end | Predicts 0.500 for everything |
| 01.2 | BPE discovers morphology without knowing grammar | List the learned tokens | 'ción', 'ando', ' el', ' de' appear |
| 02.2 | Gradients and counting end up in the same place | Compare the probability tables | Mean difference 0.001 |
| 03 | The autograd is correct | 34 checks against finite differences | 34/34 correct |
| 04.2 | "Vowels cluster in the embeddings" | Measure against the chance baseline | Input: NO (65.7% vs 64.7%). Output: YES (81.0%) |
| 05 | The 1/√dk is not decorative | Measure the softmax entropy with and without it | Without it and dk=64: entropy 0.000 (dead gradient) |
| 06 | You can train a GPT on a laptop | Do it | 810k parameters, 9.2 min, readable Spanish |
| 06.4 | What is written in NumPy is a real transformer | Load its weights into a PyTorch GPT and compare logits | Relative difference 1.0e-06, same token in all 256 positions |
| 06.4 | With enough data, overfitting disappears | Train 4.2 M parameters with 77 M tokens (Chinchilla) | training 0.2304 · validation 0.2387 (nearly equal) |
| 07.1 | AdamW beats SGD | Same model, same seed, 300 steps | SGD 2.68 · momentum 2.25 · AdamW 1.93 |
| 07.2 | Without residuals the gradient dies | Measure the gradient norm at layer 1 with 30 and 100 layers | With init 0.02 and no residual: exactly 0.0 |
| 07.3 | More data beats regularization | 4 experiments compared | 6k tokens + dropout: 1.52 · 200k with nothing: 0.81 |
| 08.2 | The KV cache speeds things up without changing the result | Compare logits and times | Difference 2.5e-06 · 16.8× faster |
| 08.3 | int4 works, but only in groups | Quantize and measure the loss | Per tensor: +0.256 · in groups of 64: +0.027 |
| 09.1 | SFT teaches format, not knowledge | Test with held-out questions | Seen: perfect · new: format right, content wrong |
| 09.1 | Evaluating without chunking blows up memory | Measure the process RSS | Peak 8.9 GB and SIGKILL; in batches, it works |
| 09.2 | LoRA does not alter the model at the start | Compare logits before and after adding it | Difference 0.00e+00 |
| 10 | DPO raises the preferred answer over the rejected one | Measure the margin before and after | 86.2% → 97.0% accuracy |
| 12.1 | An LLM's embeddings are no good for search | TF-IDF against the GPT, same test | TF-IDF 88% · neural 25% |
| 12.3 | Tools change the result | Same model, with and without a calculator | Alone: 0% · with the tool: 91% |
| 13 | An aggregate number does not compare models | Dependency test at 44 characters | Mean loss: tied · this test: 100% vs 50% |
All of these numbers come from running the scripts. If you run them and get something else, yours is the one that counts.
The seven ideas holding everything up
If you had to keep seven sentences:
- A model is a function with gaps in it. Training is filling the gaps so that it fails less. (Stage 00.)
- The chain rule automates it. Backpropagation = walking a graph backwards multiplying local derivatives. (Stage 03.)
- Text goes in as integers. Whatever ends up inside a token is, for the model, an indivisible atom. (Stage 01.)
- A language model returns a probability distribution over the next token. Nothing more. (Stage 02.)
- Embeddings make generalization possible. Similar contexts → similar vectors → the model gets combinations right that it never saw. (Stage 04.)
- Attention lets each token choose where it gets its information from, by content rather than position. (Stage 05.)
- The rest is scale and engineering. There is no secret eighth idea. (Stages 06-13.)
Recommended order
If you have an afternoon: 00 → 01 → 02 → 05 → docs/01-del-teclado-al-token.md. You will understand 70% with 20% of the effort.
If you have a weekend: all of it in order, running every script.
If you have a technical background and want the core: mininn/tensor.py → etapas/06_transformer/gpt.py → etapas/08_inferencia/02_kv_cache.py. Three files, and they contain the essentials.
If what you want is to use AI, not build it: docs/01, docs/05 and stage
- Knowing where it fails is what will serve you most.
Index of documents
- 01-del-teclado-al-token.md — the exact trace of a message
- 02-como-nace-un-modelo.md — the life cycle with real figures
- 03-matematicas-minimas.md — what you need and nothing more
- 04-hardware-y-escala.md — GPUs, memory and scaling laws
- 05-fallos-y-limites.md — why it fails, mechanism by mechanism
- 06-plan-apocalipsis.md — rebuilding all of it with no internet
- 07-glosario.md — Spanish ↔ English
- 08-mas-alla.md — RoPE, MoE, reasoning, Mamba: what exists and we have not implemented
- 09-historia.md — when, who and against what resistance: from 1943 to 2025
- 10-lo-que-no-cubre.md — where what you learn here runs out
- 11-otras-modalidades.md — image, diffusion, audio, video, multimodal
- 12-entrenamiento-distribuido.md — when the model does not fit on one GPU
- 13-agentes-y-multiagente.md — the loop, the patterns, the frameworks and when NOT to use them
- 14-roles-profesionales.md — AI Engineer, AI Developer, ML Engineer: who does what
- 15-herramientas.md — Ollama, Hugging Face, LM Studio and the rest, with a decision map
- 16-terminos-actuales.md — today's vocabulary, organized by topic