fba lab · before you start

The simplest code that completes a training run

This section presents the simplest code that can complete a training run. This is the perfect way to start learning — building from simpler examples instead of looking at complex engineering code directly. The best part is that once you go through this basic script, a lot of the concepts and learning are very transferable. Attention, QK-norm, residual connections, learning rate — many concepts transfer to scaled experiments.

Scaling & its implication

AI training, at its core, is a game of scaling large systems. This field can overwhelm a lot of people, and the fact that most engineers and teams don't have access to GPUs can be a big barrier to learning. There is a lot of content and code provided by teams who have built large models, and we can learn large-systems engineering using them. Instead of getting overwhelmed, we will anchor our learning with the speedrun and use simulation before we can fire GPUs. These will be actual runs, simulated for learning, with a lot of visualization.

Three acts, not one competition

Instead of focusing on the nanoGPT speedrun competition — which is a popular competition — we will divide our journey into 3 acts.

Act 1 will be a simple code/script. We can start with something simple and build onto it over 6 iterations, understanding the impact of each change. This creates an incubator for you to get familiar with a lot of concepts, terms, and the intuition behind them. As an example, you will get introduced to gradient accumulation and learning rate, and how and when model updates are done. It also creates a perfect entry point to learn deeper concepts — a nice, organized path to learning. You can refer to this path by looking at the roadmap, as well as the main speedrun, which is neatly divided into beats.

Act 2 is where you look at the profiler and low-level optimization. Profiler traces are the most fun to look at and give insights into actual performance under the hood.

Act 3 is the actual speedrun, or part of it. There are now 80+ iterations of this code, with a lot of participation from AI engineers across the world. We will look at a few of the iterations.

The skill you're building: LLM Training & Systems Engineering

Earned across three acts — not by memorizing facts, but by reading code, tracing losses, and making one decision at a time. By the end it's a resume line you can defend, because you'll have coded it.

1
Read the diff

Every architecture change is a single diff. Understand what changed before asking why it worked.

2
Trust the loss curve

Intuition follows from watching the curve move. Theory explains after the fact.

3
One decision at a time

The speedrun works because each step changes exactly one thing. Isolate your bets.

↗ GitHub · run it yourself
The real code behind these labs

Distributed training (DDP · torchrun · Modal) and the full FBA Lab Speedrun — profiler traces, W&B metrics, and every step you walk here. Clone it and run it.

Speed Run Results · Today on 8× H100

We trained GPT-2 from scratch in 23 minutes

Today we ran the nanoGPT speedrun experiment on 8× NVIDIA H100 GPUs. Below is what we set out to do, how the experiment is scored, and the baseline result every future beat will try to beat. This run is Beat 01 — the baseline — and it's the benchmark you'll try to improve on across the next five iterations of Act 1.

◎ Aim of this experiment

Find the best GPT-2 model — the architecture and training recipe that reaches a good model the fastest on a given dataset.

Concretely: we train a GPT-2 small (124M parameter) model from scratch until it reaches a validation loss below 3.28, and we record how long that took. Then, in each following iteration, we try to improve that time by making architectural or optimization changes to the model — same target, faster every step.

1Train from scratch. Start from randomly initialized weights — the model knows nothing.
2Race to the target. Keep training until validation loss drops below 3.28, then stop the clock.
3Iterate to go faster. Change the recipe, re-run, and beat the previous time — this is the “speedrun”.

The baseline result

23 min
Baseline training time
8× H100 · val loss 3.28 reached
6.44B
Tokens consumed
from FineWeb 10B pre-tokenized dataset
124M
Parameters
GPT-2 small · depth 12
▤ Dataset

huggingface.co/datasets/kjj0/fineweb10B-gpt2 — contains 10 billion tokens from FineWeb converted into a pre-tokenized binary format. Our training run consumed 6.44 billion tokens and took 23 minutes to complete. This is the baseline we will try to improve in the next beat.

To go deeper, open the first lab: Baseline run, decoded →

What is the Speedrun?

Built the way top labs actually train models

The FBA Lab speedrun shows how a training run gets faster — one real decision at a time. Each step appears on the loss curve so you can see why teams iterate on code before they chase bigger models or more GPUs.

Why run this lab? You read actual training scripts, walk through what changed between steps, and build the same intuition engineers use when shaving hours off a run — in a guided, visual format instead of hunting through repos and papers alone.

Start: honest baseline Target: val loss 3.28 6 teaching decisions Same goal · faster every step
loss_curve.viz — race to 3.28 simulation
target 3.28training time / compute →validation loss →
Decision 1 of 6
STARTING LINE
Baseline GPT-2
WHAT IT IS
WHY IT WORKS
baseline
time to reach validation loss 3.28
faster ◀▶ slower
baseline (slow) best (fast) target 3.28● = reaches target

Loss values and speed-ups are illustrative — simplified to teach the shape of the idea, not exact benchmark numbers. Click a step below the chart to jump into that lab in the full speedrun journey.

Cloud GPU Cluster
GPU type
8× NVIDIA H100
Dataset
FineWeb (10B tokens)
Parallelism
DDP · 8 processes · NCCL
H100
H100
H100
H100
H100
H100
H100
H100
Baseline architecture
Layers × heads × dim
12 × 12 × 768
Optimizer
AdamW
Attention
Standard causal attention
Compilation
torch.compile
ACT 1 · THE BASELINE

Same run, two machines

This is the most important table in Act 1 — it's your baseline run and time, and the number every later iteration is measured against. The exact same baseline GPT-2 training run — target val loss 3.28, 262,144 tokens/step — on a cloud H100 node vs. a two-GPU desktop. Tyler's original speedrun ran on smaller hardware, 2× RTX 4090; we run the same recipe on 8× H100.

Hardwaregrad accumWall-clockStepsTokenstok/s
8× NVIDIA H1001
23m 20s
24,576≈6.44B≈4.6MStudy it →
2× RTX 40904
8.13 hours
24,5766.44B221k

≈21× faster wall-clock on the 8× H100 node — same recipe, same tokens.

† derived: tokens = steps × 262,144; H100 tok/s = tokens ÷ 1,400 s.

The 2× RTX 4090 speedrun — 6 iterations

#IterationTimeStepsTokenstok/s
1Initial baseline
8.13 h
24,5766.44B221kStudy it →
2Architectural changes
7.51 h
9,6645.07B188kStudy it →
3Muon optimizer
4.53 h
5,8003.04B187kStudy it →
4Dataloading tweaks
4.26 h
6,3123.31B216kStudy it →
5Logit soft-capping @ 30
4.01 h
6,1203.15B218kStudy it →
6Longer sequence length
2.55 h
3,5841.88B205kStudy it →
  • Times & tokens are Tyler's reported records at ~3.28 val loss.
  • Steps are the num_iterations budgets in this repo's step folders (01…06); runs can stop earlier once val loss ≤ 3.28.
  • Baseline uses grad_accum_steps=4 on 2 GPUs to keep the global batch at 262,144 tokens/step.

Speedrun on 2× RTX 4090 by Tyler Romero · worklog

ACT 3 · THE WORLD-RECORD LADDER

From 45 minutes to 1.65 minutes

This is Act 3 — the official speedrun competition code, run for real. Its baseline took 45 minutes; by record #63 it was down to 1.650 minutes. At that point, provisioning the GPU takes longer than the run itself. The record-breaking modded-nanogpt PRs you study here — each a real speed record on 8× H100, training to the same 3.28 val loss.

#What changedRecord timeFBA Lab lessonPR
#1llm.c GPT-2 baseline — the start line45 minllm.c GPT-2 baselinellm.c
#29Flash Attention 3, 2048 max_doc_len, updated window schedule2.731 minThe attention bottleneck lesson#118Study it →
#38Polar Express — a replacement for Newton-Schulz2.476 minOptimizer internals beyond AdamW#134Study it →
#46Batch size schedule2.203 minToken efficiency vs GPU efficiency#163Study it →
#53Multi-token prediction, untie embed/lm_head at 2/3 training1.988 minMore learning signal per forward pass#178Study it →
#54Asymmetric logit rescale1.940 minOutput head stability and loss shaping#181Study it →
#62Bigram hash embedding1.655 minA clever n-gram prior inside a transformer#201Study it →
#63our runUntie value embeds1.650 minUntie Value Embeds — the run we did#209
#84FP8 — hardware-aware precision (a later record)Hardware-aware precision#306Study it →

Source: modded-nanogpt: Speedrunning the NanoGPT baselineKeller Jordan, Jeremy Bernstein, Brendan Rappazzo, et al. (2024) · KellerJordan/modded-nanogpt

What we can learn

Having understood the practical limitations of this setup, we can now be clear about what we can learn.

  • The biggest win is LLM modelling. Understanding the major moving parts of a model, and how architecture and changes affect a training run, is the biggest win.
  • Another win is DDP and PyTorch. If you are a coder or interested in math, learners from both backgrounds will get actionable code, blogs, and visualization to ground their learning. So if you are looking to break into AI, this is the perfect start.
  • Some topics in AI training are very transferable and even make you more skilled in other areas. For example, inference, sampling, and MTP can be understood even better if you have done iterations of LLM architectural changes. Tokenization can be studied in depth — the same goes for position embeddings, context length, and attention. Even reasoning and AI agentic behaviour can be understood if you understand AI training.
  • You also build a habit of benchmarking — set a target, measure a run honestly, and compare against a baseline before drawing conclusions. That “define the metric, measure, compare” discipline is a skill that carries well outside AI training, into any performance or systems work.
  • Further in, you get into low-level optimization and kernel development — profiling where the time actually goes, writing and tuning custom kernels, and seeing how code maps onto the hardware. These systems skills transfer to any performance-critical engineering, not just model training.
What we can't learn from the speedrun

Even with imagination, content, and other superpowers, some things are out of reach here.

  • MoE (mixture of experts), CoT reasoning training, and agentic tool use. Modern frontier models use different combinations of these — and this speedrun does not cover them.
  • This setup only deals with DDP, or 1D. Most modern pipelines work with 4D and more parallelism.
  • The biggest problem with this setup is that we don't get a usable checkpoint. We can only look at loss and graphs. So if inference is your main goal, you might miss out on some of the things.
  • Data pipeline engineering is also oversimplified — actual setups have complex data pipelines.