---
title: "Pretrain a small language model"
lesson_id: "05"
---

# Pretrain a small language model

- **Lesson ID:** 05
- **Goal:** Train 10M to 100M parameters until loss, grad norms, and tokens-per-second mean something you can defend.
- **Human lesson:** [05-pretrain-a-small-lm.html](05-pretrain-a-small-lm.html)
- **Phase:** Phase 3 Training

## Prerequisites

- The previous week's artifact, or a written note if this is week 1.
- Python 3.11+ and a laptop. CUDA is useful from week 5 onward and not required to read.

## Inputs, outputs, and artifacts

- **Inputs:** The replica from the prior week.
- **Outputs:** Core project 3: a small LM checkpoint with a training log you trust.
- **Artifacts:** Lesson notes plus the code named in the human page.

## Agent build steps

1. State the week 1 principle: you do not need to pretrain an 800B model to understand the shape of the problem; you do need progressively realistic replicas.
2. Teach the topics on the human page without inventing paper URLs or news claims.
3. Keep starter code in fenced blocks that match the human lesson.
4. End with the assignment and the opinion checkpoint.
5. Use Edge FDE tone: ship, do not sightseeing. Opinion checkpoints matter.

## Constraints

Plain spoken English. No quizzes. No em dashes. No invented metrics, dates, or citations. Brand Edge FDE only. Name well-known papers by title only: Attention Is All You Need, InstructGPT, Direct Preference Optimization, ZeRO, PagedAttention/vLLM, FlashAttention, Scaling Laws for Neural Language Models.

## Key concepts

- A pretrain replica is data, step, log, checkpoint, resume.
- Non-finite loss is a stop condition.
- Clip rate and grad norm are first-class logs.
- 10M to 100M is enough to feel instability without a cluster.

## Takeaways

- Use train_step as written, including the finite-loss guard.
- Resume once before you call the run real.
- Report measured tokens per second, not a hoped number.

## Acceptance checks

- Human HTML has Key concepts and Takeaways.
- Opinion checkpoint is present.
- No em dash and no fake URL.
- [ ] Proceed to [lesson 06 brief](06-distributed-training-simulation.llms.md).
