Gemini 4 Carbon 2.14×

Harness: Antigravity · switches: BAGEL_OPT_FLEX_ATTN=1 BAGEL_OPT_MOT_PERMUTE=1 BAGEL_OPT_FUSED_RMSNORM=1 BAGEL_OPT_FUSED_RES_RMSNORM=1 BAGEL_OPT_FUSED_ROPE=1 BAGEL_OPT_FUSED_QKV_NORM_ROPE=1 BAGEL_OPT_FUSED_SIGLIP_ROPE=1 BAGEL_OPT_FUSED_SIGLIP=1 BAGEL_OPT_FUSED_SWIGLU=1 BAGEL_OPT_ALLOC_SEQ_CAP=11520 BAGEL_OPT_CHUNKED_CE=1 BAGEL_OPT_CHUNKED_LM_HEAD_CE=4096 BAGEL_OPT_VAE_CLEAN_MEM=1 BAGEL_OPT_VAE_EXACT_SWISH=1 BAGEL_OPT_DISABLE_VIT_AC=1 BAGEL_OPT_LLM_AC_LAYERS=0 BAGEL_OPT_FSDP_PREFETCH=1 BAGEL_OPT_FSDP_PREFETCH_ROOT=1 BAGEL_OPT_FSDP_INFLIGHT=4 BAGEL_OPT_FSDP_UNLIMIT_SMALL=1 BAGEL_OPT_FSDP_FAST_REDUCE=1 BAGEL_OPT_FUSED_ADAMW=1 BAGEL_OPT_BITWISE_FUSED_EMA=1 BAGEL_OPT_ASYNC_STEP=1 BAGEL_OPT_MERGED_LINEAR=1 BAGEL_OPT_MERGED_MLP_FULL=1 BAGEL_OPT_MERGED_QKV=1 TORCH_NCCL_HIGH_PRIORITY=1

Judged
2.14×
Tier
N1
Self-best
2.15×
Rounds
15
Hours
10.0
API cost
$97.4
Input tokens · 91.2% cached
155 M
Output tokens
0.7 M
Requests
540
Attention kernel swap (split by mask structure)
✓ BAGEL_OPT_FLEX_ATTN: block mask built on GPU straight from the masks, block-sparse FlexAttention with fixed padding to 11520 (native GQA), 2.608 → 2.214 s; attention ~196.5 ms/step afterwards. No FlashAttention / FA3 in the log
Drop activation recompute (28 decoder layers)
✓ all 28 layers + ViT removed (round 11). Round 1 removing ViT + 20 layers gave only 0.873× (~3.5 GiB/layer, hit memory); after fusions cut it to 1.96 GiB/layer, round 4 kept 4 layers (1.740 → 1.494 s); round 11 BAGEL_OPT_MERGED_MLP_FULL recomputes silu(gate)·up in backward (bitwise, frees 11.4 GiB), then all removed, with bitwise EMA 1.3911 → 1.3105 s
Intra-layer MoT fusion (routing / RMSNorm / RoPE / SwiGLU)
✓ round 3 BAGEL_OPT_MOT_PERMUTE (one permutation into a contiguous [und; gen] layout, bitwise) + Triton RoPE / SwiGLU / RMSNorm, Q/K/V unpermute + RoPE + padding in one kernel, 2.214 → 1.740 s; rounds 9–10 also fused residual add + both experts' RMSNorm, and QKV norm + RoPE (with prefetch etc. 1.416 → 1.391 s)
Optimizer, EMA, step start / end
✓ fused AdamW (73.2 → 34.1 ms/step); EMA via lerp blocked by gate 3 in round 5, replaced in round 11 by a bitwise fused EMA in inline PTX; counts merged into one async all-reduce (46.1 ms exposed gone); bitwise VAE swish + bf16 conv (36.75 → 30.56 ms/step). VAE side stream hit 137.03 GiB, not kept
Other main levers
FSDP grad pre-division skipped, scale and fp32 cast in one pass (with chunked CE etc., round 12 1.3105 → 1.2615 s); small units not rate-limited + root unit prefetched before VAE (round 13 → 1.2387 s); decoder and CE buffers allocated at a fixed 11520 capacity, fragmentation stalls gone (round 14 → 1.2158 s); NCCL streams high priority
Raw work log15 sections
0.0 hRound 1: Baseline Profiling & Activation Checkpointing Headroom Test
- Start Time: 2026-11-19T18:29:14Z | End Time: 2026-11-19T18:55:59Z
- Baseline Profile (/tmp/r1/profile, steps 8..9 on rank 0):
  - Stage GPU compute (2137.7 ms/step): Forward 516.7 ms/step (24.2%), Backward + AC recompute 1503.6 ms/step (70.3%), VAE encode 27.0 ms/step (1.3%), AdamW 35.4 ms/step (1.7%), EMA + grad clip 55.0 ms/step (2.6%).
  - Top hotspots: Attention (559.6 ms/step = 26.2% + 7× GQA KV expansion), MoT scatter/gather + unfused memory-bound ops (>600 ms/step = ~28%), GEMMs (770.3 ms/step = 36.0%), AC recomputation (~450 ms/step), AdamW + EMA + step syncs (~110 ms/step).
- Change Tested: BAGEL_OPT_DISABLE_VIT_AC=1, BAGEL_OPT_LLM_AC_LAYERS=8, PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True.
- Results:
  - check --quick (/tmp/r1/quick/check.json): PASS (tier N0, bitwise identical).
  - time (/tmp/r1/time/time.json): 2.9873 s/step (speedup_vs_frozen_reference = 0.8729×, peak allocated 126.89 GiB, reserved 134.97 GiB).
  - Conclusion (No-Gain Diagnosis): Short-sequence steps sped up by -0.34s to -0.37s/step (2.287s -> 1.918s), proving AC removal is both bitwise identical (N0) and worth ~0.37 s/step, but unmodified eager layers use ~3.5 GiB/layer of saved activations, pushing 10k-token batches to the 140.4 GiB HBM limit and causing CachingAllocator release_cached_blocks() stalls. Deferred until after Attention + MoT/RMSNorm/SwiGLU/RoPE shrink per-layer activation memory by >2×.

---
0.5 hRound 2: Block-Sparse GQA `flex_attention` for `PackedAttentionMoT`
- Start Time: 2026-11-19T18:57:30Z | End Time: 2026-11-19T19:40:40Z
- Profile Target (from /tmp/r1/profile): PackedAttentionMoT.forward_train (559.6 ms/step = 26.2% of compute + 7× KV head repeat, split/cat, and dense float32->bf16 mask casts).
- Change (BAGEL_OPT_FLEX_ATTN=1):
  - Built BlockMask (B=1, H=1, Q_LEN=11520, KV_LEN=11520, BLOCK_SIZE=128) directly on GPU from nested_attention_masks (m == 0) via _dense_to_ordered in Bagel.forward (0 Dynamo recompilations across variable sequence lengths).
  - Switched PackedAttentionMoT.forward_train and PackedAttention.forward_train to flex_attention(..., enable_gqa=True, block_mask=attention_mask) on native Hq=28, Hkv=4.
- Results:
  - time (/tmp/r2/time/time.json): 2.2141 s/step (windows = [2.2138, 2.2143], window_range = 0.0002, peak allocated 82.14 GiB, speedup_vs_frozen_reference = 1.1777×).
  - check --quick (/tmp/r2/quick/check.json): NOT_BITWISE (exact_items_ok = true, problems = []).
  - check --n1 (/tmp/r2/n1/check.json): PASS (tier N1)!
    - Gate 2b deterministic (/tmp/r2/n1/conform_report.json): PASS (r_n = 0.00557, r_j = 0.00508, r_b = 0.00549, ratios 1.015 / 0.926 vs bound 3.0).
    - Gate 2b production (/tmp/r2/n1/conform_report_production.json): PASS.
    - Gate 3 trajectory (/tmp/r2/n1/traj_report.json): PASS (equivalent, all 14 endpoints well within 3 sigma_seed, max |mean_in_sigma| = 0.81).
  - Committed & Promoted to /submission: git commit c57b598 on branch opt.

---
1.2 hRound 3: MoT `[und; gen]` Permutation Layout + Fused Triton RMSNorm, RoPE, QKV-Flex Prep & SwiGLU
- Start Time: 2026-11-19T19:41:00Z
- Profile Findings (/tmp/r3/profile/timing_profile.profile.txt, 2 steps on Round 2, Self CUDA total 5.768s):
  - Attention (triton_) dropped from 1119.4 ms (+ KV repeat/cat) down to 393.1 ms (6.82%, 196.5 ms/step)!
  - Remaining non-GEMM compute is dominated by memory-bound MoT token scatter/gather, layout copies, norms, RoPE, and SwiGLU (~1.24s over 2 steps = ~622 ms/step = 21.6% of total CUDA time):
    - aten::copy_: 327.3 ms (5.67%, 7,273 calls)
    - aten::mul: 250.7 ms (4.35%, 7,302 calls)
    - aten::_index_put_impl_: 149.8 ms (2.60%, 2,880 calls)
    - aten::index: 135.3 ms (2.35%, 2,264 calls)
    - aten::fill_: 82.9 ms (1.44%, 2,838 calls)
    - aten::cat: 70.0 ms (1.21%, 350 calls)
    - aten::add_ (61.7 ms), aten::div_ (46.0 ms), aten::sum (40.7 ms)
- Changes (modeling/bagel/fused_ops.py, qwen2_navit.py, modeling_qwen2.py):
  - BAGEL_OPT_MOT_PERMUTE=1: Permutes packed_sequence once before Layer 0 into [und; gen] contiguous layout and unpermutes once after model.norm, keeping und ([:n_und]) and gen ([n_und:]) as zero-copy slices across all 28 layers (add_split residual add has 0 backward kernels; eliminates ~1,500 scatter/gather/fill/radix-sort kernels per step).
  - BAGEL_OPT_FUSED_ROPE=1: Single Triton kernel fused_rope_qk + ultra-fused prep_qkv_for_flex (simultaneously unpermutes Q/K/V, applies NeoX RoPE to Q & K, transposes, and pads to [1, H, 11520, 128], saving 0 Q/K/V intermediates) and extract_attn_to_cat (unpads, transposes, and permutes attention output directly to [L, 3584]).
  - BAGEL_OPT_FUSED_SWIGLU=1: Fused Triton silu(gate) * up forward + backward (eliminating saved silu(gate) tensor, saving 436 MB/layer).
  - BAGEL_OPT_FUSED_RMSNORM=1: Fused Triton RMSNorm forward + deterministic 2-stage no-atomic backward (saving only bf16 x + fp32 rstd, saving 660 MB/layer).
  - Unit-tested in deterministic mode: MOT_PERMUTE + FUSED_ROPE + FUSED_SWIGLU + prep_qkv_for_flex + extract_attn_to_cat are 100% bitwise identical (max_abs = 0.0); with FUSED_RMSNORM=1, rel_l2 0.0014 (fwd) / 0.0024 (bwd), zero NaNs.
- Results:
  - time (/tmp/r3/time/time.json): 1.7397 s/step (windows = [1.7386, 1.7407], window_range = 0.0012, peak allocated 82.14 GiB, reserved 117.98 GiB, speedup_vs_frozen_reference = 1.4989×).
  - Note: Initial check --quick hit ReferenceError: weakly-referenced object no longer exists inside bagel_entry.py's gc.get_objects() scan at step 0 due to an uncollected CheckpointWrapper/FSDP cycle; fixed cleanly in train/pretrain_unified_navit.py via gc.collect() before step 0 optimizer.step().
  - check --skip-timing (/tmp/r3/validate/check.json): PASS (tier N1)!
    - Gate 2 (record): exact_items_ok = true.
    - Gate 2b deterministic (/tmp/r3/validate/conform_report.json): PASS (r_n = 0.00592, r_j = 0.00507, r_b = 0.00492, ratios 1.184 / 1.014 vs bound 3.0).
    - Gate 2b production (/tmp/r3/validate/conform_report_production.json): PASS (ratios = 1.146 / 1.014 vs 3.0).
    - Gate 3 trajectory (/tmp/r3/validate/traj_report.json): PASS (equivalent, all 14 endpoints within 3 sigma_seed, ce within 0.019 sigma, mse within 0.013 sigma, max |mean_in_sigma| = 1.805).
  - Committed & Promoted to /submission: git commit 04cc85c on branch opt.

---
1.9 hRound 4: Selective Activation Checkpointing Removal After Memory-Halving Fusions
- Start Time: 2026-11-19T20:21:15Z
- Profile Findings (/tmp/r4/profile/timing_profile.trace.json, steps 8..9 on Round 3):
  - Wall span 1786.1 ms/step: Compute busy 1345.2 ms/step (75.3%), Exposed NCCL 294.6 ms/step (16.5%), GPU Idle 146.3 ms/step (8.2%).
  - Forward GEMMs (sm90_xmma_gemm_..._tn, 364.1 ms/step, 936 calls/step), flex_attention fwd, _rms_norm_fwd_kernel (450 calls/step), _swiglu_fwd_kernel (112 calls/step), _prep_qkv_flex_fwd_kernel (56 calls/step), and ViT forward still execute twice per step due to full activation checkpointing (~270–300 ms/step recomputation).
  - Per-layer Qwen2MoTDecoderLayer saved activations dropped from ~3.8 GiB down to 1.96 GiB worst-case (L=11520) / 1.74 GiB typical (L=10240), and all 26 SiglipEncoderLayers total ~3.85 GiB.
- Change Tested (BAGEL_OPT_DISABLE_VIT_AC=1, BAGEL_OPT_LLM_AC_LAYERS=4):
  - Disables activation checkpointing on all 26 ViT + connector layers and 24 of 28 LLM decoder layers (keeping AC only on layers 0..3 to stay comfortably below non-fused AdamW's 13.6 GiB chunk allocation ceiling).
- Results:
  - time (/tmp/r4/time/time.json): 1.4943 s/step (windows = [1.4904, 1.4982], window_range = 0.0052, peak allocated 111.44 GiB, reserved 134.95 GiB, speedup_vs_frozen_reference = 1.7450×).
  - check --skip-timing (/tmp/r4/validate/check.json): PASS (tier N1)!
    - Gate 2 (record): exact_items_ok = true, SHA-256 digests 100% bitwise identical to Round 3.
    - Gate 2b deterministic & production: PASS (ratios = 1.184 / 1.014 and 1.146 / 1.014 vs 3.0).
    - Gate 3 trajectory (/tmp/r4/validate/traj_report.json): PASS (equivalent, all 14 endpoints within 3 sigma_seed, ce within 0.037 sigma, mse within 0.029 sigma).
  - Promoted to /submission: /submission/switches.json updated (code unchanged from commit 04cc85c).

---
2.4 hRound 5: FSDP Comm Overlap + Fused AdamW/EMA + Async Step Pipeline + Zero AC (`BAGEL_OPT_LLM_AC_LAYERS=0`)
- Start Time: 2026-11-19T20:53:40Z
- Profile Findings (/tmp/r5/profile/timing_profile.trace.json, steps 8..9 on Round 4):
  - Wall span 1542.95 ms/step: Compute busy dropped from 1345.2 to 1089.95 ms/step (-255.2 ms/step), causing Exposed NCCL to rise to 351.19 ms/step (22.8%) + GPU Idle 101.81 ms/step (6.6%) + AdamW + EMA multi_tensor_apply 90.4 ms/step + 46.1 ms/step exposed AllReduce_Sum_u64 + remaining 4 AC layers (~30 ms/step).
- Changes (/tmp/work_r5, /tmp/r5/switches.json):
  - TORCH_NCCL_HIGH_PRIORITY=1 + BAGEL_OPT_FSDP_PREFETCH=1: Gives NCCL streams high CUDA priority so Hopper GEMM waves do not starve ReduceScatter/AllGather, and enables FSDP forward_prefetch=True.
  - BAGEL_OPT_FUSED_ADAMW=1: Enables torch.optim.AdamW(..., fused=True), collapsing 7 foreach passes into 1 kernel and eliminating 13.6 GiB of 1.02 GiB foreach_sqrt allocations so BAGEL_OPT_LLM_AC_LAYERS=0 (0 AC across the entire model) fits comfortably in HBM.
  - BAGEL_OPT_FUSED_EMA=1: Fuses fsdp_ema_update (_foreach_mul_ + _foreach_add_) into single-pass torch._foreach_lerp_.
  - BAGEL_OPT_ASYNC_STEP=1: non_blocking=True in SimpleCustomBatch.cuda, CPU precomputation of vit_max_seqlen (removing mid-forward GPU .item() sync), single async int64 all_reduce for step token/sample counts overlapped with vae_model.encode + fsdp_model(**data), and batched post-step logging reductions.
- Results:
  - Initial LLM_AC_LAYERS=0 + FSDP_PREFETCH=1 (/tmp/r5/time/time.json): 1.7008 s/step (1.5332×) — un-stalled steps dropped to 1.2094 s, but 118.61 GiB allocated hit 134.96 GiB release_cached_blocks() without garbage_collection_threshold.
  - With LLM_AC_LAYERS=8 (/tmp/r5/time_ac8/time.json): 1.4384 s/step (windows = [1.4408, 1.4360], window_range = 0.0033, speedup_vs_frozen_reference = 1.8128×).
  - check --skip-timing (/tmp/r5/validate/check.json): INCORRECT on disp_ema only — all 12 model endpoints (ce 0.004 sigma, mse 0.004 sigma, log_grad_norm 0.24 sigma, disp_vit, disp_lm 0.11 sigma, disp_other) passed cleanly, plus Gate 2 and Gate 2b det/prod passed, while BAGEL_OPT_FUSED_EMA=1 (_foreach_lerp_) removed the tiny fp32 rounding drift present in upstream's two-step ema * float32(0.9999) + float32(1e-4) * new (disp_ema has tiny sigma_seed = 3.7e-5).
  - Fix: Disabled BAGEL_OPT_FUSED_EMA (retaining exact upstream _foreach_mul_ + _foreach_add_ for EMA) while keeping BAGEL_OPT_FUSED_ADAMW=1, BAGEL_OPT_ASYNC_STEP=1, and TORCH_NCCL_HIGH_PRIORITY=1.

---
3.5 hRound 6: Zero-Copy Merged `gate+up` SwiGLU, Merged QKV, Zero-`SliceBackward0` Splits + Verified Round 5 Stack
- Start Time: 2026-11-19T22:00:00Z
- Profile Findings (/tmp/r6/profile/timing_profile.profile.txt & trace):
  - AdamW.step dropped from 73.2 to 34.1 ms/step (-39.1 ms/step) and exposed AllReduce_Sum_u64 (46.1 ms/step) was eliminated.
  - Remaining compute overhead includes 504 separate MLP/QKV GEMMs + 168 [L, 3584] fan-out add_ kernels + 168 SliceBackward0 (FillFunctor zero-fills + copies, 19.8 ms/step on Stream 7) + 4 extra AC layers (8 -> 4 once garbage_collection_threshold:0.85 + FUSED_ADAMW reclaim cached blocks without cudaDeviceSynchronize()).
- Changes (/tmp/work_r6, /tmp/r6/switches_safe.json):
  - BAGEL_OPT_MERGED_LINEAR=1: Zero-copy FlatParameter view _merged_2_weights + merged_gate_up_swiglu (rel_y = 0.0, rel_dw = 0.0 on GPU), merged_qkv_linear in LLM & SigLIP ViT, fork_residual_split (max_diff = 0.0), split_und_gen, and extract_attn_to_und_gen (0.0 diff).
  - Combined with BAGEL_OPT_FUSED_ADAMW=1, BAGEL_OPT_ASYNC_STEP=1, TORCH_NCCL_HIGH_PRIORITY=1, BAGEL_OPT_LLM_AC_LAYERS=4, and PYTORCH_CUDA_ALLOC_CONF=garbage_collection_threshold:0.85 (with BAGEL_OPT_FUSED_EMA off).
- Results:
  - Full bench.py check (/tmp/r6/check/check.json, Gates 0 + 1 + 2 + 2b + 3): status: "PASS", tier: "N1", speedup = 1.8086× (1.4418 s/step vs 2.6076 s/step frozen reference; Window 1 1.4275 s/step = 1.8265×, Window 2 1.4561 s/step = 1.7910×)!
    - Gate 2 (record): exact_items_ok = true, problems = [].
    - Gate 2b conformance (det & prod): PASS (ratios = 1.179 / 1.014 vs 3.0).
    - Gate 3 trajectory (/tmp/r6/check/traj_report.json): PASS (equivalent, all 14 endpoints within 3 sigma_seed — ce -0.020 / -0.013 sigma, mse +0.002 / +0.022 sigma, disp_lm -0.509 / -0.387 sigma, disp_ema -0.008 / -0.351 sigma).
  - Committed & Promoted to /submission: git commit 80d0abe on branch opt, /submission/switches.json updated.

---
4.0 hRound 7: Eliminate `cudaFree` GC Stall via `BAGEL_OPT_LLM_AC_LAYERS=8` (Zero `PYTORCH_CUDA_ALLOC_CONF` Overhead)
- Start Time: 2026-11-19T22:26:30Z
- Timing Trace Finding (/tmp/r6/check/check.json):
  - Un-stalled steps in Round 6 ran at 1.245–1.390 s/step (~1.90×), but BAGEL_OPT_LLM_AC_LAYERS=4 (111.17 GiB allocated) + PYTORCH_CUDA_ALLOC_CONF=garbage_collection_threshold:0.85 still triggered synchronous cudaFree reclamation (3.3505 s on step 50, costing +33 ms/step across the run and raising window_range to 0.0199).
- Change Tested (/tmp/r7/switches.json on commit 80d0abe):
  - Set BAGEL_OPT_LLM_AC_LAYERS="8" and removed PYTORCH_CUDA_ALLOC_CONF so peak allocated drops to ~104 GiB (reserved < 134.9 GiB, zero synchronous cudaFree calls).
- Results:
  - Full bench.py check (/tmp/r7/check/check.json, Gates 0 + 1 + 2 + 2b + 3): status: "PASS", tier: "N1", speedup = 1.8422× (1.4155 s/step vs 2.6076 s/step frozen reference; windows [1.4152, 1.4158], window_range = 0.0005 = 0.05%!!)!
    - Peak allocated 104.01 GiB, reserved 134.83 GiB — zero allocator spikes across all 65 steps (min = 1.2225 s, max = 1.7093 s).
    - Gate 2 (record): exact_items_ok = true, problems = [].
    - Gate 2b conformance (det & prod): PASS.
    - Gate 3 trajectory (/tmp/r7/check/traj_report.json): PASS (equivalent, all 14 endpoints well within 3 sigma_seed, max |mean_in_sigma| = 1.55 — ce -0.027 / +0.013 sigma, mse -0.0001 / +0.010 sigma, log_grad_norm +0.98 / -1.26 sigma, disp_lm -0.67 / +0.12 sigma, disp_ema -0.010 / -0.198 sigma).
  - Promoted to /submission: /submission/switches.json updated (code at commit 80d0abe).

---
4.4 hRound 8: FSDP Forward Prefetch + 4-Inflight AllGather Rate-Limiter + Zero-Copy-Only Linear Merge
- Start Time: 2026-11-19T22:53:00Z
- Profile Findings (/tmp/r8/profile, steps 8..9 on Round 7 1.8422×):
  - Wall span 1494.2 ms/step: Compute busy 1057.1 ms/step, Exposed NCCL 322.9 ms/step, GPU Idle 114.2 ms/step.
  - cudaEventSynchronize inside FullyShardedDataParallel.rate_limiter (_max_num_inflight_all_gathers = 2) blocked the main Python thread for 848.5 ms/step (57.94% Self CPU, 117 calls/step), serializing CPU prefetching of AllGather, while forward_prefetch was off.
  - Zero-copy merged_gate_up_swiglu + fork_residual_split + extract_attn_to_und_gen eliminated FillFunctor (19.8 ms) and -32.4 ms of aten::add_, whereas non-adjacent merged_qkv_linear added 39.4 ms/step of aten::cat + .contiguous() copies.
- Changes (/tmp/work_r8, /tmp/r8/switches.json):
  - BAGEL_OPT_FSDP_PREFETCH=1 + BAGEL_OPT_FSDP_INFLIGHT=4 (BAGEL_OPT_LLM_AC_LAYERS=9 to keep peak memory neutral at ~104 GiB), overlapping forward/backward AllGather without rate_limiter CPU stalls.
  - Separated BAGEL_OPT_MERGED_QKV (off) from BAGEL_OPT_MERGED_LINEAR=1 (keeping zero-copy merged_gate_up_swiglu + fork_residual_split + extract_attn_to_und_gen).
- Results:
  - Full bench.py check (/tmp/r8/check/check.json): status: "PASS", tier: "N1", speedup = 1.8422× (1.4155 s/step, Window 1 1.4132 s/step = 1.8450×, peak_memory_allocated_gib = 102.80 GiB, reserved = 134.79 GiB).
  - Diagnosis: FSDP_PREFETCH=1 + FSDP_INFLIGHT=4 sped up short/medium steps (1.2225 -> 1.1908 s) and added only +0.6 GiB peak allocated, while disabling MERGED_QKV (+10 ms/step) and raising LLM_AC_LAYERS 8 -> 9 (+7 ms/step) offset the average gain (1.4155 s/step tie). Kept Round 7 in /submission.

---
5.1 hRound 9: Fused Residual Add-Split + Dual-Expert RMSNorm (`BAGEL_OPT_FUSED_RES_RMSNORM=1`) + Full Prefetch & Merged QKV
- Start Time: 2026-11-19T23:32:45Z
- Target (/tmp/r8/profile): _add_split_fwd_kernel (18.2 ms/step), _ForkResidualSplitFnBackward (15.5 ms/step), and separate und/gen _rms_norm_{fwd,bwd}_kernel (31.4 ms/step, ~276 launches/step + 16 GB HBM traffic).
- Changes (/tmp/work_r9, /tmp/r9/switches.json):
  - BAGEL_OPT_FUSED_RES_RMSNORM=1: Fuses fork_residual_split + dual und/gen RMSNorm at sublayer 1 (fused_fork_dual_rmsnorm) and add_split + fork_residual_split + dual und/gen RMSNorm at sublayer 2 (fused_add_split_dual_rmsnorm), including fused residual-add + dual deterministic 2-stage backward (_dual_rmsnorm_res_bwd_kernel). Verified 100% bitwise identical (torch.equal == True on all outputs & gradients) to Round 7 on GPU across n_und = 0, 317, 1024.
  - Combined with BAGEL_OPT_FSDP_PREFETCH=1, BAGEL_OPT_FSDP_INFLIGHT=4, BAGEL_OPT_MERGED_QKV=1, and BAGEL_OPT_LLM_AC_LAYERS=7.
- Results:
  - time (/tmp/r9/time/time.json): 1.3957 s/step (windows = [1.3870, 1.4044], peak_memory_allocated_gib = 105.81 GiB, reserved = 134.71 GiB, speedup_vs_frozen_reference = 1.8683×)!
  - check --skip-timing (/tmp/r9/validate/check.json): status: "PASS", tier: "N1"!
    - Gate 2 (record): exact_items_ok = true, problems = [].
    - Gate 2b conformance (det & prod): PASS.
    - Gate 3 trajectory (/tmp/r9/validate/traj_report.json): PASS (equivalent, all 14 endpoints well within 3 sigma_seed, max |mean_in_sigma| = 1.44 — ce -0.015 / +0.012 sigma, mse -0.005 / -0.0015 sigma, disp_lm -0.136 / +0.066 sigma, disp_ema +0.015 / -0.087 sigma).
  - Committed & Promoted to /submission: git commit ae39df3 on branch opt, /submission/switches.json updated.

---
5.6 hRound 10: Mega-Fused QKV Projection + Dual-Expert QK-RMSNorm + NeoX RoPE + Unpermute + Flex Pad (`BAGEL_OPT_FUSED_QKV_NORM_ROPE=1`)
- Start Time: 2026-11-20T00:02:10Z
- Target: Eliminate merged_qkv_linear's 216 .contiguous() split copies + 56 torch.cat([dq, dk, dv]) copies, 368 separate q_norm/k_norm forward/backward kernel launches (including 875-iteration serial backward loops on 224k Q/K heads), _prep_qkv_flex_{fwd,bwd}_kernel, and ~2 GiB of saved QK-norm intermediates (allowing BAGEL_OPT_LLM_AC_LAYERS=6).
- Changes (/tmp/work_r10, /tmp/r10/switches.json):
  - BAGEL_OPT_FUSED_QKV_NORM_ROPE=1: Single forward/backward Triton pipeline _qkv_norm_rope_pad_{fwd,bwd}_kernel operating directly on contiguous [M, 4608] QKV outputs/gradients with 2-stage deterministic dw reduction (rel_q = 3.2e-6, rel_dhu = 7.3e-5 on GPU under torch.use_deterministic_algorithms(True)).
  - Set BAGEL_OPT_LLM_AC_LAYERS="6".
- Results:
  - time (/tmp/r10/time/time.json): 1.3911 s/step (windows = [1.3823, 1.3999], peak_memory_allocated_gib = 107.81 GiB, reserved = 134.87 GiB, speedup_vs_frozen_reference = 1.8745×)!
  - check --skip-timing (/tmp/r10/validate/check.json): status: "PASS", tier: "N1"!
    - Gate 2 (record): exact_items_ok = true, problems = [].
    - Gate 2b conformance (det & prod): PASS.
    - Gate 3 trajectory (/tmp/r10/validate/traj_report.json): PASS (equivalent, all 14 endpoints within 3 sigma_seed — ce -0.049 / +0.024 sigma, mse -0.005 / +0.015 sigma, log_grad_norm -0.109 / -0.149 sigma, disp_lm -0.110 / -0.426 sigma, disp_ema +0.022 / -0.225 sigma).
  - Committed & Promoted to /submission: git commit d9944de on branch opt, /submission/switches.json updated.

---
6.0 hRound 11: Full Zero-Saved-SwiGLU MLP (`BAGEL_OPT_MERGED_MLP_FULL=1`) Unlocking `BAGEL_OPT_LLM_AC_LAYERS=0` + Bitwise-Exact PTX Fused EMA (`BAGEL_OPT_BITWISE_FUSED_EMA=1`)
- Start Time: 2026-11-20T00:30:40Z
- Target:
  - self.down_proj(merged_gate_up_swiglu(...)) saved [L, 18944] swiglu_out (436.5 MB/layer = 11.4 GiB across 28 layers), forcing BAGEL_OPT_LLM_AC_LAYERS=6 (6 layers still recomputed every step).
  - fsdp_ema_update ran two multi_tensor_apply passes over 13.6 GiB fp32 shards (54.4 GiB HBM traffic, 19.6 ms/step).
- Changes (/tmp/work_r11, /tmp/r11/switches.json):
  - BAGEL_OPT_MERGED_MLP_FULL=1: Fuses gate_proj + up_proj + SwiGLU + down_proj into merged_mlp_swiglu, reconstructing y_rec = silu(gate) * up inside _swiglu_merged_bwd_recomp_kernel at zero extra read cost (torch.equal == True 100% bitwise identical on GPU, freeing 11.4 GiB), enabling BAGEL_OPT_LLM_AC_LAYERS="0" (zero activation checkpointing across the entire 14.6B model)!
  - BAGEL_OPT_BITWISE_FUSED_EMA=1: Inline-PTX bitwise_fused_ema_update (mul.rn.f32 + fma.rn.f32), verified torch.equal == True on 11.1M floats vs upstream two-step EMA while halving HBM traffic.
- Status & Verification:
  - Gate 1 (time): /tmp/r11/time/time.json -> 1.3105 s/step (1.9898× speedup vs frozen reference 2.6076 s/step, Window 1 1.3052 s/step = 1.9979×, Window 2 1.3157 s/step, window_range = 0.008, peak_memory_allocated_gib = 107.54, peak_memory_reserved_gib = 134.88).
  - Gates 0, 2, 2b & 3 (check --skip-timing): /tmp/r11/validate/check.json -> PASS (tier N1):
    - Gate 2 (record): exact_items_ok: true, problems: [].
    - Gate 2b (conformance): PASS (ratio n = 1.123, j = 1.016; prod n = 1.066, j = 0.983, bound 3.0).
    - Gate 3 (traj_report.json): PASS (equivalent, all 14 endpoints within 3 sigma_seed — ce -0.009 / -0.010 sigma, mse +0.009 / +0.010 sigma, log_grad_norm +0.478 / +0.716 sigma, disp_lm -0.686 / +0.301 sigma, disp_ema -0.032 / -0.262 sigma).
  - Committed & Promoted to /submission: git commit 6f1291c on branch opt, /submission/switches.json updated.

---
6.6 hRound 12: FSDP Fast Post-Backward Reduce Hook (`BAGEL_OPT_FSDP_FAST_REDUCE=1`) + Chunked In-Place BF16 Cross-Entropy (`BAGEL_OPT_CHUNKED_CE=1`) + Fused SigLIP 2D RoPE (`BAGEL_OPT_FUSED_SIGLIP_ROPE=1`)
- Start Time: 2026-11-20T01:01:45Z
- Target:
  1. PyTorch FSDP HYBRID_SHARD (num_replicate=1, num_shard=4) ran padded_unsharded_grad.div_(2.0) (58.4 GB HBM traffic on _post_backward_stream delaying every reduce_scatter), launched 58 size-1 dist.all_reduce calls on _inter_node_pg, and ran new_sharded_grad.div_(2.0) + new_sharded_grad.to(fp32) as separate passes (36.5 GB HBM traffic on priority-0 _all_reduce_stream).
  2. F.cross_entropy(packed_ce_preds, ...) materialized [N_ce, 152064] log_softmax (~3 GiB) + grad_logits (~3 GiB) right at the forward/backward turnaround (peak_memory_reserved_gib = 134.88 GiB, close to 134.96 GiB).
  3. SiglipFlashAttention2 (26 layers) launched 22 forward + 26 backward small elementwise/cat/SliceBackward kernels per layer (~1,248 kernels/step) for 2D RoPE.
- Changes (/tmp/work_r12, /tmp/r12/switches.json):
  - BAGEL_OPT_FSDP_FAST_REDUCE=1: Uses FULL_SHARD when num_replicate == 1 + official FSDP.register_comm_hook skipping unsharded predivide (-58.4 GB), fusing post-reduce scale + bf16->fp32 cast (-14.6 GB), and keeping CUDA stream priority=-1.
  - BAGEL_OPT_CHUNKED_CE=1: Row-chunked (1024 rows) F.cross_entropy with in-place gradient writeback into packed_ce_preds (~5–6 GiB peak HBM saved, zero GEMM recompute, bitwise exact).
  - BAGEL_OPT_FUSED_SIGLIP_ROPE=1: Single-launch Triton 2D RoPE forward & backward across all 26 SigLIP layers (bitwise exact).
- Status & Verification:
  - Single-GPU & 4-GPU unit checks: fused_bf16_scale_to_fp32, chunked_inplace_cross_entropy, fused_siglip_2d_rope, and 4-GPU FSDP_FAST_REDUCE all verified torch.equal == True (100% bitwise exact).
  - Gate 1 (time): /tmp/r12/time/time.json -> 1.2615 s/step (2.0671× speedup vs frozen reference 2.6076 s/step, Window 1 1.2644 s/step, Window 2 1.2586 s/step, window_range = 0.0046, peak_memory_allocated_gib = 107.54, peak_memory_reserved_gib = 136.76 — FULL_SHARD also freed ~2 GiB of second-PG NCCL memory).
  - Gates 0, 2, 2b & 3 (check --skip-timing): /tmp/r12/validate/check.json -> PASS (tier N1):
    - Gate 2 (record): exact_items_ok: true, problems: [].
    - Gate 2b (conformance): PASS (ratio n = 1.117, j = 1.020; prod n = 1.117, j = 1.044, bound 3.0).
    - Gate 3 (traj_report.json): PASS (equivalent, all 14 endpoints within 3 sigma_seed — ce -0.016 / +0.017 sigma, mse +0.002 / +0.011 sigma, log_grad_norm -0.239 / -1.105 sigma, disp_lm -0.264 / -0.196 sigma, disp_ema -0.013 / -0.229 sigma).
  - Committed & Promoted to /submission: git commit caac452 on branch opt, /submission/switches.json updated.

---
7.1 hRound 13: Unlimit Small SigLIP FSDP Handles (`BAGEL_OPT_FSDP_UNLIMIT_SMALL=1`) + Root Prefetch Before VAE (`BAGEL_OPT_FSDP_PREFETCH_ROOT=1`) + Clean VAE Encoder Memory (`BAGEL_OPT_VAE_CLEAN_MEM=1`)
- Start Time: 2026-11-20T01:36:35Z
- Profile Analysis (/tmp/r13/profile on caac452):
  1. FSDP.rate_limiter (cudaEventSynchronize) blocked the CPU for 21.61 ms ([2492.3..2513.9 ms]) at the end of LLM backward (INFLIGHT=4), causing twenty-six 1.18 ms GPU idle gaps (30.7 ms total) across the 26 32 MB SiglipEncoderLayer backward layers.
  2. vae_model.encode(padded_images) ran before Root Bagel AllGather, leaving a 17.21 ms GPU idle gap ([1448.8..1466.0 ms]) right after VAE encode.
  3. Microbenchmarks screened out FAST_FLEX_MASK (4.36 -> 4.40 ms/layer, L2 already cached active allow_2d diagonal band), VAE_SWISH fp32->bf16 (rel_l2 = 1.26e-2), and side-stream ASYNC_VAE + INFLIGHT=6 (/tmp/r13/time: 1.4485 s/step, hit 137.03 GiB due to separate vae_stream allocator pool).
- Changes & Verification (/tmp/work_r13, /tmp/r13c/switches.json):
  - BAGEL_OPT_FSDP_UNLIMIT_SMALL=1: Sets s.limit_all_gathers = False on FSDP handles < 32M shard elements (SigLIP layers & connectors, < 900 MB total, fitting inside _unshard_stream's existing 3.8 GB cached pool).
  - BAGEL_OPT_VAE_CLEAN_MEM=1: Drops dead hs intermediate feature-map list in Encoder.forward (-511 MiB, torch.equal == True).
  - BAGEL_OPT_FSDP_PREFETCH_ROOT=1: Launches Root Bagel AllGather on FSDP's existing _unshard_stream right before vae_model.encode (0 new streams, 6 root unshards over 3 steps, torch.equal == True).
  - Isolated timing (/tmp/r13b/time/time.json, UNLIMIT_SMALL=1 + VAE_CLEAN_MEM=1): 1.2442 s/step (2.0958×, window_range = 0.0021).
  - Combined timing (/tmp/r13c/time/time.json, + FSDP_PREFETCH_ROOT=1): 1.2387 s/step (2.1051×, Window 1 1.2406, Window 2 1.2367, window_range = 0.0031).
  - Full bench.py check (/tmp/r13c/check/check.json): PASS (tier N1, speedup = 2.0763× — Window 2 1.2376 s/step = 2.1072×, Window 1 had a single +1.0s allocator stall on step 9 at 136.96 GiB reserved; Gate 2 exact_items_ok: true, Gate 2b ratio n = 1.117 / j = 1.020, Gate 3 all 14 endpoints within 3 sigma_seed with ce -0.048 / +0.027 sigma, disp_ema +0.035 / -0.100 sigma).
  - Committed & Promoted to /submission: git commit e3c85c4 on branch opt, /submission/switches.json updated.

---
8.2 hRound 14: Fused SigLIP BF16 LayerNorm + ResAdd-LN + Recomp MLP (`BAGEL_OPT_FUSED_SIGLIP=1`), Bitwise-Exact Inline-PTX VAE Swish + BF16 Conv (`BAGEL_OPT_VAE_EXACT_SWISH=1`), and Fixed-Capacity LLM & CE Buffers (`BAGEL_OPT_ALLOC_SEQ_CAP=11520`, `BAGEL_OPT_CHUNKED_LM_HEAD_CE=4096`)
- Start Time: 2026-11-20T02:42:00Z
- Root-Cause & Microbenchmark Analysis:
  1. Diagnosed CUDACachingAllocator fragmentation (33.18 GiB un-reusable segments between 103.84 GiB allocated and 137.02 GiB reserved): dynamic [n_und, D] + [n_gen, D] split allocations and step-to-step seq_len growth (9547 -> 10171 -> 10228) stranded 28-layer gu (~735 MiB each) segments across steps 0..9. Unifying [und; gen] storage views (.set_(gu_buf.untyped_storage(), ...) with independent TensorImpl version counters) at BAGEL_OPT_ALLOC_SEQ_CAP=11520 + BAGEL_OPT_CHUNKED_LM_HEAD_CE=4096 eliminated 100% of LLM/CE segment growth and release_cached_blocks() stalls across both time (window_range = 0.0069) and check (window_range = 0.0043).
  2. Isolated microbenchmarks screened out slower candidates (BAGEL_OPT_FUSED_EXTRACT_OPROJ=1: 39.61 -> 46.19 ms/step; BAGEL_OPT_DUAL_MLP_RES_ADD=1: 565.2 -> 595.9 ms/step; BAGEL_OPT_PREWARM_ALLOC=1: starved _unshard_stream on step 9) and selected the proven winners:
     - BAGEL_OPT_FUSED_SIGLIP=1: Fused deterministic Triton BF16 LayerNorm, ResAdd+LayerNorm, and zero-saved-GELU MLP across all 26 SiglipEncoderLayers + post_layernorm + MLPconnector (54.75 -> 47.54 ms/step, -7.21 ms/step + -0.7 GiB HBM, MLPconnector 0.00e+00 diff).
     - BAGEL_OPT_VAE_EXACT_SWISH=1: Inline-PTX IEEE-754 add.rn.f32 / div.rn.f32 / mul.rn.f32 fp32 -> bf16 fused swish + pre-casting frozen vae_model.encoder nn.Conv2d weights/biases to bfloat16 (36.75 -> 30.56 ms/step, -6.19 ms/step + -536 MB peak VAE HBM, torch.equal == True 100% bitwise identical).
- Verification:
  - Standalone bench.py time (/tmp/r14c/time/time.json): 1.2164 s/step (2.1437× vs frozen reference 2.6076 s/step, Window 1 1.2206, Window 2 1.2122, window_range = 0.0069, peak_memory_reserved_gib = 136.32).
  - Full bench.py check (/tmp/r14c/check/check.json): PASS (tier N1, speedup = 2.1448×, 1.2158 s/step, windows [1.2184, 1.2132], window_range = 0.0043; Gate 2 exact_items_ok: true, problems: []; Gate 2b PASS ratio n = 1.630 / j = 1.027; Gate 3 PASS all 14 endpoints within 3 sigma_seed — ce +0.023 / +0.014 sigma, mse -0.004 / -0.006 sigma, disp_lm +0.179 / +0.052 sigma, disp_ema +0.022 / +0.053 sigma).
  - Committed & Promoted to /submission: git commit c8f8935 on branch opt, /submission/switches.json updated.

---
9.7 hRound 15: Profile `c8f8935` (`1.2158 s/step`) & Target Remaining Compute / Kernel-Launch Bottlenecks
- Start Time: 2026-11-20T04:12:30Z
- Status: Running bench.py profile on c8f8935 while /submission remains cleanly banked at c8f8935 (PASS full check 2.1448×).

---
↑ BAGEL SFT