Part 10›
✎

13. Building Your Own: A Roadmap Through the Assignments#

Level: Practitioner · Reading time: 14 min · Exercise: 10 weeks

In one sentence: After this chapter you have an order, a compute budget and a list of known traps for working through CS336's five assignments on your own.

Why this matters#

The course's method is understanding by building. Watching the lectures gives the map. The assignments are the territory.

The territory is steep. Lecture 1's outline quotes a Spring 2024 course evaluation: the first assignment alone was about the work of all five assignments plus the final project of the NLP course. Enrolled students get a cluster, a teaching staff and deadlines. You have none of those, so you need three things this chapter supplies: an order, a realistic idea of the compute, and the traps the handouts themselves warn about.

The core idea#

Five assignments follow the pipeline of this part, one per unit:

# Assignment What you build Chapters
1 Basics Tokenizer, Transformer, loss, optimizer, training loop 01 to 03
2 Systems Profiling, a FlashAttention kernel, distributed training 02, 05, 06
3 Scaling Fits that predict loss and pick model size 07
4 Data Text extraction, filtering, deduplication 10
5 Alignment Reinforcement learning with verifiable rewards 11

They share one shape. The handouts give no solution code. They give a test suite, and an adapters.py file of empty functions. You write the real code in your own module, then make each adapter call it. Until you do, every test fails with NotImplementedError. Each repository is public under the stanford-cs336 organization on GitHub, and each README shows the setup with uv, a Python environment manager: clone, run uv run pytest, then fill the adapters.

The analogy is a test-driven project at work: the tests are written, the implementation is yours. The analogy breaks on size. Nothing here is a function to fill in. Assignment 1 is a small deep-learning framework.

Two course policies matter for self-study:

The five assignments#

Time and cost figures below are estimates for a self-learner, not course statements. Prices come from the course page.

Assignment 1: Basics#

Assignment 2: Systems#

Assignment 3: Scaling laws#

Assignment 4: Data#

Assignment 5: Alignment#

Order and pace#

Do them in order. Each one reuses the last: the model from 1 is profiled in 2, the training script in 4 descends from 1, and 5 needs a trained model to improve.

Figure 1. The five assignments in order, with the three things later assignments reuse from the first.

flowchart TD
    A1["1 Basics: tokenizer, Transformer, training loop"] --> A2["2 Systems: profiling, kernels, distributed training"]
    A2 --> A3["3 Scaling: fits that pick the model size"]
    A3 --> A4["4 Data: extraction, filtering, deduplication"]
    A4 --> A5["5 Alignment: RL with verifiable rewards"]
    A1 -->|"model to profile"| A2
    A1 -->|"training script"| A4
    A1 -->|"trained model"| A5

Assignment 1 feeds all the others, which is why doing it first matters more than the order of the rest.

For enrolled students, the course page's Spring 2026 deadlines gave about two and a half weeks to Assignment 1, two weeks to Assignment 2, one week to Assignment 3, two to Assignment 4 and two to Assignment 5, inside a ten-week quarter. For self-study, plan on roughly twice that, about twenty weeks at ten hours a week, and treat Assignment 1 as the half-way mark in effort.

Three shortcuts are reasonable:

Compute for self-study#

The course page has a section on self-study compute. It lists cloud providers with "public pricing for a single B200 GPU on March 28, 2026" and thanks Modal, the course's sponsor:

Provider Price per B200 hour Note on the page
RunPod $4.99
Nebius $5.50 $3.05 for preemptible instances
Modal $6.25 $30 of free compute per month; charged for actual use
Lambda Labs $6.69
Together $7.49 Minimum of 8 GPUs

The page was fetched on 2026-11-24. Prices change, so check before you budget.

Worked example#

A cost calculator with illustrative hours:

PRICES = {"RunPod": 4.99, "Nebius": 5.50, "Modal": 6.25, "Lambda Labs": 6.69}  # per B200 hour

# Illustrative GPU hours for a self-learner who follows the low-resource tips.
assignments = {"A1 basics": 4, "A2 systems": 12, "A3 scaling": 8, "A4 data": 6, "A5 alignment": 10}

total = sum(assignments.values())
for provider, price in sorted(PRICES.items(), key=lambda item: item[1]):
    print(provider, round(total * price, 2))
# RunPod 199.6, Nebius 220.0, Modal 250.0, Lambda Labs 267.6

What to observe:

What the practitioners say#

Lecture 1 describes how the course works. There is no scaffolding code, but unit tests keep you from working blind for weeks on an unverified guess. Much of each assignment can be done on a laptop, and the cluster is for benchmarking speed and accuracy (22:00).

The last lecture is a guest talk by Dan Fu. Her one hoped-for takeaway: if you understand inference, the inference engines and the GPU kernels underneath them, you can innovate across the whole stack, algorithms included (Lecture 18, 6:00). She contrasts synthetic benchmarks with real request traces, then follows a request through a serving system. Prefill resembles training, heavy in FLOPs. Decode is heavy in memory bandwidth, because every step loads all the weights, so engines now run the two on separate workers and tune each (Lecture 18, 20:00). When the KV cache outgrows GPU memory it spills to CPU memory and then to disk, one reason CPU and SSD speed matter (Lecture 18, 26:00). A rack of 72 fast-linked GPUs raises the questions of how to split a trillion-parameter model across it and what to do when one GPU fails (Lecture 18, 30:00). The outline also lists a set of production bugs and a lesson on reading profiler timelines, and ends with early scaling results for recurrent-style models. The useful takeaway for a self-learner is the gap it exposes: an assignment ends when the tests pass. A serving system begins there.

Pitfalls#

  1. Letting an agent write the code. The handouts prohibit it, and the learning is the point. Fix: use AI to explain, never to implement.
  2. Putting logic in adapters.py or editing tests. Fix: keep adapters as one-line calls into your own module.
  3. Reaching for the GPU to debug. Fix: get shapes and round trips right on the CPU first.
  4. Optimizing before profiling in Assignment 2. Fix: measure, then change one thing, then measure again.
  5. Spreading the scaling budget thin. Fix: choose a few budgets and several sizes at each, and write down the prediction before you look.
  6. Not looking at the data in Assignment 4. Fix: read rejected and kept samples before trusting a filter.
  7. Stale weights during RL. In Assignment 5 the inference server and the trainer hold separate copies. Fix: confirm that the server uses the updated weights before each round.

Try it#

Start Assignment 1 and stop at the tokenizer.

Deliverable: a cloned repository with the tokenizer tests passing.

You are done when:

Stretch: train the small Transformer on TinyStories for an hour and read ten samples of its generated text.

Key takeaways#

Self-check#

  1. How do the assignments tell you your code is right? - A. By comparing against a hidden reference model - B. Through a provided test suite - C. By a leaderboard alone - D. By a grader reading the source
  2. What may AI tools be used for under the handouts' policy? - A. Writing any part of the implementation - B. Completing code in the editor - C. Answering conceptual questions and documenting library interfaces - D. Generating the write-up
  3. Which assignment do enrolled students complete without training models themselves? - A. Assignment 1 - B. Assignment 2 - C. Assignment 3 - D. Assignment 4
  4. Why does the course page advise debugging on the CPU? - A. GPUs do not support the tokenizer - B. Correctness checks need no GPU, and GPU time costs money - C. The tests cannot run on GPUs - D. CPU results are more accurate
  5. What does Assignment 2 say to do before optimizing? - A. Profile to see where time and memory go - B. Rewrite everything in Triton - C. Double the batch size - D. Lower the precision
Show answers 1. B. Each test calls a function in `adapters.py`, which must call your implementation. 2. C. Implementation, including autocomplete, is off limits. 3. C. Assignment 3 queries a training API that returns the validation loss. 4. B. The page's advice is to get correctness right before paying for GPU runs. 5. A. Otherwise you optimize parts that do not matter.

Sources#

Next#

→ Start with The Language Modeling Pipeline and Tokenization and keep this roadmap as your checklist. For the wider picture of where pretraining sits, see how large language models are trained.