Skip to content

The batch that stopped paying at 16 pays to 32, because the fusions moved the wall - #117

Merged
feitreim merged 1 commit into
mainfrom
batch-size-recheck
Aug 6, 2026
Merged

feitreim merged 1 commit into
mainfrom
batch-size-recheck

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

B = 16 was chosen in #105, when a unit of batch cost 5.33 GiB and the curve
went flat immediately after it. The fusions of #108-#114 cut that to 3.39 GiB,
which moves two things at once: the B200's ceiling from 21 to 33, and where the
curve flattens. It is now 32 -> 33, not 16 -> 20.

Measured

One B200 (178.35 GiB visible), wiki-val-00000.tok, 12 steps with the first
discarded, every number from bin/train.rs itself, all in one container.
modal run modal_app.py::sweep_batch --batches 16,20,24,28,32 --steps 12.

B tokens/batch tokens/s MFU peak VRAM 65.5 + 3.39·B vs B=16
16 32 768 90 286.2 40.09% 119.80 GiB 119.74 —
20 40 960 90 488.7 40.18% 133.36 GiB 133.30 +0.22%
24 49 152 91 527.3 40.64% 146.94 GiB 146.86 +1.37%
28 57 344 92 055.7 40.88% 160.50 GiB 160.42 +1.96%
32 65 536 92 717.6 41.17% 174.05 GiB 173.98 +2.69%
33 67 584 92 680.0 41.15% 177.40 GiB 177.37 +2.65%
34 69 632 — — out of memory 180.76 —

The memory model never breaks: every point is within 0.08 GiB of
65.5 + 3.39·B, and the fit through the endpoints is 3.388 GiB per unit of B
on 65.59 GiB of weights, gradients and AdamW moments.

The ceiling is 33, and it is measured

33 fits with 0.95 GiB to spare; 34 dies in allocation with
DriverError(2, "out of memory"). So the ceiling the slope predicts is the
ceiling the card has. 33 is also not faster than 32 — −0.04%, well inside the
run-to-run spread — so the last GiB buys nothing, and 32 is the largest batch
that still leaves a margin (4.30 GiB).

Same container, both refs

modal run modal_app.py::train_ab --ref batch-size-recheck, two rounds each,
alternating, on one B200:

baseline main:              mean=88989.4 tokens/s spread=0.57% mfu=39.52% runs=[89244.5 88734.4]
candidate batch-size-recheck: mean=90717.9 tokens/s spread=0.36% mfu=40.28% runs=[90882.7 90553.0]
candidate/baseline=1.0194

+1.94% on a card that ran ~1.4% slower overall than the sweep's, which is why
the pair is quoted alongside the sweep row rather than instead of it. Both
agree on sign and both clear the bar; take +1.9% as the conservative number.

(This is the first train_ab run against a branch rather than main — it needs
the ref-resolution fix in #116.)

The win is not tile quantization

Worth saying, because in this codebase that is usually the first guess.

The tcgen05 GEMM grid is persistent and capped: 2 * min(tiles, 74) = 148 CTAs
(gpu/gemm/src/host.rs:80-94), one per SM. Every dominant GEMM therefore
launches the same 148 CTAs at every batch size, and its last-wave efficiency
sits between 97% and 100% across 16..32 with no trend in B. Nothing tiles
better at 32 than at 16, and nothing tiles badly at any of them: N = 2048·B
and C = 512·B clear every divisibility gate for every integer B.

What does change is the launches whose grid is small and proportional to N.
router_softmax_topk and router_backward take
LaunchConfig::for_num_elems(N) (gpu/model/src/lib.rs:4795, :5065), which
is 256 threads per block and so N/256 = 8·B blocks: 128 at B=16, less than
one wave on 148 SMs
, and 256 at B=32. Beside them sit the fixed-width
serialization points — moe_bin_assign at 8 CTAs, moe_aux_terms at 8 × 12
layers, the loss tail at 1 — whose cost is simply amortized over twice the
tokens. A gain that accumulates gradually over 20/24/28/32 rather than arriving
as a step is what that predicts, and is what the table shows.

Costs

  • Checkpoints record N and C in their header and refuse a mismatch, so
    nothing saved at B = 16 resumes here.
  • bin/profile.rs stays at 12. It is the A/B reference compare_profile
    builds historical refs against, and moving it would silently rebase every
    before/after claim.
  • Headroom goes from 58.55 GiB to 4.30. Anything added later that allocates per
    batch now has to come out of B rather than out of slack.

…oved the wall

`B = 16` was chosen when a unit of batch cost 5.33 GiB and the curve went
flat right after it. The fusions cut that to 3.39 GiB, which moves the
B200's ceiling from 21 to 33 and, with it, where the curve flattens: 32 is
worth 2.7% over 16, and the flat stretch is now 32 -> 33, not 16 -> 20.

Measured on one B200, 12 steps with the first discarded, every number from
train.rs itself:

  B   tokens/s   MFU      peak VRAM   vs B=16
  16  90 286.2   40.09%   119.80 GiB  --
  20  90 488.7   40.18%   133.36 GiB  +0.22%
  24  91 527.3   40.64%   146.94 GiB  +1.37%
  28  92 055.7   40.88%   160.50 GiB  +1.96%
  32  92 717.6   41.17%   174.05 GiB  +2.69%
  33  92 680.0   41.15%   177.40 GiB  +2.65%
  34  out of memory

32 keeps 4.30 GiB spare; 33 keeps 0.95 and buys nothing.
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