← TinyGPT · docs · devlog · roadmap · speedup
source: docs/prds/C9-determinism-harness.md · view on GitHub ↗

PRD — Bit-exact replay of tinygpt train step N

Goal

Add tinygpt train --replay-step N --replay-from <ckpt> that runs exactly step N of an earlier training run, deterministically. The output is a logged forward + backward trace identical to what the original step produced — same input batch, same weights at step N-1, same RNG, same intermediate tensor norms.

The single tool that turns “training spiked at step 4218” from a 4-hour investigation into a 4-minute one: load the saved state, replay 4218, inspect the activations / gradients / Adam state directly.

Why now

Scope — in

Scope — out

Files to touch

FileChange
Sources/TinyGPTModel/RNGSnapshot.swiftnew — serialize/restore MLX RNG + sampler cursor
Sources/TinyGPT/Train.swiftsnapshot RNG + cursor every save; --replay-step / --replay-from flag handlers
Sources/TinyGPT/ReplayTrace.swiftnew — emit + reload trace JSON
Tests/TinyGPTModelTests/DeterminismTests.swiftnew — run 10 steps, replay step 5, assert byte-equality of weights at step 5
docs/training_guide.md”Debugging a loss spike” runbook section

Acceptance criteria

Reference patterns

Open questions