Welcome! ๐
This repository contains 160+ pages of handwritten notes that I created while taking Stanford CS336: Language Modeling from Scratch (Spring 2024).
The course, instructed by Percy Liang and Tatsunori Hashimoto, provides a comprehensive introduction to the principles and systems behind modern Large Language Models (LLMs), covering topics from pre-training datasets, tokenization, transformer architectures, LLM pretraining to distributed training, inference and LLM serving, memory optimization, GPU benchmarking and profiling, collective communcation, AI evaluation, and RL alignment and policy optimization, ect.
My goal was not simply to pass the course, but to build a deep understanding of how LLMs are developed from the ground up.
Throughout the course, I handwrote detailed notes to reinforce my understanding of the mathematical foundations, implementation details, systems concepts, and engineering trade-offs. Looking back, these notes played an important role in shaping my knowledge of:
- ๐ง Transformer core principles (attention, positional encoding, architecture design)
- ๐ค Tokenization and vocabulary construction (BPE, SentencePiece)
- โ๏ธ PyTorch fundamentals and tensor ops (einops) for LLM implementation
- ๐งน Dataset preparation, cleaning, filtering, and corpus engineering
- ๐งช Data-centric techniques (data mixing, rewriting, SFT pipelines)
- ๐ Scaling laws and dataโmodelโcompute trade-offs
- ๐๏ธ Pretraining objectives & training dynamics (causal LM, masked LM)
- ๐ฏ Fine-tuning strategies (SFT, instruction tuning)
- ๐ค Model alignment (RLHF, DPO, RL algorithms)
- โก Inference systems (latency vs throughput, batching, serving)
- ๐ Evaluation methodologies (perplexity, downstream benchmarks)
- ๐ป GPU & TPU architecture + memory optimization
- ๐ Resource accounting (roofline), profiling & performance tuning
- ๐ Distributed training (data/model/pipeline parallelism)
- ๐ Collective communication (AllReduce, NCCL)
- ๐งฉ Mixture of Experts (MoE) and sparse architectures
- ๐งฌ Kernel-level optimization (CUDA, Triton)
- ๐ง Compiler stacks & graph optimization (XLA)
- ๐ KV Cache, Flash Attention, efficient attention mechanisms
- ๐ข Mixed precision training (FP16, BF16)
- ๐ ๏ธ Checkpointing, fault tolerance, training efficiency
- ๐ฆ System-level optimization (throughput, latency, memoryโcompute balance)
- ๐ Deployment & LLM serving systems
- ๐ง RL policy optimization and RL aligment
- โ and moreโฆ
- ๐ Stanford_CS336_Handwritten_Notes.pdf โ Complete handwritten notes (160+ pages)
This resource is intended for:
- Students studying Large Language Models
- AI and LLM engineers
- ML Systems engineers
- Researchers and scientists interested in ML System and AI infrastructure
- Anyone preparing to study or review Stanford CS336
Please note that these are personal study notes, not official course materials. They reflect my own understanding of the lectures and may contain omissions or mistakes.
Many thanks to Professor Percy Liang, Professor Tatsunori Hashimoto, the CS336 teaching staff, and everyone who contributed to making this outstanding course publicly available.
I am also grateful for the opportunity to contribute to the open-source CS336 course after taking it as a student.
These handwritten notes are shared for educational and non-commercial purposes. Please respect Stanford University's intellectual property and course policies. If you reuse or reference these notes, I would appreciate appropriate attribution.
โญ If you find these notes helpful, please consider giving this repository a Star. I hope they make your journey into LLM engineering a little easier.