Skip to content

The init checkpoint is bigger than the work it replaces, and step 1 is the last step the trainer agrees with itself - #131

Merged
feitreim merged 1 commit into
mainfrom
gpu-spend-economy
Aug 7, 2026
Merged

feitreim merged 1 commit into
mainfrom
gpu-spend-economy

Conversation

@feitreim

@feitreim feitreim commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Parameter initialization is 119.5s of the 123.9s a three-step trainer process takes at B=32, and a compare_train A/B pays it six times to reach the same bytes six times — ~76% of 848-1509s of B200 spent re-deriving one function of one seed. The premise of the task holds. Caching a step-0 checkpoint is the obvious economy, and it does not work. It was built, measured on both storage tiers, and refused on both.

The measurement

modal run --detach modal_app.py::init_cache is kept in the tree so this can be redone:

storage save load a run that resumes, vs fresh init's 123.9s
wiki volume 174.5s 237.8s -30.3s per run
container disk 35.4s 139.0s -14.0s per run

Resuming is slower than initializing on both, and the second row is why this is not the filesystem's fault: the container's own disk takes the file at 1.18 GiB/s and gives it back at 300.8 MiB/s. The read is not bound by fetching the bytes, it is bound by what checkpoint::load does with them.

The artifact is bigger than the work it replaces. Of its 40.85 GiB, 80% is AdamW moments that are zero at step 0 — and a fresh init never materializes those at all, because GpuTensor::zeros fills them on the device, over no bus. So the cache trades ~119s of host RNG and an 8.8 GiB upload for a 40.85 GiB read, 4.39 billion host bf16 widenings, and a 35 GiB upload of zeros.

This is ferro-kittens#226's result one layer down, and it lands the same way: the negative result is written into modal_app.py and README.md so it is not rediscovered. What would overturn it is the format, not the storage — a step-0 artifact without the zero moments is ~8.6 GiB, which is a checkpoint v6. The probe is what makes that a one-container question the day someone writes one.

The correctness half came back with a finding of its own

Two fresh runs of one binary on one shard, beside the resumed arm:

step fresh 1 fresh 2 resumed from step 0
1 11.124607 11.124607 11.124607
2 9.793599 9.793572 9.793576
3 10.715647 10.715630 10.715669

Step 1's loss is a pure function of the parameters and agrees to every printed digit — that is what says the resumed model is the initialized model. From step 2 the two fresh runs disagree with each other by as much as either disagrees with the resumed arm (at step 2, fresh 1 is closer to the resumed arm than to fresh 2). The embedding gradient accumulates atomically and atomic order is not fixed across launches.

So step 1 is the last step at which a loss compares across processes at all, which is worth knowing independently of this PR — it bounds what any A/B can claim about losses. The bitwise form of the resume claim therefore goes where launch order is not a variable: moe_checkpoint_gate now takes one training step from a resumed step-0 checkpoint and from fresh initialization and requires the two saves to be byte-identical. Without this, the step-0 path was never exercised — the existing arm resumes at step 1, with populated moments and a mid-shard next_batch.

What stays, and why

  • bin/init_ckpt, behind an init-ckpt feature so it is not a fourth full device codegen every cargo oxide build model pays (confirmed: the gate run built four bins, not five). Its shape constants are imposed from bin/train.rs at build time by _impose_train_shape, with the checkpoint header as the guard behind that — drift costs a failed run, never a wrong number.
  • TRAIN_CHECKPOINT_INIT: a starting state read and never written back. TRAIN_CHECKPOINT is one path serving as both resume source and save destination, which is right for a run continuing its own trajectory and wrong for one resuming a shared file — without the split, a resuming round saves its final state over the file every later round reads, at tens of gigabytes a round. Purely additive; no output line changes shape.

Also here

  • Build once, run many, and say so. Both A/B entry points already built each arm once and launched target/release/train directly for every round — cargo was never in the round loop. What that assumption needed was a guard: each arm prints its resolved commit, and _built_here refuses a binary older than any .rs/.toml/.lock beneath it. It earned itself immediately: the verification run below resolved --ref main to a74128a, not the 353ac1a this branch started from.
  • Timeouts at ~3x a measured baseline, with the baseline in a comment at each @app.function: compare_train 4h → 80 min against a 1509s worst case, batch_sweep → 2h, rebuild_stability and torch_versus_train → 90 min, dump_ptx/jit_probe → 20 min, tools_check → 10. Three are deliberately left open-ended (run_kernel and prepare_data take unbounded --steps/--limit-files, profile replays every kernel per metric pass) and now say so rather than merely being large.
  • _run(stamp=True) puts elapsed time on every echoed line, which is how the init window was attributed at all. The returned text is unstamped, so both throughput= parsers still see exactly what the child printed.

Verification

  • modal run modal_app.py::main --kernel model — the full correctness gate, green, including ✓ checkpoint v5 (bf16 masters) resumes bit-identically from step 0 and mid-run, ….
  • modal run --detach modal_app.py::train_ab --ref main --baseline-ref main — one full A/B through the changed harness: candidate/baseline=0.9961, spreads 0.18% / 0.36%, both arms provenance-checked, 1509s.
  • modal run --detach modal_app.py::init_cache — the table above, twice (volume arm and container-disk arm).
  • cargo check --features init-ckpt --bins clean on all five binaries, cargo fmt --check clean.

What this does not do

It does not reduce the 76%. The only other lever is fewer trainer processes — running an arm's rounds inside one process — and that is the one thing the alternation control forbids, since alternating arms round by round is what puts a drift in clocks on both of them. Making initialization itself faster is a real follow-up but not a free one: CpuTensor::uniform is a sequential SplitMix64, so parallelizing it changes the parameters it produces and therefore every number ever measured against them.

…s the last step the trainer agrees with itself

Parameter initialization is 119.5s of the 123.9s a three-step trainer process
takes at B=32, and a `compare_train` A/B pays it six times to reach the same
bytes six times -- ~76% of 848-1413s of B200 spent re-deriving one function of
one seed. Caching a step-0 checkpoint is the obvious economy. It was built,
measured on both storage tiers, and refused on both.

`init_cache_probe` is the measurement, kept so it can be redone:

              save        load     a resuming run vs fresh init's 123.9s
  volume     174.5s      237.8s      -30.3s
  disk        35.4s      139.0s      -14.0s

The second row is why this is not the filesystem's fault: the container's own
disk takes the file at 1.18 GiB/s and gives it back at 300.8 MiB/s, so the read
is bound by what `checkpoint::load` does with the bytes. Of the 40.85 GiB, 80%
is AdamW moments that are zero at step 0 -- which a fresh init never
materializes at all, because `GpuTensor::zeros` fills them on the device over
no bus. The cache trades ~119s of host RNG and an 8.8 GiB upload for a 40.85
GiB read, 4.39 billion host bf16 widenings, and a 35 GiB upload of zeros. What
would overturn it is the format, not the storage: a step-0 artifact without the
zero moments is ~8.6 GiB, which is a checkpoint v6.

The apparatus stays, because the refusal is only re-checkable with it:
`bin/init_ckpt` (behind an `init-ckpt` feature, so it is not a fourth device
codegen every `cargo oxide build model` pays; its shape constants are imposed
from `bin/train.rs` at build time, with the checkpoint header as the guard
behind that) and `TRAIN_CHECKPOINT_INIT`, a starting state read and never
written back -- which `TRAIN_CHECKPOINT`, one path serving as both resume
source and save destination, cannot express. Without it a resuming round saves
its final state over the file every later round reads, at tens of gigabytes a
round.

The correctness half came back with a finding of its own. Two fresh runs of one
binary on one shard:

  step   fresh 1     fresh 2     resumed from step 0
  1      11.124607   11.124607   11.124607
  2       9.793599    9.793572    9.793576
  3      10.715647   10.715630   10.715669

Step 1's loss is a pure function of the parameters and agrees to every printed
digit, which is what says the resumed model is the initialized model. From step
2 the two fresh runs disagree with each other by as much as either disagrees
with the resumed arm: the embedding gradient accumulates atomically and atomic
order is not fixed across launches. So step 1 is the last step at which a loss
compares across processes at all, and the bitwise form of the claim goes where
launch order is not a variable -- `moe_checkpoint_gate` now takes one training
step from a resumed step-0 checkpoint and from fresh initialization and
requires the two saves to be byte-identical. Green.

Also here, from the same audit:

- **Build once, run many, and say so.** Both A/B entry points already built
  each arm once and launched `target/release/train` for every round; what that
  needed was a guard. Each arm prints its resolved commit and `_built_here`
  refuses a binary older than any source beneath it, which is how a build that
  silently did not happen would otherwise measure the wrong tree.
- **Timeouts sized at ~3x a measured baseline**, with the baseline in a comment
  at each `@app.function`. `compare_train` 4h -> 75 min against a 1413s worst
  case, `batch_sweep` -> 2h, `rebuild_stability` and `torch_versus_train` -> 90
  min, `dump_ptx` and `jit_probe` -> 20 min, `tools_check` -> 10. Three are
  left open-ended and now say why rather than merely being large.
- `_run(stamp=True)` puts elapsed time on every echoed line, which is how a
  run's internal phases were attributed at all. The returned text is unstamped,
  so the two `throughput=` parsers see exactly what the child printed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant