Skip to content

One image, both toolchains: the trainer is 0.9890 of torch.compile() and the interval excludes parity - #120

Merged
feitreim merged 2 commits into
mainfrom
perf/versus-one-container
Aug 6, 2026
Merged

feitreim merged 2 commits into
mainfrom
perf/versus-one-container

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

torch_baseline was the only Modal function on torch_image and every trainer
entrypoint runs on the kernel image, so the trainer and the PyTorch baseline
could never share a GPU. At B=16 that did not matter -- the gap was 12.4%. At
B=32 it was the whole question: 92,718 against 93,634 is 0.99%, inside the 1.4%
spread the same trainer binary shows between two containers.

The harness

ab_image is the kernel toolchain plus torch. image is untouched -- kernel
runs pull no torch -- because the toolchain layers were split out and both
images build from them, so the torch image is image's cache plus one pip
install (82s the first time, cached after).

torch_versus_train / modal run modal_app.py::versus:

  • trainer from --ref, baseline script from --torch-ref (default
    pytorch-throughput-baseline), both checked out in the container as
    worktrees of one clone, with A pushed branch names itself, and the compare's clone knows it as origin's #116's origin/-fallback ref resolution;
    the baseline branch stays the source of truth for what PyTorch is asked to do
  • one --batch imposed on both arms, on train.rs by rewriting its compile-time
    B, so a matched batch is a property of the run and not of the two refs
  • alternating rounds after a discarded warmup each, like compare_train
  • torch's compile lands in the script's own warmup steps, never a timed window
    (63s cold in the container, 15s once inductor's cache is warm)
  • an arm whose inductor recorded CUDA graphs is rejected: the trainer has
    none and cuda-oxide cannot give it any
  • the summary reports a 95% interval on the difference, not two point estimates
modal run modal_app.py::versus --ref main --batch 32 --steps 30 --rounds 6

The result

main (c5a3b1a) at B=32, 30 steps (29 measured), against torch.compile()
default mode, bf16 masters, same shard, cuda_graphs=False verified every
round, peak 150.1 GiB every round.

Container round trainer tokens/s MFU torch.compile() tokens/s MFU
1 0 92,630.6 41.13% 92,436.8 41.05%
1 1 92,397.6 41.03% 92,786.0 41.20%
1 2 92,522.3 41.08% 92,439.8 41.05%
2 0 89,953.0 39.94% 91,483.7 40.62%
2 1 89,945.2 39.94% 91,610.6 40.68%
2 2 90,089.5 40.00% 91,087.8 40.45%
2 3 90,015.0 39.97% 92,187.8 40.94%
2 4 90,019.1 39.97% 91,979.7 40.84%
2 5 90,268.0 40.08% 91,470.8 40.62%
3 0 90,427.6 40.15% 91,986.9 40.85%
3 1 90,868.8 40.35% 91,594.3 40.67%
3 2 90,643.5 40.25% 91,330.8 40.56%
3 3 90,811.1 40.32% 91,627.9 40.69%
3 4 90,298.3 40.10% 91,471.5 40.62%
3 5 91,248.7 40.52% 91,738.3 40.74%
Container rounds trainer mean (sd) torch mean (sd) difference (95%) ratio
1 3 92,516.8 (0.13%) 92,554.2 (0.22%) -0.04% ± 0.62% 0.9996
2 6 90,048.3 (0.13%) 91,636.7 (0.43%) -1.73% ± 0.47% 0.9827
3 6 90,716.3 (0.38%) 91,624.9 (0.25%) -0.99% ± 0.47% 0.9901

Verdict. Container 1 came back unresolved (-0.04% ± 0.62%), so the rounds
were doubled; containers 2 and 3 each resolve, both against the trainer. Over
all fifteen pairs the trainer is at 0.9890 of torch.compile(), ±0.0042 at
95%
-- 1.1% behind, interval excluding parity. It is ahead in no container.

Within-arm spread landed at 0.13-0.43% per container (target was ~0.3%), while
the trainer's mean moves 2.72% between containers and torch's 1.01%. That is
the whole argument for the pairing: the effect is smaller than the noise the
pairing removes. The old comparison -- 92,718 from one container, 93,634 from
another -- was two draws from a distribution wider than the thing being
measured. Neither number was wrong; the subtraction was.

Both arms also read lower here than the numbers they replace, and the window is
why: 93,634 came off an 11-step measurement, these off 29. A 4-step window in
this same harness reads 96-97k for both arms.

max-autotune gate

Not beaten. mode="max-autotune" stays locked. The gate was 93,634; the
better-measured value for torch.compile() default at B=32 is 91,816
tokens/s
(grand mean, 15 rounds, three containers), and main reaches 90,809
against it. The trainer has to be ahead to unlock the next tier and it is
behind by 1.1% with the interval excluding zero -- a stronger statement than
#117's coin flip, and in the same direction.

Diff is additive: image keeps its exact build, split only so ab_image can
reuse the toolchain layers; the only new runtime objects are ab_image,
torch_versus_train, and the versus entrypoint.

… container gets it

`torch_baseline` was the only function on `torch_image` and every trainer
entrypoint runs on the kernel image, so the trainer and the PyTorch baseline
could never share a GPU. At B=16 that did not matter: the gap was 12.4%. At
B=32 it is the whole question -- 92,718 against 93,634 is 0.99%, inside the
1.4% spread the same trainer binary shows between two containers.

`ab_image` is the kernel toolchain plus torch. The three expensive layers are
the toolchain's own, so it is `image`'s cache plus a pip install, and `image`
itself is untouched -- kernel runs still pull no torch. `torch_versus_train`
takes the trainer from a pushed ref and the baseline script from another
(default the baseline branch, which stays the source of truth for what PyTorch
is asked to do), imposes one batch on both by rewriting train.rs's compile-time
`B`, and alternates them round by round after a discarded warmup each. Torch's
compile lands in the script's warmup steps; an arm whose inductor recorded CUDA
graphs is rejected, because the trainer has none and cuda-oxide cannot give it
any.

The summary reports a 95% interval on the difference rather than two point
estimates, since the answer at this margin is decided by the interval.
…e interval excludes parity

Fifteen alternating pairs at B=32 and 30 steps, three containers. The trainer
is 1.1% behind torch.compile()'s default mode with a 95% interval of 0.42
points, and it is not ahead in any container: 0.9996, 0.9827, 0.9901.

The 0.99% that #117's table left as a coin flip was never going to be settled
by more of the same measurement. The columns say why: each arm's spread within
a container is 0.13-0.43%, while the trainer's mean moves 2.72% between
containers and torch's 1.01%. The old pair -- 92,718 from one container against
93,634 from another -- was two draws from a distribution wider than the effect.
Neither number was wrong; the subtraction was.

Both arms also read lower here than the numbers they replace, and the window is
why: 93,634 came off an 11-step measurement, this off 29. A four-step window in
the same harness reads 96-97k for both arms. Short windows flatter whatever
they measure.

The escalation rule is unchanged and now has a properly measured gate:
`mode="max-autotune"` stays locked until a trainer beats torch.compile(), and
what it has to beat is 91,816 tokens/s under this harness.
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