CS336: Language Modeling from Scratch
TL;DR Highlight
Stanford's CS336 teaches building an LLM from scratch, from tokenizer to RL
Who Should Read
A backend developer who only uses LLM APIs and wants to understand training, data, and serving by building them
Core Mechanics
- A course on building an LLM from scratch
- It covers data collection and cleaning, Transformer construction, training, and evaluation before deployment.
- It says it takes inspiration from OS courses that build a whole OS from scratch.
- Five assignments cover the full pipeline
- A1 trains a minimal LM with your own tokenizer, model, and optimizer.
- A2 has you write FlashAttention2 in Triton and build distributed training code.
- A3 queries a training API to fit a scaling law (a formula predicting performance from model size).
- Data and post-training are included
- A4 turns raw Common Crawl dumps into pretraining data via filtering and deduplication.
- A5 uses SFT and RL to teach math reasoning, with optional safety alignment such as DPO.
- Prerequisites are steep
- You need strong Python, PyTorch, and basic systems concepts like the memory hierarchy.
- Calculus, linear algebra, probability, and ML basics are also required.
- It is a 5-unit, implementation-heavy class, so budget plenty of time.
- Self-study means renting cloud GPUs
- Single B200 prices on March 28, 2026: RunPod $4.99/hr, Nebius $5.50/hr ($3.05 preemptible), Modal $6.25/hr, Lambda $6.69/hr, Together $7.49/hr (8 GPU minimum).
- They recommend debugging on CPU first, then moving to GPU.
- AI tool use is restricted
- LLMs are allowed for low-level or conceptual questions but not for directly solving problems.
- They strongly encourage disabling AI autocomplete such as Cursor Tab or Copilot.
Community Reactions
- Experience from someone who finished the 2025 version
- It took several months of evenings and weekends to do the videos and most assignments.
- They also said the environment requirements were unclear: it expects Linux, an NVIDIA GPU, and specific CUDA versions.
- A backend engineer's run with Claude on gpt-1
- They blended gpt-1 with modded-nanogpt and reproduced most of the original results in 1 hour on an RTX 2060 SUPER.
- The code is at github.com/epoyraz/modded-gpt-1.
- Doubts about needing a B200
- One commenter said a 4090 on Vast.ai was enough in the early phases.
- Others asked whether a 5080 16GB, an AMD GPU, or an MBP M5 Max would work.
- Study group experience
- One group started with over 30 learners and ended with 8.
- Another said the 2026 version is up to date on architecture choices and has low-compute tips for Mac.
How to Apply
- Skim lecture 1 and the schedule
- Open lecture 1 (tokenization) and lecture_01.py from the YouTube playlist today.
- Note where it connects to your token costs and length limits.
- Set a pace and start a study group
- Plan one lecture per week with a few colleagues.
- Target only A1 first and debug correctness on CPU.
- Rent GPUs only when needed
- Use cloud GPUs only for training in A1, A4, A5 or benchmarking in A2.
- Compare hourly prices and Modal's $30 monthly credit to set a budget first.
- Follow the AI tool rules
- Turn off autocomplete and ask LLMs only conceptual questions.
- Do not have them generate the solution code.
Try It
# Paste into Claude or ChatGPT (simplified version of the course idea: CS336 study plan helper)
I'm a backend developer who uses LLM APIs. I want to self-study Stanford CS336 (Language Modeling from Scratch).
- My setup: {{GPU/OS, e.g. RTX 4090, Linux}}
- Time per day: {{hours}}
- What I know: {{Python, PyTorch experience, etc.}}
Make a 4-week study plan for Assignment 1 (train a minimal LM with tokenizer, Transformer, optimizer).
Rules: no solution code. Only concept explanations, questions to ask when stuck, and a weekly checklist.Terminology
Related Papers
Quadrillion-parameter transformers and how to train them
On fixed data, much bigger models with scaled weight decay and ensembling keep loss falling as compute grows.
Astra can read and write weights to improve Qwen
An LLM edited Qwen3.5-0.8B's weights directly, lifting MATH-500 from 7.9% to 48.1%.
Show HN: Qwen3-4B with the AI writing tics trained out
Distilling Qwen3-4B with LoRA cut its AI-writing slop score from 121 to 12.5 per 1000 words
Dust: Pretraining Transformers Without Backpropagation
Adding per-token noise to activations lets transformers pretrain without backpropagation, rivaling backprop.
Show HN: TurboGPT: train 22KiB transformer in 13s
A CUDA C++ project trains a tiny byte-level GPT in under a minute.
I had Gemini train its own replacement for $9
Fine-tuning GLiNER on $9 of Gemini labels reached 0.83 F1 locally.
Learning to solve hard problems in RL for LLMs by never giving up
Cutting compute on easy problems and retrying hard ones in RL raised accuracy on the hardest problems
Training a 3.8B LLM to 0.384 CORE for $998
A 3.8B LLM trained on 8 B200s in 43 hours for $998 scored 0.384 on CORE.