Models & Sampling
How a model is made, how it picks each token, and how to tame the randomness.
Training pipeline
| Stage | Data | Result |
|---|---|---|
| Pre-training | Web-scale text, self-supervised | A text completer; ~98% of compute (InstructGPT) |
| Supervised finetuning (SFT) | (prompt, response) demonstrations | Converses instead of just completing |
| Preference finetuning | (prompt, winner, loser) comparisons → reward model (RLHF), or DPO / RLAIF | Responses people prefer |
SFT + preference finetuning = post-training. Memory napkin math: parameters × 2 bytes (16-bit) ≥ inference memory, so 7B → 14 GB.
Sampling pipeline
logits ÷ temperature → softmax → top-k → top-p → sample
| Need | Settings |
|---|---|
| Consistent output (grading, classification, extraction) | Temperature 0 (greedy), fixed seed, cache answers |
| Creative output (taglines, brainstorming) | Temperature ≈ 0.7 as a starting point, top-p 0.9–0.95 |
| Smaller, cheaper softmax | Top-k (50–500) |
| Context-sized candidate pool | Top-p (nucleus) |
| Cap latency and cost | Max tokens or stop tokens, with enough headroom for structured output |
| Higher quality, more money | Test-time compute: best-of-N (cost ≈ N×) |
Worked example: logits [1, 2]. At T = 1, B = 73%. At T = 0.5, B = 88%. As T → 0, B → 100%.
Probabilistic failure modes
| Problem | Cause | Mitigation |
|---|---|---|
| Inconsistency (same input) | Sampling randomness; hardware | Fix sampling variables and seed; cache. Still not guaranteed. |
| Inconsistency (slightly different input) | Model sensitivity | Careful prompts (Ch 5), memory (Ch 6) |
| Hallucination | Self-delusion (treats its own output as fact; snowballs) · knowledge mismatch with SFT labelers | Concise answers, “say I don't know,” grounding with context (Ch 5–6), detection (Ch 4) |