KatalockAi AcademyBack to KatalockAi
Build track, required for the Phase 10 certificate

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.

about 32 h 8 guided steps Reviewed against a 7-point rubric
Submit your project Get coached by Professor Katalock

Build it step by step

  1. 1Large Corpus DownloaderPhase 19: Capstone projects
  2. 2HDF5 Tokenized CorpusPhase 19: Capstone projects
  3. 3Cosine LR with Linear WarmupPhase 19: Capstone projects
  4. 4Gradient Clipping and Mixed PrecisionPhase 19: Capstone projects
  5. 5Gradient AccumulationPhase 19: Capstone projects
  6. 6Checkpoint Save and ResumePhase 19: Capstone projects
  7. 7Distributed Data Parallel and FSDP from ScratchPhase 19: Capstone projects
  8. 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

  1. 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 urllib without buffering whole files. Keep a .partial.json checkpoint with verified_bytes and a sha256 prefix, and resume with Range after you kill the process mid-download (serve the shards with python -m http.server so Range is real). Discard the partial if the prefix hash does not match.
  2. Dedup and manifest. MinHash plus LSH (default k=128, b=32, r=4) with tombstone verdicts (near_duplicate plus the keeper id). Inject near-duplicates of your own and report how many were caught. Write manifest.json with per-shard sha256, document and unique counts, and a manifest hash.
  3. HDF5 shards. Buffer-then-extend writes into a resizable chunked integer dataset, token_count and sha256 stored as attributes, a shards.json index, a --validate mode that recomputes hashes, and a seeded sliding-window loader that inserts a boundary token between documents.
  4. Schedule. CosineWithWarmup as one function of step, with tests at step 0, at warmup_steps, at total_steps, past total_steps (pinned at lr_min) and for warmup_steps = 0. Write the schedule to CSV.
  5. 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 columns step, lr, grad_l2_pre_clip, grad_l2_post_clip, loss, skipped, skip_reason, scaler_scale. Inject an Inf to prove the skip path.
  6. 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.
  7. Checkpoint and resume. Model, optimizer, scheduler, counters and Python/NumPy/torch RNG state saved atomically (temp file plus os.replace), loaded with weights_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.
  8. 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.
  9. 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.json with a schema string. Add at least one task file you wrote and score both the toy adapter and an adapter wrapping your trained model.
  10. Integration. One train.py that reads shards.json and trains a small GPT-style model with requirements 4 to 7 active (and 8 behind a --world-size flag), followed by the eval run.

Constraints

  • Everything runs on CPU. Use gloo and torch.multiprocessing for 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_type and the backend to nccl is 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.

CriterionWeightHow it's checked
Data pipeline20Pasted logs show a killed download resuming from verified bytes; manifest.json and shards.json include sha256 values; dedup count on the learner's injected duplicates is reported; validate mode passes.
Training-loop safety20Schedule boundary tests pass; code shows the correct scaler/clip order; the training CSV has the canonical columns with at least one SKIP row; accumulation equivalence diff below 1e-4 is printed.
Checkpoint and resume15Atomic save via temp file and os.replace, weights_only=True load, RNG state captured; pasted resume comparison shows max diff below 1e-4.
Distributed training102-rank gloo run output shows the gradient equivalence check below 1e-3 and an exact FSDP round trip.
Eval leaderboard10leaderboard.json has per-task scores, latency, overall average and schema string for the toy adapter and the learner's model; one task file is learner-written; code_exec rejects `import os`.
Code quality and tests10Stages are separate modules composed by train.py, pytest suite passes, config values live in one config file.
README and explanation15README gives run order, corpus and dedup results, chosen hyperparameters with reasons, interruption method, CPU vs GPU differences and a reflection on failures.

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.