Modeled on Stanford CS336

从零构建大语言模型

LLM from Scratch

Hand-build every piece of an LLM, along the 17-lecture skeleton of Stanford CS336

8 labs25 AI-mentored sessions~12 hoursBilingual · EN / 中
Start learning →

About this course

A build-it-yourself course: no passive lectures. In every session an AI mentor walks you
through writing code, tuning knobs, and reading curves — building an LLM from characters
all the way to alignment. It follows the full 17-lecture skeleton of Stanford CS336
(Language Modeling from Scratch) 1:1 — tokenization, architecture, systems, scaling laws,
inference, data, alignment — with every session rewritten as original hands-on teaching
for the online sandbox.

What you'll learn

  • Hand-implement BPE tokenization, embedding similarity, and a full gradient-descent training loop
  • Account for a model's FLOPs/memory and reason about architecture & hyperparameters (incl. MoE)
  • Explain how GPUs, kernels and parallelism determine training throughput
  • Use scaling-law reasoning to trade off model size vs data
  • Understand inference optimization (KV cache/batching), evaluation (perplexity/benchmarks) and data pipelines
  • Explain what SFT/RLHF/RLVR and multimodal alignment do, and why they work

Syllabus

1Foundations: Tokens, Embeddings & the Training Loop3 sessions
  • 1From Characters to Tokens: Build a BPE Tokenizer25 minStart →
  • 2Giving Tokens Meaning: Embeddings and Cosine Similarity25 minStart →
  • 3The Training Loop: How Gradient Descent Makes a Model Learn30 minStart →
2Attention & the Transformer: Build the Model's Heart by Hand4 sessions
  • 1Attention: Letting Each Token See What Matters30 minStart →
  • 2Multi-Head & Position: Parallel Views + a Sense of Order30 minStart →
  • 3Assembling the Transformer: The Pre-Norm Residual Block & a Full Forward Pass30 minStart →
  • 4End-to-End Training: Teaching Your Transformer to Speak30 minStart →
3Architecture: Resource Accounting, Hyperparameters & MoE3 sessions
  • 1Resource Accounting: FLOPs, Memory & Arithmetic Intensity30 minStart →
  • 2Architectures & Hyperparameters30 minStart →
  • 3Attention Alternatives & Mixture of Experts30 minStart →
4Systems: GPUs, Kernels & Parallelism5 sessions
  • 1GPUs & TPUs30 minStart →
  • 2Kernels & Triton30 minStart →
  • 3FlashAttention: Cutting Attention's Memory Bill from O(n²) to O(n)30 minStart →
  • 4Parallelism Basics: DP, TP, PP30 minStart →
  • 5Advanced Parallelism: ZeRO, FSDP & Hybrids30 minStart →
5Scaling Laws: Spending Compute Wisely2 sessions
6Inference & Evaluation2 sessions
  • 1Inference: KV Cache & Throughput35 minStart →
  • 2Evaluation: Perplexity, Benchmarks & Contamination30 minStart →
7Data: Sources, Curation & Mixing2 sessions
  • 1Data Sources30 minStart →
  • 2Data Curation: Filtering, Dedup, Mixing & Synthetic30 minStart →
8Alignment: SFT, RLVR & Multimodality4 sessions
  • 1Alignment I: SFT & RLHF30 minStart →
  • 2DPO: Aligning Straight from Preferences, No Reward Model30 minStart →
  • 3RLVR: RL with Verifiable Rewards30 minStart →
  • 4Multimodal Alignment30 minStart →

Same series · 世界名校知名实验室系列

Flagship University Lab Series

Modeled on Stanford / MIT / Berkeley syllabi — learn from scratch with a mentor Agent guiding you in real time.