Stanford CS336: Language Modeling from Scratch

Author

Chao Ma

Published

October 13, 2026

Notes following Stanford CS336, Spring 2026, taught by Percy Liang and Tatsunori Hashimoto. The course connects model construction with systems, scaling, data, evaluation, and post-training.

Official course and materials · Official lecture recordings

Notes

What a Visual Token Keeps—and What It Costs Lecture 17: CLIP, SigLIP, visual features, multimodal token budgets, and image generation.

A Verifiable Reward Still Leaves an Optimization Problem Lecture 16: GRPO, normalization, reasoning-model recipes, and verification.

Post-Training Changes Which Answers a Model Favors Lecture 15: SFT, feedback collection, PPO, and the DPO derivation.

A Data Mixture Is Also a Repetition Schedule Lecture 14: quality filtering, MinHash LSH, finite data, and synthetic trajectories.

The Same Web Can Produce Different Training Data Lecture 13: data sources, extraction, selection, provenance, and training exposure.

An Evaluation Score Comes with a Protocol Lecture 12: perplexity, preferences, agent budgets, and measurement validity.

Scaling a Language Model Means Scaling Its Training Recipe Lecture 11: WSD, hyperparameter scaling, and feature learning with μP.

Inference Gets Faster When Less State Has to Move Lecture 10: KV caches, speculative sampling, and dynamic serving.

A Compute Budget Is a Choice Between Parameters and Tokens Lecture 9: Power laws, critical batch size, and compute allocation.

Sharding a Model Changes When Memory Is Needed Lecture 8: ZeRO, FSDP, activation memory, and combined parallelism.

Parallel Training Starts with Deciding What Moves Lecture 7: collectives, gradient weighting, tensor partitions, and pipeline bubbles.

A Faster Kernel Starts with Fewer Memory Trips Lecture 6: timing, fusion, Triton masks, row reductions, and matrix tiling.

Peak FLOPs Are Only One Ceiling Lecture 5: GPU and TPU memory, roofline bounds, tile scheduling, and online softmax in FlashAttention.

More Capacity, Less Work per Token Lecture 4: recurrent states, sparse attention, MoE routing, and the cost of conditional computation.

Transformer Architecture Is Also a Systems Decision Lecture 3: residual paths, gated FFNs, RoPE, hyperparameters, and the KV-cache budget.

A Tokenizer Changes the Work a Language Model Has to Do Lecture 1: course overview, lossless text representation, and BPE as a sequence-length and vocabulary tradeoff.

Course path

  • Lectures 1–4: tokenization, resource accounting, architectures, and attention alternatives.
  • Lectures 5–8: accelerators, kernels, and parallelism.
  • Lectures 9–11: scaling laws and inference.
  • Lectures 12–14: evaluation and data.
  • Lectures 15–17: post-training, verifiable rewards, alignment, and multimodality.

The lecture notes above follow this path in order. Earlier material on LLM agents and deep learning systems provides complementary perspectives.

Lecture 2: PyTorch and Resource Accounting

Shapes, training memory, FLOPs, and the cost of moving data.