← TinyGPT · docs · devlog · roadmap · speedup
source: docs/prds/B12-loss-spike-recovery.md · view on GitHub ↗

PRD — Auto-rollback on training spikes (the controller half of B12)

Goal

Add a grad-norm tracker that triggers an automatic --resume <step-K> --lr-drop F if step N’s grad-norm exceeds a rolling-median multiplier (default 3×) — the “loss spiked, wait, where do we go from here?” question turned into an automatic action. Saves hours of wasted compute on long pretrain runs.

The on-disk state is already there (adam-state-persistence.md covered the state-persistence half). C9 (determinism harness) is the debug-tool half. B12 is the automatic policy that uses both.

Why now

Scope — in

Scope — out

Files to touch

FileChange
Sources/TinyGPT/SpikeMonitor.swiftnew — controller
Sources/TinyGPT/Train.swiftwire spike monitor into the step loop; flag parsing
Sources/TinyGPT/HistoryRow.swift(or wherever the history JSONL schema lives) — add rollbacks field
Tests/TinyGPTTests/SpikeRecoveryTests.swiftnew — inject a synthetic spike, assert rollback fires + LR drops
docs/PLAN.mdB12 ⬜ → ✅ on ship

Acceptance criteria

Reference patterns

Open questions