# LLM Foundations This section explains the ideas that the training code assumes you know. It is not a PyTorch primer. It is a bridge between the source files in this repository and the core concepts behind modern decoder-only language models. The priority is: 1. understand the base model and pretraining mechanics; 2. connect those mechanics to every existing stage in the site; 3. use the same language later for SFT, reward models, DPO, PPO, and GRPO. ## The whole training story ```mermaid flowchart LR RAW[raw text] --> TOK[tokenizer] TOK --> IDS[token ids] IDS --> BASE[decoder-only Transformer] BASE --> CE[next-token cross-entropy] CE --> CKPT[base checkpoint] CKPT --> SFT[SFT: instruction following] SFT --> PREF[preference optimization] PREF --> RL[RL / verifier optimization] RL --> CHAT[inference and chat] classDef data fill:#d6ffd9,stroke:#27ae60,stroke-width:2px,color:#143d1a; classDef model fill:#ffe8a3,stroke:#d48806,stroke-width:2px,color:#5a3d00; classDef loss fill:#ffd6d6,stroke:#c0392b,stroke-width:2px,color:#5c1212; class RAW,TOK,IDS data; class BASE,CKPT,SFT,PREF,RL,CHAT model; class CE loss; ``` At the base level, an LLM is a conditional probability model: \[ p_\theta(x_1, x_2, \ldots, x_T) = \prod_{t=1}^{T} p_\theta(x_t \mid x_{