Build a resumable LLM training pipeline
Take a language model from raw shards to a leaderboard: resumable download with MinHash dedup, HDF5 token shards, warmup cosine, clipping and AMP, accumulation, atomic checkpoints, multi-rank DDP and an eval harness.
Build it step by step
- 1Large Corpus DownloaderPhase 19: Capstone projects
- 2HDF5 Tokenized CorpusPhase 19: Capstone projects
- 3Cosine LR with Linear WarmupPhase 19: Capstone projects
- 4Gradient Clipping and Mixed PrecisionPhase 19: Capstone projects
- 5Gradient AccumulationPhase 19: Capstone projects
- 6Checkpoint Save and ResumePhase 19: Capstone projects
- 7Distributed Data Parallel and FSDP from ScratchPhase 19: Capstone projects
- 8Language Model Evaluation HarnessPhase 19: Capstone projects
What You'll Build
The production plumbing around a pretraining run, built at a scale your laptop can hold. A downloader streams zstd shards with HTTP Range resume and near-duplicate removal, a tokenizer pipeline writes chunked HDF5 shards, and a single training script composes warmup plus cosine, gradient clipping with mixed precision and NaN skip, gradient accumulation, atomic checkpoint and resume, and gloo-based multi-rank data parallel. A JSONL task harness scores the result on a leaderboard. Every stage writes a verifiable artifact (manifest, shards.json, CSV, checkpoint index, leaderboard.json).
Requirements
- Downloader. Stream zstd-compressed shards of a corpus you choose (a few MB to about 100 MB of public text, for example Project Gutenberg or a Wikipedia slice, split into shards yourself) through
urllibwithout buffering whole files. Keep a.partial.jsoncheckpoint withverified_bytesand a sha256 prefix, and resume withRangeafter you kill the process mid-download (serve the shards withpython -m http.serverso Range is real). Discard the partial if the prefix hash does not match. - Dedup and manifest. MinHash plus LSH (default k=128, b=32, r=4) with tombstone verdicts (
near_duplicateplus the keeper id). Inject near-duplicates of your own and report how many were caught. Writemanifest.jsonwith per-shard sha256, document and unique counts, and a manifest hash. - HDF5 shards. Buffer-then-extend writes into a resizable chunked integer dataset,
token_countand sha256 stored as attributes, ashards.jsonindex, a--validatemode that recomputes hashes, and a seeded sliding-window loader that inserts a boundary token between documents. - Schedule.
CosineWithWarmupas one function ofstep, with tests at step 0, atwarmup_steps, attotal_steps, pasttotal_steps(pinned atlr_min) and forwarmup_steps = 0. Write the schedule to CSV. - Clipping and mixed precision. The order
scale(loss).backward(),unscale_,clip_grad_norm_,step,update; a finite check on the loss before backward and on gradients after unscale; skipped steps logged with a reason; the canonical CSV columnsstep, lr, grad_l2_pre_clip, grad_l2_post_clip, loss, skipped, skip_reason, scaler_scale. Inject an Inf to prove the skip path. - Gradient accumulation. An equivalence check (accumulated vs full-batch gradients, max abs diff below 1e-4), a no-sync context on non-final micro-batches with a sync counter, and a throughput sweep written to JSON.
- Checkpoint and resume. Model, optimizer, scheduler, counters and Python/NumPy/torch RNG state saved atomically (temp file plus
os.replace), loaded withweights_only=True(torch 2.6 or newer), plus a sharded variant with a sha256 index. Kill a run mid-epoch, resume it, and show the post-resume loss trajectory matches the uninterrupted run within 1e-4. - Data parallel. A 2-rank gloo process group, a minimal DDP wrapper that broadcasts at construction and averages gradients after backward, an equivalence check against single-process gradients (below 1e-3), and the FSDP all-gather round trip reconstructing every parameter exactly.
- Eval harness. JSONL tasks with the five metrics (exactmatch, rougel, codeexec in a stripped-builtins namespace, multiplechoice, substring_contains), a swappable adapter, batched runner and
leaderboard.jsonwith a schema string. Add at least one task file you wrote and score both the toy adapter and an adapter wrapping your trained model. - Integration. One
train.pythat readsshards.jsonand trains a small GPT-style model with requirements 4 to 7 active (and 8 behind a--world-sizeflag), followed by the eval run.
Constraints
- Everything runs on CPU. Use
glooandtorch.multiprocessingfor ranks; 2 ranks on any modern laptop. Keep the model tiny (for example 2 to 4 layers, d_model 64 to 256) so a run finishes in minutes. - CPU autocast runs in bf16 and the GradScaler is a no-op there, as the lessons explain; that is why the skip path is proven with an injected Inf. Real fp16 loss-scale dynamics need a CUDA GPU and are optional; switching
device_typeand the backend toncclis the only change. - Libraries: torch, numpy, h5py, zstandard. Keep the corpus under about 1 GB on disk. Do not expect your tiny model to score well on the leaderboard; correct plumbing and honest numbers are what count.
Stretch Goals
- Partition the LSH index on disk (sqlite or shelve) and compare throughput with the in-memory index.
- Add a rolling skip-rate alert that fails the run above a threshold.
- Add a leaderboard diff command and pin task-file sha256 values inside
leaderboard.json.
How to Submit
Public repo with data/download.py, data/tokenize_hdf5.py, train/ (schedule, amp, accumulation, checkpoint, ddp), train.py, eval/, tests/ and results/ (manifest.json, shards.json, training CSV, resume comparison JSON, leaderboard.json). Do not commit the corpus; give the download or build command. The README must give the full run order, what corpus you used and how many near-duplicates were removed, your schedule and clip settings with reasons, how you simulated the interruptions, and what you would change for a real multi-GPU run.
How It's Reviewed
Professor Katalock reads your repository and the evidence you paste, and scores each criterion out of 100. You pass with a weighted total of 70 or more and no criterion below 40. A copied or padded submission is flagged and fails.
Submit
Push your work to a public GitHub repository with a README that explains how to run it, then paste the evidence below. Up to 3 reviews a day, free.
- Terminal log of a download that was killed and resumed, plus the manifest summary
- First 15 rows of the training CSV, including at least one SKIP row
- Accumulation equivalence and resume comparison output (max diffs)
- Output of the 2-rank DDP run
- Contents of results/leaderboard.json
- Output of `python -m pytest -q`
- A short note on which stage failed first and how you found the cause
Reviews are done by AI against the rubric above. They check the evidence in your repository; they are not a substitute for a human code review, and a review can be wrong. If you think it is, improve the README so the evidence is unmistakable and resubmit.