2400: LLM Pretraining¶
Pretrain a language model from scratch — data, tokenization, training objectives, distributed execution, and evaluation.
Contents¶
- Module Overview
- Learning Objectives
- Module Contents
- Learning Path
- Prerequisites
- Assessment
- Related Modules
- Time Commitment
- Resources
- Tips for Success
- Common Pitfalls
- Scale Requirements
- Training Checklist
- Summary
- References
- Next Steps
Module Overview¶
This module covers the complete journey of pretraining large language models, from fundamentals to distributed training at scale. You'll learn how modern LLMs like GPT and LLaMA are trained from scratch.
Why This Matters:
- Pretraining is the foundation of all LLM capabilities
- Understanding training dynamics helps with fine-tuning and debugging
- Scale brings unique challenges (distributed training, optimization)
- Evaluation frameworks determine model quality
Learning Objectives¶
After completing this module, you will be able to:
- Pretraining Fundamentals: Understand data curation, tokenization, and training objectives
- Distributed Training: Configure and debug multi-GPU and multi-node training
- Optimization Strategies: Implement learning rate schedules, optimizers, and stability techniques
- Evaluation Frameworks: Build comprehensive evaluation pipelines
- Production Training: Manage training runs, checkpoints, and fault tolerance
Module Contents¶
Each lesson is written around runnable code — work through the examples, don't just read them.
Lesson 2401 — Data, Objectives, and Training Dynamics¶
2401: Pre-training Fundamentals
- Data collection and curation pipelines
- Tokenization strategies (BPE, SentencePiece, Unigram)
- Training objectives (causal LM, masked LM, seq2seq)
- Hyperparameter selection and tuning
- Training stability and convergence
Lesson 2402 — Distributed Training Infrastructure¶
2402: Large-Scale Training for Language Models
- Data parallelism (DDP, FSDP)
- Tensor parallelism for model parallelism
- Pipeline parallelism strategies
- Mixed precision training (FP16, BF16)
- Gradient accumulation and checkpointing
Lesson 2403 — Measuring LLM Performance¶
2403: Evaluation Frameworks for Language Models
- Perplexity and cross-entropy metrics
- Downstream task evaluation (MMLU, BIG-bench, HELM)
- Human evaluation frameworks
- Bias and safety evaluation
- Logging and monitoring dashboards
Learning Path¶
- Verify readiness with 2400: LLM Pretraining - Prerequisites
- 2401: Pre-training Fundamentals — data, tokenization, objectives, training loop
- 2402: Large-Scale Training for Language Models — scale the loop across devices
- 2403: Evaluation Frameworks for Language Models — measure what you trained
- Check understanding with the 2400: Pretraining Fundamentals - Quiz
- Apply it with the 2400: Pretraining - Practice exercises
Prerequisites¶
Required:
- 2100: Calculus for Deep Learning — backpropagation, optimization
- 2200: Deep Learning Frameworks — PyTorch proficiency
- 2300: Framework Engineering — ML system design
Helpful:
- Transformer architecture at an intuition level (attention, blocks, embeddings) — this module treats the architecture as a given; Phase 3: Transformer Physics & LLM Internals [3000] studies it in depth
- Multi-GPU hardware (or cloud resources) — required only for the full-scale distributed exercises in 2402; the fundamentals run on a single GPU
Review: 2400: LLM Pretraining - Prerequisites for detailed requirements with runnable self-check examples.
Assessment¶
Knowledge Check¶
- 2400: Pretraining Fundamentals - Quiz — self-graded questions across all three lessons
Practice Exercises¶
- Format: End-to-end pretraining project
- Duration: 8-12 hours
- Topics:
- Build a complete pretraining pipeline
- Implement distributed training
- Create evaluation framework
- Train and evaluate a small LLM
- Location: 2400: Pretraining - Practice
Related Modules¶
- 3100: Attention Architectures — the architecture every pretrained model is built from, studied in depth
- 4100: Low-Bit Quantization — making the pretrained result cheap to store and serve
- 5100: Parameter-Efficient Fine-Tuning (PEFT) — adapting pretrained weights without re-pretraining
- 1400: LLMOps and Model Serving — operating the models this module trains
Time Commitment¶
| Activity | Time |
|---|---|
| Reading (2401) | 4 hours |
| Experiments (2401) | 4 hours |
| Reading (2402) | 6 hours |
| Experiments (2402) | 6 hours |
| Reading (2403) | 3 hours |
| Experiments (2403) | 4 hours |
| Practice | 8-12 hours |
| Total | 35-39 hours |
Resources¶
Essential Papers:
- Attention Is All You Need (Vaswani et al.) — the transformer architecture
- Language Models are Few-Shot Learners (Brown et al.) — GPT-3 and what scale buys
- LLaMA: Open and Efficient Foundation Language Models (Touvron et al.) — open-weights pretraining at scale
- Training Compute-Optimal Large Language Models (Hoffmann et al.) — the Chinchilla token-budget scaling laws
Essential Tools:
- PyTorch Distributed (DDP, FSDP)
- Hugging Face Transformers
- Weights & Biases / MLflow
- DeepSpeed / Megatron-LM
Tips for Success¶
- Start small: Train tiny models before scaling up
- Profile everything: Identify bottlenecks before optimizing
- Monitor training: Set up comprehensive logging early
- Use existing tools: Don't reinvent distributed training
- Document experiments: Track hyperparameters and results
Common Pitfalls¶
- Underestimating data quality: Bad data ruins models
- Ignoring compute costs: Pretraining is expensive
- Poor monitoring: Training failures waste resources
- Overlooking tokenization: It affects model quality significantly
- Skipping evaluation: You can't improve what you don't measure
Scale Requirements¶
| Model Size | GPU Memory | Training Time | Hardware |
|---|---|---|---|
| 125M params | 8GB | 1-2 days | 1x A100 |
| 1B params | 40GB | 1-2 weeks | 8x A100 |
| 7B params | 80GB | 3-4 weeks | 64x A100 |
| 70B params | 80GB | 2-3 months | 512x A100 |
Order-of-magnitude estimates for full pretraining runs at Chinchilla-or-larger token budgets (the rows correspond roughly to 10B / 100B / 500B / 1T+ training tokens). Cost scales linearly in tokens: the standard rule of thumb is 6·N·D FLOPs for N parameters and D training tokens — e.g. 125M params on 10B tokens is ~7.5e18 FLOPs, about a day on one A100 at realistic utilization. See the Chinchilla paper for compute-optimal token budgets.
Training Checklist¶
Before starting pretraining:
- Data collected and cleaned
- Tokenizer trained and tested
- Training code validated on small model
- Distributed training configured
- Monitoring and logging set up
- Checkpoint strategy defined
- Evaluation pipeline ready
- Fault tolerance tested
Summary¶
- This module is the full pretraining arc: data and objectives, distributed execution, evaluation — closed by a quiz and hands-on practice.
- It is the last module of Phase 2: everything before it builds the tools, everything after it (Phase 3+) assumes a trained model exists.
- Plan for 35-39 hours (13 hours reading + 14 hours lesson experiments + 8-12 hours practice); the distributed lessons need multi-GPU access, the rest runs on one GPU.
- Pretraining cost is dominated by data quality and token budget, not model size — read the Chinchilla scaling laws before you spend GPU-hours.
References¶
Related Documents¶
- 2401: Pre-training Fundamentals — data curation, tokenization, training objectives
- 2402: Large-Scale Training for Language Models — DDP/FSDP, tensor and pipeline parallelism, mixed precision
- 2403: Evaluation Frameworks for Language Models — perplexity, benchmarks, safety evaluation
- 2400: LLM Pretraining - Prerequisites — readiness check with runnable self-test examples
- 2300: Framework Engineering — previous module; the engineering practices this module applies
External References¶
- Attention Is All You Need — Vaswani et al., the transformer architecture
- Language Models are Few-Shot Learners — Brown et al., GPT-3 and scale
- LLaMA: Open and Efficient Foundation Language Models — Touvron et al., open-weights pretraining
- Training Compute-Optimal Large Language Models — Hoffmann et al., Chinchilla scaling laws
Next Steps¶
- Not reviewed yet? Start with 2400: LLM Pretraining - Prerequisites and run its self-check examples.
- Work the lessons in order: 2401: Pre-training Fundamentals → 2402: Large-Scale Training for Language Models → 2403: Evaluation Frameworks for Language Models — each builds on the previous one.
- Close the loop: take the quiz, then the practice exercises.
- Continue to Phase 3: 3100: Attention Architectures
Related: 2300: Framework Engineering · 2401: Pre-training Fundamentals · 3100: Attention Architectures
Experiment: No EXP_24xx exists yet — nearest relevant: EXP_2201: PyTorch Computational Graphs (the autograd mechanics every training loop in this module rests on).