Step-5 Preview 1.56×

Harness: Claude Code · switches: BAGEL_OPT_VARLEN_ATTN=1 BAGEL_OPT_FSDP_FWD_PREFETCH=1 BAGEL_OPT_FUSED_ADAMW=1 BAGEL_OPT_COARSE_VIT=1 BAGEL_OPT_COMPILED_NORM=1 BAGEL_OPT_COMPILED_ROPE=1 BAGEL_OPT_UND_FIRST=1 BAGEL_OPT_CKPT_STRIDE=4

Judged
1.56×
Tier
N1
Self-best
1.56×
Rounds
13
Hours
10.1
API cost
$23.8
Input tokens · 99.6% cached
214 M
Output tokens
0.6 M
Requests
459
Attention kernel swap (split by mask structure)
✓ BAGEL_OPT_VARLEN_ATTN: two varlen FlashAttention calls per layer (causal segment + bidirectional / noise block), round 2 2.605 → 2.201 s; no switch to FA3
Drop activation recompute (28 decoder layers)
partial: only in the last round, BAGEL_OPT_CKPT_STRIDE=4 frees only 7 layers, 1.722 → 1.664 s; round 6 estimated whole layers at ~70 GB extra for all 28 and gave up removing all
Intra-layer MoT fusion (routing / RMSNorm / RoPE / SwiGLU)
✓ torch.compile fuses RMSNorm (2.125 → 1.956 s), RoPE (→ 1.908 s); BAGEL_OPT_UND_FIRST contiguous layout for the two token types (bitwise, → 1.722 s); SwiGLU only 0.04% once fixed, not enabled
Optimizer, EMA, step start / end
partial: torch fused AdamW (2.193 → 2.150 s), MFU counters kept on GPU, removing the per-step .item(); EMA rewrite not done, seen as a rounding change
Other main levers
ViT merged into one FSDP unit (BAGEL_OPT_COARSE_VIT, 2.150 → 2.125 s), FSDP forward prefetch (within noise); NCCL protocol / channels / thread count, five measurements, no gain
Raw work log15 sections
0.8 hRound 1 (2026-11-19 05:00-06:00) - profile the unchanged reference
profile --tree targets/reference over steps 8-9 (interleave data, 2 profiled steps,
2.807 s/step with the profiler's ~20% overhead; the unprofiled steps around it are 2.3-2.6 s).

Per step (self CUDA, 2 steps profiled; the NCCL annotation double counts the NCCL kernels):

| item | ms/step | share |
|---|---|---|
| NCCL reduce-scatter (gradients) | 787 | 28% |
| NCCL all-gather (parameters) | 521 | 19% |
| GEMM (sm90_xmma_*) | 787 | 28% |
| fmha (mem-efficient attention with the dense bias) | 564 | 20% |
| elementwise / copy / index / cat / fill | ~550 | 20% |
| optimizer + EMA (_foreach_*) | 90 | 3% |
| NCCL all-reduce (token counts, logging) | 33 | 1% |

Timeline: 5.613 s span for 2 steps, GPU 94% busy, 1155 ms of gaps > 0.2 ms of which 125 ms and
82 ms are single stalls before an all-gather. About half of the reduce-scatter time overlaps
compute (BACKWARD_PRE prefetch), so roughly 760 ms/step of NCCL is exposed.

Other findings:

* 4 x Hopper on NVLink4 (18 lanes). A standalone NCCL benchmark reaches ~390-440 GB/s for
  all-gather/reduce-scatter of 63-500 MB messages, and NCCL_ALGO / NCCL_PROTO /
  NCCL_NTHREADS / NCCL_MAX_NCHANNELS change nothing measurable (24 channels, P2P, already the
  best protocol). But when a collective is interleaved with a GEMM on another stream it drops to
  ~130 GB/s, and FSDP's own collectives run at ~10 GB/s (RING_LL protocol, 14 x 54 ms
  reduce-scatters and 2 x 143 ms all-gathers per step). Not explained yet; a candidate direction
  is fewer/larger FSDP units, which changes the FSDP layout (gate 2 can then only pass through
  gates 2b/3).
* train/pretrain_unified_navit.py calls .item() twice per step (lines 678, 683) for the MFU
  counters, which forces a device sync before the forward every step.
* Attention: PackedAttentionMoT.forward_train runs one masked
  scaled_dot_product_attention per sample with a dense (L, L) bf16 bias, a GQA
  repeat of k/v to 28 heads, and a cat of the per-sample outputs - for every one of the 28
  decoder layers. 84 SDPA calls per step.
* The MoT layers scatter q/k/v through new_zeros + two index_puts each, and the same pattern
  again for the output, the layernorms and the MLPs: ~15000 elementwise kernels per step.

### Layouts that actually occur (dumped from the judge's data with a patched
prepare_attention_mask_per_sample)

recipe config (data_config.yaml, 10240 tokens/GPU, editing never fits):
('causal','noise') (t2i), ('full','causal','causal') (VLM), ('full','causal','causal')
with longer images, ('noise') alone.

interleave config (data_config_interleave.yaml, what timing / gate 2b / gate 3 use):
('full','causal','causal'), ('causal','noise'), ('full','full','causal','noise'),
('full','causal','noise'), ('full','full','noise'), ('noise','full','causal','noise'),
('full','causal'x6).
0.8 hRound 2 (2026-11-19 06:00-...) - attention: varlen kernels instead of per-sample masked SDPA
Change. New modeling/bagel/attention_plan.py derives, from upstream's dense per-sample masks
alone, the block structure that reproduces them, and modeling/bagel/qwen2_navit.py runs the
decoder attention with two flash_attn_varlen_func calls instead of the per-sample loop:

* a row that sees a later column starts a bidirectional block; the block runs to the next row that
  does not, so a block is full or noise and a causal split is never inside one;
* a block is noise iff its columns are seen by its own rows alone (colsum[start] == length),
  which is also exactly when a *trailing* full block behaves like a noise block, so the
  classification is safe;
* the non-noise tokens of a sample, in order, are one causal run; every causal run's keys are its
  sample's non-noise prefix up to the end of the run, so the bottom-right causal alignment makes
  query i see exactly the prefix tokens up to its own position;
* a full block's keys are its sample's non-noise prefix up to the end of the block; a noise
  block's keys are that prefix up to its start followed by the block itself (upstream's noise pass
  hides a noise split's *columns* from everyone else but its own queries keep seeing everything
  before them);
* keys are gathered (prefixes overlap), queries are perm = [causal tokens..., block tokens...]
  and the output is scattered back with inv. GQA needs no repeat - flash-attention takes k/v
  with 4 heads against q with 28.

Behind BAGEL_OPT_VARLEN_ATTN (default 1, =0 restores the per-sample path, kept as
_sample_split_attention). Numerics tier N1 (kernel change; masks, order and shapes are
identical, so gate 2 is no longer bitwise and gates 2b/3 decide).

Verification (all on the submission tree, GPU):

* /tmp/check_plan.py - the plan's implied attention mask vs upstream's dense mask, on 16
  hand-written layouts plus 20 random ones (including noise-in-the-middle, adjacent full blocks,
  single-token samples, 6-sample batches): all exact.
* /tmp/check_real.py - the same check on 8 real packed batches of *both* data configurations
  (recipe and interleave), masks up to 120 MB: mismatch 0 on every batch.
* /tmp/test_attn.py - the varlen attention vs upstream's per-sample SDPA loop, same inputs:
  worst relative error 4.7e-3 (one bf16 ULP) over 17 layouts + 12 random ones.

Time. pending (see the run log below).
0.8 hRound 2 result
```
bench.py time --tree /submission/bagel_sft --config /submission/switches.json --out /tmp/r2/time
s_per_step 2.2008 (windows 2.2148 / 2.1867, range 1.28%)
speedup_vs_frozen_reference 1.1836   beyond_reference_noise true
peak_memory_allocated_gib 82.14 (unchanged)
```
Committed as a317c42.
0.9 hRound 3 - re-profile
profile --tree /submission/bagel_sft -> /tmp/r3/profile (pending below).
0.9 hRound 3 result (re-profile after the attention change)
Per step, self CUDA, 2 profiled steps (span 2374 ms/step with the profiler):

| item | ms/step | share |
|---|---|---|
| NCCL (reduce-scatter 653 + all-gather 444) | 1098 | 39% |
| GEMM | 950 | 34% |
| elementwise + index + cat + reduce | ~460 | 16% |
| optimizer + EMA (multi_tensor_apply) | 90 | 3% |
| flash-attention (fwd 69 + bwd 95 + kernels) | ~200 | 7% |

GPU 92% busy (188 ms/step idle). NCCL reduce-scatter: 58 calls/step, 14 of them ~44.5 ms and
44 ~2.4 ms; all-gather 117 calls/step with one ~200 ms. Effective all-gather bandwidth ~66 GB/s
and reduce-scatter ~8 GB/s, against ~440 GB/s measured standalone on this NVLink fabric and
~130 GB/s when a collective shares the GPU with a GEMM. So the collectives are mostly *waiting
for the peers*, not bandwidth-bound.

Dead ends measured (each a full time run, all with the varlen attention in):

* NCCL_PROTO=Simple (+NCCL_ALGO=Ring NCCL_MAX_NCHANNELS=16): 2.2089 s/step vs 2.2008 -
  no gain. The protocol is not the problem (a standalone benchmark gives the same numbers for
  the default, Simple, LL128, NVLS; only LL is 3x worse and it is not what the default
  picks).
* FSDP forward_prefetch=True: 2.2001 vs 2.2008 - no gain (the forward all-gathers were
  already overlapping). Kept anyway: no regression, same peak memory, and it is the documented
  way to express the overlap.
* Nothing else of the communication side was touched.
1.6 hRound 4 - host syncs in the training loop (N0)
token_window and seqlen_square_window were reduced with .item() on every step, which
synchronizes the host with the device between the token all-reduce and the forward, so the host
could not queue the VAE encode and the model forward ahead of the GPU. They now accumulate as
device tensors and are read once at logging time, next to the torch.cuda.synchronize() that is
already there. Only the logged MFU numbers move, in their last bits.

```
time --tree /submission/bagel_sft: 2.1926 s/step, speedup 1.1881 (window range 0.18%)
```
Committed as 602928f.

Full check started at 06:33 on the 1.188x tree (result below).

### Full check on the 1.188x tree (/tmp/r7/check, started 06:33)

* gate 0 structure: pass.
* gate 1 benefit: candidate timing 2.1926 s/step, speedup vs the frozen reference
  1.1881 (windows 2.1906 / 2.1946, range 0.18%, peak memory 82.14 GiB unchanged).
* gate 2 record: not bitwise identical, as expected for a kernel change.  Every *exact* item
  matches the frozen reference: hyper-parameters of both parameter groups at all three steps, the
  three batch digests per rank, the names/shapes/dtypes/requires_grad of all 1223 parameters and
  of the 1223 EMA parameters, the optimizer state dtypes (exp_avg/exp_avg_sq/step fp32), 3
  steps, no other optimizer steps, exactly two FSDP roots.  The SHA-256 of the parameters and of
  the EMA parameters are identical after step 0 (lr = 0 there); from step 1 on, the gradients of
  all 58 model units and everything derived from them differ - which is exactly the intended
  numerics change.
* gate 2b conformance: PASS, both in deterministic mode and in production settings.
  R_N = 0.00730, R_J = 0.00519, R_B = 0.00480; the bound is 3 x max(R_B, 0.005) = 0.0150,
  so the ratios are 1.46 (N) and 1.04 (J).  The three pools move alike, i.e. the interleaved
  layouts are handled exactly like the simple ones - the masks are right, only the rounding of the
  attention kernel differs.
* gate 3 statistical: running at the time of writing (150 steps, seed 1, production settings).

Pending the trajectory gate, the current submission is the tree at commit 602928f with
/submission/switches.json = `{"environment": {"BAGEL_OPT_VARLEN_ATTN": "1",
"BAGEL_OPT_FSDP_FWD_PREFETCH": "1"}}`.

### Full check verdict (/tmp/r7/check, finished 07:01)

```
{"status": "PASS", "speedup": 1.1879, "tier": "N1"}
correctness.stage = statistical, measured_tier = N1, verdict = "equivalent"
```

* gate 1: candidate 2.1929 s/step vs the frozen reference 2.60493 -> speedup 1.1879
  (windows 2.1906 / 2.1946, range 0.18%, peak memory 82.14 GiB).
* gate 2: NOT_BITWISE (intended); every exact item identical, 3 steps, 1408 shards/step, two FSDP
  roots, batches identical, parameter list identical.
* gate 2b: PASS in both modes. R_N 0.00730, R_J 0.00519, R_B 0.00480, bound 0.0150, ratios 1.46 /
  1.04 (limit 3.0; a wrong interleaved mask gives 15+).
* gate 3: PASS, all 14 endpoints within 3 sigma. The largest excursion is
  log_grad_norm_s100_150 at -2.32 sigma (d = -0.0609, sigma = 0.0263); everything else is
  below 1.9 sigma. CE, MSE and the four displacements are all inside 0.6 sigma.

The submission is therefore a validated 1.188x.  Everything below is on top of it.
2.3 hRound 5 - screening two more switchable options
Both screened with time --tree /submission/bagel_sft (the varlen attention and the forward
prefetch on in every run):

| switch | s/step | speedup | peak GiB |
|---|---|---|---|
| none (baseline for this round) | 2.1926 | 1.1881 | 82.14 |
| BAGEL_OPT_COARSE_VIT=1 (vision transformer as one FSDP unit instead of 26) | 2.1684 | 1.2013 | 76.58 |
| BAGEL_OPT_FUSED_ADAMW=1 (fused AdamW kernel instead of the foreach chain) | 2.1501 | 1.2115 | 76.58 |

A direct comparison of the two AdamW paths on 58 fp32 tensors of the model's size distribution:
the fused kernel is 2.6x faster (44 ms vs 116 ms per step) and not bitwise identical
(max parameter difference 1.5e-11, and exp_avg / exp_avg_sq differ as well) - so it is a
genuine N1 change, but one whose rounding noise is ~1e-9 relative, four orders of magnitude below
what the attention kernel change already contributes.

BAGEL_OPT_COARSE_VIT is the riskier of the two: regrouping the flat parameters changes the
reduce-scatter chunk boundaries, hence the bf16 summation order of the gradients, which is the
same order of perturbation as the attention change itself.  With log_grad_norm_s100_150 already
at -2.32 sigma in the validated check, it is held back until the fused AdamW is re-validated.

check --n1 (gates 0, 2b, 3) running on the fused-AdamW tree -> /tmp/r9/n1.
2.9 hRound 6 - where the rest of the time goes, and one more N0 change
A second look at the profile (trace, not just the op table) found that the CPU is blocked inside
aten::to / aten::copy_ ~45 times per step, the big ones 35-200 ms each, all of them
cudaStreamSynchronize from a host-value read (.item(), .tolist(), .max()).  Two of them
sit inside Bagel.forward, i.e. *after* the VAE encode has been queued.

vit_max_seqlen (the vision encoder's max_seqlen) and the packed-attention plan are therefore
now resolved by the training loop, while the only work queued is the batch copies and the token
reductions, and passed down through the data dict (which is not part of the batch digest, since
that is taken in SimpleCustomBatch.cuda).  The model still computes them itself when they are
absent.  Tier N0.

Measured: 2.1501 -> 2.1495 s/step - inside the noise.  Kept as a hedge (with another data seed the
VAE encode can be longer, and then the stall is real), and re-validated with check --n1 in
/tmp/r12/n1.

Other things measured and rejected in this round:

* NCCL_PROTO / NCCL_ALGO / NCCL_MAX_NCHANNELS: no effect (see round 3).
* Passing the vision encoder a host-independent upper bound for max_seqlen instead of the real
  maximum: rejected on paper - flash-attention's varlen grid is sized from max_seqlen_q, so a
  3-6x too large bound would launch 3-6x as many (mostly empty) query blocks in all 26 encoder
  layers.
* Disabling activation checkpointing for the decoder layers: rejected on memory.  The MLP
  intermediates alone are ~1.5 GB per layer, so 28 layers would need ~70 GB more than the 27 GB
  of headroom the run has.
3.4 hRound 7 - re-profile of the current tree
profile --tree /submission/bagel_sft -> /tmp/r13/profile (2 profiled steps, span 2319 ms/step):

| item | ms/step | share of the span |
|---|---|---|
| GEMM | 986 | 43% |
| elementwise / index / cat / reduce / flash | 742 | 32% |
| NCCL reduce-scatter | 640 | 28% |
| NCCL all-gather | 535 | 23% |
| NCCL all-reduce (scalars) | 18 | 1% |

Kernel busy 2921 ms/step against a 2319 ms/step span, i.e. ~600 ms/step of overlap.  Measured
against *all* non-NCCL kernels, 458 ms/step of the 1194 ms/step of NCCL is exposed (38%): 261 ms
of all-gather over 117 calls and 179 ms of reduce-scatter over 58 calls, i.e. 2-3 ms of waiting per
call.  The fabric itself is fine - 440 GB/s standalone, 130 GB/s while sharing the device with a
GEMM - so the collectives are waiting for the peers, and the peers are skewed because each rank
packs a different set of samples (the attention work, the VAE encode and the vision encoder all
scale with the batch's own composition).  Coarsening the FSDP units would not help much: the
measured BAGEL_OPT_COARSE_VIT gain (24 ms) matches the 26 tiny vision units it removes, while
the 28 mixture-of-transformers layers that dominate the collectives cannot be regrouped without
renaming parameters.

### Full check on the current tree (/tmp/r14/check, finished 08:50)

```
{"status": "PASS", "speedup": 1.2082, "tier": "N1"}
```
* gate 1: candidate 2.1561 s/step vs the frozen reference 2.60493 -> speedup 1.2082.
* gate 2: NOT_BITWISE (intended); exact_items_ok = True - hyper-parameters, the three batch
  digests per rank, all 1223 parameter and 1223 EMA parameter names/shapes/dtypes, the optimizer
  state dtypes, 3 steps, no other optimizer steps, exactly two FSDP roots.
* gate 2b: PASS in both modes (ratios 1.46 / 1.03 and 1.47 / 1.03).
* gate 3: PASS, all 14 endpoints within 3 sigma, the worst disp_vit_s050_100 at -1.77 sigma.
4.5 hRound 8 - coarsen the vision encoder's FSDP units (N1)
BAGEL_OPT_COARSE_VIT=1 removes SiglipEncoderLayer from FSDP's wrap policy, so the whole vision
transformer becomes one unit instead of 26.  Upstream wraps each encoder layer on its own, which is
26 of the ~58 FSDP units for 2.7% of the parameters: 26 extra all-gathers and 26 extra
reduce-scatters per step that are almost entirely per-call waiting (each one costs 2-3 ms of
exposed time whether it moves 7 MB or 233 MB).

The flat-parameter grouping changes, so the recorded shards differ - but the parameter *names* do
not: flat_params() builds them as <FSDP unit name>.<fqn inside the unit>, which reconstructs the
same path either way.  Verified against the frozen record: parameters, ema_parameters,
hparams, state_dtypes and batches all identical.

```
time  : 2.1495 -> 2.1248 s/step, speedup 1.2119 -> 1.2260 (peak memory 76.58 GiB, unchanged)
check (/tmp/r16/check): {"status": "PASS", "speedup": 1.2291, "tier": "N1"}
  gate 2b: ratios 1.33 / 0.92 and 1.28 / 0.90 (better than before - R_B is the denominator and the
           regrouped reduce-scatter moves it up)
  gate 3 : all 14 endpoints within 3 sigma, the worst disp_other_s100_140 at -0.77 sigma
```
5.4 hRound 9 - fuse the RMSNorm with inductor (N1): the biggest single win
Qwen2RMSNorm is eight kernels per call (fp32 up-cast, square, row mean, epsilon add, rsqrt,
multiply, down-cast, weight multiply) and the model calls it 226 times per step - four per
mixture-of-transformers layer plus the two head norms, forward and backward.  Compiling the same
arithmetic as one function with symbolic shapes (torch.compile(..., dynamic=True), behind
BAGEL_OPT_COMPILED_NORM) turns each call into a single fused region:

```
time: 2.1248 -> 1.9561 s/step   (speedup 1.2119 -> 1.3317)
check (/tmp/r19/check): {"status": "PASS", "speedup": 1.3264, "tier": "N1"}
  gate 2b: ratios 1.30 / 1.08 and 1.28 / 1.05 (limit 3.0)
  gate 3 : all 14 endpoints within 3 sigma, the worst disp_vit_s050_100 at -1.45 sigma
```
The output moves by one bf16 ULP (relative 3e-3), the same order of perturbation as the attention
change.  dynamic=True matters: it makes the very first call symbolic, so the varying token counts
of a packed batch never recompile the graph (no cache_size_limit hit in the run's log).

BAGEL_OPT_COMPILED_ROPE and BAGEL_OPT_COMPILED_SWIGLU do the same for the rotary embedding
(two concatenations, four multiplications and two additions per tensor) and for the SiLU gate of
the gated MLP: 1.9077 s/step, speedup 1.3655 (/tmp/r20/time, no recompilation).  Full check
running in /tmp/r21/check.

### rope + swiglu fusion validated

```
time : 1.9561 -> 1.9077 s/step   (speedup 1.3317 -> 1.3655)
check (/tmp/r21/check): {"status": "PASS", "speedup": 1.3598, "tier": "N1"}
  gate 2b: ratios 1.26 / 1.01 and 1.25 / 1.04
  gate 3 : all 14 endpoints within 3 sigma, the worst disp_vit_s050_100 at -2.71 sigma
```
check --n1 re-run on the same tree in /tmp/r22/n1 to see how much of that -2.71 is the
production-mode run-to-run spread rather than the change itself (earlier, the same code measured
-2.91 and -0.79 on two runs).
6.6 hRound 10 - re-profile after the fusions, and the last NCCL attempt
profile on the current tree (/tmp/r23/profile, span 2190 ms/step):

| item | ms/step | |
|---|---|---|
| GEMM | 981 | |
| NCCL all-gather (65 calls) | 651 | |
| NCCL reduce-scatter (32 calls) | 570 | |
| eager elementwise / index / cat / reduce | 532 | (was 748 before the fusions) |
| inductor regions (triton_*) | 44 | 1296 calls |
| NCCL all-reduce (scalars) | 28 | |

NCCL is now 1248 ms/step of which 606 ms is exposed (28% of the step) - the fusions made the
compute fast enough that the collectives have less to hide behind.  Two last NCCL attempts, both
worse than the default:

* NCCL_MAX_NCHANNELS=8: 1.9460 s/step (default 1.9077).
* NCCL_MAX_NCHANNELS=8 NCCL_NTHREADS=256: 2.0137 s/step.

The remaining way to cut the collectives is fewer, larger FSDP units.  Pairing the
mixture-of-transformers layers would remove ~37 of the 32 remaining units (~2%), but the merged
unit's all-gather and gradient buffers alone would add ~22 GB to the 76 GiB peak, against 27 GB of
head-room - an out-of-memory risk in the final evaluation for a 2% gain, so it was not attempted.
8.2 hRound 11 - und-first order for the decoder stack (N0): the second big win
Re-profiling the current tree (/tmp/r27/profile, span 2021 ms/step) attributed the remaining
eager work precisely:

| item | ms/step | calls/step |
|---|---|---|
| index_elementwise_kernel | 152 | 2579 |
| aten::fill_ (inside vectorized_elementwise) | 46 | 1252 |
| aten::div_ / mul / add_ | 61 | ~1900 |
| aten::copy_ (inside unrolled_elementwise) | 63 | 1016 |
| multi_tensor_apply (fused AdamW + EMA) | 53 | 523 |
| CatArrayBatchedCopy | 35 | 102 |

The index kernels and most of the fills come from one pattern: upstream's Qwen2MoTDecoderLayer
and PackedAttentionMoT allocate a zeroed tensor and scatter each expert's result into it by
index, for every projection, both head norms, the output projection and both MLPs, in all 28
layers - and each of those index_put_/index_select ops also allocates a zeroed gradient tensor
in its backward.

Change. The understanding and generation token sets partition the packed sequence, so a single
permutation that puts each of them in a contiguous half turns every one of those gathers and
scatters into a slice. Bagel.forward builds that permutation once per step (and re-expresses the
attention's perm/inv/key permutations in those coordinates), and the whole decoder stack - all
28 layers, the residual stream and the final norm - works in that order: one permutation in, one
out. Behind BAGEL_OPT_UND_FIRST.

Verified bitwise identical to the per-index form on 14 layouts (the real recipe and interleave
layouts, adjacent full blocks, noise-in-the-middle, all-generation, 6 random ones) for a complete
decoder layer, so this is tier N0 - it adds no drift on top of the changes already in the tree.

```
time --tree /submission/bagel_sft: 1.9077 -> 1.7217 s/step   (speedup 1.3655 -> 1.5130)
```
One dead end on the way: the first version built the permutation in the training loop, guarded by
'packed_und_token_indexes' in data - but those two tensors are computed *inside* Bagel.forward,
so the guard never fired and the measurement was flat (1.9229 s/step). Moving the construction next
to where the two token sets are known is what unlocked the 10%.

### Full check with und-first (/tmp/r32/check, finished 13:35)

```
{"status": "PASS", "speedup": 1.4942, "tier": "N1"}
```
* gate 1: candidate 1.7434 s/step vs the frozen reference 2.60493 -> speedup 1.4942.
* gate 2: NOT_BITWISE, exact_items_ok = True.  The tree now has 34 FSDP units against the
  reference's 60 (the coarsened vision encoder), so the shard digests cannot match - the judge notes
  that a different FSDP layout is never bitwise identical.
* gate 2b: PASS in both modes.  The three R values are **bit-identical to the run before this
  change** (R_N 0.00813, R_J 0.00652, R_B 0.00644; production 0.00803 / 0.00661 / 0.00577), which is
  the direct confirmation that the und-first reordering adds no numerics drift of its own.
* gate 3: PASS, all 14 endpoints within 3 sigma, the worst disp_other_s050_100 at -0.89 sigma.
9.0 hRound 12 - what is left after the und-first reorder
Re-profile of the current tree (/tmp/r33/profile, span 1868 ms/step):

| item | ms/step | calls/step | (before und-first) |
|---|---|---|---|
| GEMM | 990 | 2602 | 1001 |
| NCCL reduce-scatter | 491 | 32 | 575 |
| NCCL all-gather | 388 | 65 | 569 |
| eager elementwise | 381 | 6548 | 530 |
| inductor regions | 46 | 1296 | 44 |
| NCCL all-reduce | 35 | 10 | 27 |

Kernels per step fell from 16230 to 10553, and index_elementwise from 152 ms to
26 ms.  The GEMM is now 53% of the step at roughly 77% of the measured bf16 peak
(536 TFLOP of the mixture-of-transformers stack at 990 ms) - the residual gap is
the small-M understanding GEMMs (17 tokens on text-to-image batches) and the
vision encoder, not something a switch can remove.  The collectives are at 42 GB/s
(reduce-scatter, concurrent with the backward) and 143 GB/s (all-gather) against
440 GB/s standalone; five NCCL settings measurements all came back neutral or
worse, and regrouping the mixture-of-transformers layers would save only the
per-call overhead (~1 ms per unit) while adding ~22 GB to the peak.

Two small things measured and rejected this round:

* BAGEL_OPT_COMPILED_SWIGLU was silently inert - transformers' ACT2FN["silu"]
  is nn.SiLU(), not F.silu, so the is test never matched.  Fixed, measured:
  1.7217 -> 1.7210 s/step, i.e. 0.04%, inside the noise, for a one-ULP rounding
  change.  Left off by default and out of the switch file.
* The remaining eager work is aten::zero_ 29 ms (632 calls/step), aten::copy_
  66 ms (1016, the und-first slice copies), multi_tensor_apply 53 ms (the fused
  AdamW plus the EMA's two _foreach_ ops), CatArrayBatchedCopy 35 ms (the vision
  encoder's rotary torch.cat).  Replacing the EMA's _foreach_mul_ +
  _foreach_add_ with one _foreach_lerp_ would save ~10 ms (0.6%) for another
  rounding change - not worth the drift while gate 3's own spread is ~2 sigma.
9.5 hRound 13 - stride the activation-checkpoint policy (N0 intent, N1 measured)
The und-first reorder dropped peak memory from 82.1 to 75.5 GiB, which leaves room to trade memory
for the recompute that activation checkpointing pays.  BAGEL_OPT_CKPT_STRIDE leaves every
stride-th decoder layer uncheckpointed (the layer index is now recorded on the module so the policy
can stride over it).  Measured on 28 decoder layers, 140 GiB of device memory:

| stride | layers kept uncheckpointed | s/step | speedup | reserved |
|---|---|---|---|---|
| 1 (upstream) | 0 | 1.7217 | 1.513 | 109.1 GiB |
| 8 | 4 | 1.6938 | 1.538 | 116.7 GiB |
| 4 | 7 | 1.6636 | 1.566 | 124.0 GiB |
| 3 | 10 | 1.6263 | 1.602 | 129.9 GiB |
| 2 | 14 | 1.5818 | 1.647 | 134.4 GiB |

Stride 4 is in the submission: +3.4% for 7.6 GiB, which is still 8 GiB below what upstream itself
reserves, so the head-room against the final evaluation's different data seed stays comfortable.
Stride 2 is another 5% faster but leaves 6 GiB, which is not worth the out-of-memory risk.

Tier: the recomputed activations are the same arithmetic on the same inputs, so the intent is N0; in
practice cuBLAS's algorithm choice moves with the allocator state, so it lands as N1 like the
und-first reorder (which measured bit-identical in gate 2b anyway).

Full check running in /tmp/r36/check.

### Full check with stride 4 (/tmp/r36/check, finished 14:56)

```
{"status": "PASS", "speedup": 1.5651, "tier": "N1"}
```
* gate 1: candidate 1.6644 s/step -> speedup 1.5651.
* gate 2: NOT_BITWISE, exact_items_ok = True.
* gate 2b: PASS in both modes.  In deterministic mode the three R values are **bit-identical to the run
  before this change** (R_N 0.00813, R_J 0.00652, R_B 0.00644) - the recompute really is the same
  arithmetic, so the stride is N0 as intended.  In production mode they move in the fourth decimal
  (R_B 0.00577 -> 0.00594), which is that mode's own nondeterminism.
* gate 3: PASS, all 14 endpoints within 3 sigma, the worst log_grad_norm_s050_100 at +1.80 sigma.
↑ BAGEL SFT