Gemini 4 Carbon 1.97×

Harness: Antigravity · switches: PYTORCH_ALLOC_CONF=expandable_segments:True BAGEL_OPT_SYNC_FREE_DECODE=1 BAGEL_OPT_DECODE_CUDAGRAPH=1 BAGEL_OPT_FAST_DECODE_LOOP=1 BAGEL_OPT_FAST_FLOW=1 BAGEL_OPT_BATCH_CFG_FLOW=gen BAGEL_OPT_FAST_SINGLE_FLOW=1 BAGEL_OPT_DEDUP_ROLLOUT_CTX=1 BAGEL_OPT_DEDUP_ROLLOUT_IMG=1 BAGEL_OPT_DEDUP_TRAIN_VISION=1 BAGEL_OPT_NO_EMPTY_CACHE=1 BAGEL_OPT_SHARE_REF_PRECOMP=1 BAGEL_OPT_DECOUPLE_MOT=1 BAGEL_OPT_DIRECT_TRAIN_SPLIT=1 BAGEL_OPT_OVERLAP_REWARD=1 BAGEL_OPT_OVERLAP_REF_FWD=1 BAGEL_OPT_FAST_STEP_SYNC=1 BAGEL_OPT_FUSED_RMSNORM=1 BAGEL_OPT_FUSED_ADD_RMSNORM=1 BAGEL_OPT_FUSED_DUAL_LOGPS=1 BAGEL_OPT_FUSED_ROPE=1 BAGEL_OPT_FUSED_QKNORM_ROPE=1 BAGEL_OPT_FUSED_TRAIN_QKV=1 BAGEL_OPT_FUSED_SWIGLU=1 BAGEL_OPT_FLOW_CUDAGRAPH=1 BAGEL_OPT_FAST_PACK=1 BAGEL_OPT_BF16_REF_SHARDS=1 BAGEL_OPT_RESHARD_REF=0 BAGEL_OPT_SELECTIVE_AC=0 BAGEL_OPT_MLP_AC=2

Judged
1.97×
Tier
N0
Self-best
2.09×
Rounds
11
Hours
10.0
API cost
$105
Input tokens · 94.0% cached
198 M
Output tokens
1.0 M
Requests
688
Text-decode CUDA graph
✓ BAGEL_OPT_DECODE_CUDAGRAPH + SYNC_FREE_DECODE, round 1 together with denoise desync and context dedup, single-run timing 1.44×; round 10 FAST_DECODE_LOOP moves sampling prep into the graph and pipelines the D2H by one step
Reward wait hidden behind forward
partial: round 2 OVERLAP_REWARD only moves CPU-side packing and image transforms into the wait; round 7 OVERLAP_REF_FWD moves the reference forward earlier: the version before the reward wait OOMed at step 6, the final version runs after the local reward returns and before the cross-rank sync (with the round's other changes, single-run timing 1.91× → 1.95×); policy forward not moved
Rollout-side bitwise fused kernels
✓ custom CUDA extension: round 3 RMSNorm, RoPE, SwiGLU fwd/bwd (shared by rollout and training), single-run timing 1.55× → 1.80× (full check 1.80×); round 5 q/k norm + RoPE + V scatter in one kernel (16 launches per denoise layer → 1); round 9 residual add + RMSNorm
Train-side bitwise kernels / freeing memory
✓ round 8 train-side q/k norm + RoPE + scatter + transpose and attention-output split fwd/bwd kernels, single-run timing 1.95× → 1.98× (full check 1.96×); round 10 fused dual log_softmax, reference shards cast to bf16 (14.6 → 7.3 GiB), full-check peak 124.59 GiB; resharding the reference after forward (round 4) added ~475 ms of AllGather per step, reverted in round 5
Other main levers
packing desync (40960 .item() per window) + denoise CUDA graph (round 4, kept in the submission); MoT streams split, block mask / ViT shared between reference and policy (round 2); refine image context B=1 broadcast (round 5); CFG batching only on generation steps (3-branch batching together with MLP_AC=4 made refine steps 120–540 ms slower); round 11 custom block-mask kernel not in the submission
Raw work log11 sections
0.0 hRound 1 — Rollout Host-Sync Removal, Decode CUDA Graph, Pre-merged Flow KV, & Context Deduplication
- Start time: 2026-11-19T19:36:01Z
- End time: 2026-11-19T20:35:06Z
- Baseline Profile (/tmp/r1_profile/profile.json, /tmp/r1_profile/timing_profile.profile.txt, steps 11–12, span 54.384s):
  - GPU busy 26.374s (48.5%); GPU idle 51.5%.
  - Top hotspots: aten::mm (11.488s CUDA, 41.94%), aten::mul (2.728s CUDA, 9.96%), aten::_index_put_impl_ (1.682s CUDA, 6.14%), aten::copy_ (1.324s CUDA, 4.83%), aten::addmm (1.187s CUDA, 4.33%), aten::_local_scalar_dense (9.233s CPU / 21.42%, 244,157 calls), aten::nonzero (1.452s CPU, 19,314 calls).
- Changes (committed in 27bde66 on opt):
  - Enabled BAGEL_OPT_SYNC_FREE_DECODE=1, BAGEL_OPT_DECODE_CUDAGRAPH=1, BAGEL_OPT_FAST_FLOW=1, BAGEL_OPT_DEDUP_ROLLOUT_CTX=1.
- time result (/tmp/r1_time/time.json):
  - window_s_per_step: [15.543, 16.4004, 16.9122] s/step
  - s_per_step: 16.2852 s (vs 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.4421 (mean window ratio 1.4432, peak allocated memory 130.76 GiB)
- check --quick result (/tmp/r1_quick/check.json):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical.

---
1.0 hRound 2 — MoT Stream Decoupling, Shared Ref/Policy Precomputation, Allocator Stall Removal, & Reward Overlap
- Start time: 2026-11-19T20:35:47Z
- End time: 2026-11-19T21:39:58Z
- Profile (/tmp/r2_profile/profile.json, /tmp/r2_profile/timing_profile.profile.txt, steps 11–12, span 32.314s, rank0 steps [21.748s, 10.655s]):
  - GPU busy 26.754s (82.8%); non-NCCL GPU compute 24.570s (76.0%); GPU idle 5.560s (17.2%: reward HTTP wait + empty_cache() / caching-allocator alloc_retry stalls 447ms).
  - Top non-GEMM / structural hotspots:
    - MoT redundant scatter/gather/zero/cast in Qwen2MoTDecoderLayer & PackedAttentionMoT: aten::_index_put_impl_ (1.605s CUDA, 5.74%, 41,505 calls), aten::index (0.419s CUDA, 32,416 calls), aten::copy_ (1.052s CUDA, 3.77%, 46,118 calls), aten::fill_ (0.191s CUDA, 15,824 calls).
    - Elementwise/norm/RoPE/SwiGLU ops: aten::mul (2.348s CUDA, 8.40%), aten::mean/reduce_kernel (0.482s), aten::pow (0.387s), aten::cat (0.329s), aten::add (0.328s), aten::silu (0.287s).
    - Duplicate create_block_mask (114ms) and duplicate frozen vit_model 26-layer forward (15,552 tokens in Refine) across ref_model and fsdp_model.
- Changes (committed in f67c41f on opt):
  - PYTORCH_ALLOC_CONF=expandable_segments:True + BAGEL_OPT_NO_EMPTY_CACHE=1 (eliminating empty_cache() syncs and caching-allocator alloc_retry stalls, plus early release of dead ref_loss_dict/output_dict saving 1.90 GiB peak VRAM).
  - BAGEL_OPT_SHARE_REF_PRECOMP=1 (single shared BlockMask and cloned frozen vit_model raw embeddings across ref_model and fsdp_model, plus single-H2D create_sparse_mask).
  - BAGEL_OPT_DECOUPLE_MOT=1 (decoupled (und/text, gen/vae) streams across all 28 Qwen2MoTDecoderLayers in both rollout mode='gen' and training forward_train + _ScatterDisjoint2/_GatherDisjoint2 + direct PreparedStaticReadonlyKV destination writes).
  - BAGEL_OPT_OVERLAP_REWARD=1 (overlapping CPU prepack + PIL vae_transform/vit_transform prewarming with async GenEval HTTP reward futures).
- time result (/tmp/r2_time/time.json):
  - window_s_per_step: [14.4775, 15.8001, 15.2011] s/step
  - s_per_step: 15.1596 s (vs 16.2852 s Round 1 and 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.5491 (peak allocated memory reduced 130.76 GiB → 128.86 GiB)
- check --quick result (/tmp/r2_quick/check.json):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical.

---
2.1 hRound 3 — Bitwise-Exact (`Tier N0`) Custom Fused CUDA Kernels (`Qwen2RMSNorm`, `RoPE`, `SwiGLU`)
- Start time: 2026-11-19T21:40:25Z
- End time: 2026-11-19T22:25:31Z
- Profile (/tmp/r3_profile/profile.json, /tmp/r3_profile/timing_profile.profile.txt, steps 11–12, Self CPU 27.266s, Self CUDA 25.371s):
  - aten::_index_put_impl_ eliminated from top 50 (1.605s CUDA → aten::index_copy_ 0.282s CUDA).
  - Top remaining non-GEMM / non-Attention hotspots are all memory-bound elementwise/reduction ops in Qwen2RMSNorm, RoPE, and SwiGLU:
    - aten::mul: 2.434s CUDA (9.60%), 3.361s CPU (12.33%), 78,949 calls.
    - aten::copy_: 1.103s CUDA (4.35%), 5.387s CPU (19.76%), 55,315 calls (.to(fp32)/.to(bf16) casts in Qwen2RMSNorm & RoPE).
    - aten::mean / reduce_kernel: 0.354s / 0.482s CUDA, 22,862 calls (Qwen2RMSNorm variance).
    - aten::add: 0.345s CUDA, 46,369 calls.
    - aten::pow: 0.337s CUDA, 1.654s CPU, 23,772 calls (Qwen2RMSNorm .pow(2)).
    - aten::silu: 0.296s CUDA, 5,698 calls (Qwen2MLP SwiGLU).
    - aten::cat: 0.250s CUDA, 11,519 calls (rotate_half in RoPE).
- Changes (committed in 867a069 on opt, bagel_fast_ops installed in /opt/candidate-env):
  - BAGEL_OPT_FUSED_RMSNORM=1: 0-ULP pre-compiled CUDA C++ Qwen2RMSNorm fwd+bwd (D=128 and D=3584, reproducing Reduce.cuh reduction tree and exact CUDA MeanOps / BinaryMulDiv reciprocal factors).
  - BAGEL_OPT_FUSED_ROPE=1: 0-ULP pre-compiled CUDA C++ fused (q, k) RoPE fwd+bwd (including fused fp32 -> bf16 output cast in rollout mode='gen').
  - BAGEL_OPT_FUSED_SWIGLU=1: 0-ULP pre-compiled CUDA C++ vectorized uint4 (bf16x8) fused F.silu(gate) * up fwd+bwd (exhaustively verified across all 65,024 finite bfloat16 bit patterns; saves 1.5 GiB per active layer in backward).
- time result (/tmp/r3_time/time.json):
  - window_s_per_step: [12.6256, 13.2056, 13.239] s/step
  - s_per_step: 13.0234 s (vs 15.1596 s Round 2 and 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.8032 (peak allocated memory reduced 128.86 GiB → 126.71 GiB)
- check --quick result (/tmp/r3_quick/check.json):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical.
- Full check result (/tmp/r3_full_check/check.json):
  - status: PASS, speedup: 1.8007 (window ratios [1.8968, 1.6644, 1.841]), bitwise: true, measured_tier: "N0".

---
3.3 hRound 4 — Sync-Free `pack_batch`, Flow Denoising CUDA Graph, `ref_model` Resharding, & Tail Selective AC
- Start time: 2026-11-19T22:50:04Z
- Profile (/tmp/r4_profile/profile.json, /tmp/r4_profile/timing_profile.profile.txt, steps 11–12, Self CPU 23.612s, Self CUDA 22.382s):
  - Round 3 custom kernels eliminated aten::mul/aten::copy_/aten::mean/aten::pow/aten::silu/aten::cat from top CUDA hotspots (Self CUDA dropped 25.371s → 22.382s).
  - Top remaining bottlenecks exposed in /tmp/r4_profile:
    - aten::mm + aten::addmm: 10.246s + 0.891s CUDA (49.76% of CUDA compute; includes full-28-layer activation-checkpointing recompute in fsdp_model backward).
    - Command Buffer Full (8.008s CPU / 33.91%) + cudaLaunchKernel (4.447s CPU total / 18.83%, 140,238 launches — heavily driven by ~50,000 tiny M=8 text-stream and M=4096 flow denoising launches per window).
    - aten::_local_scalar_dense (3.341s CPU total / 14.15%, 41,785 calls) + Memcpy DtoH (41,846 calls): 40,960 synchronous .item() D2H copies inside pack_batch when calling torch.tensor([cuda_scalar] * 1024) on packed_timesteps and dts!
- End time: 2026-11-19T23:27:44Z
- Changes (committed in 3d92e8f on opt):
  - BAGEL_OPT_FAST_PACK=1: converts scalar timestep and dt tensors to Python float once in prepack/add_latent and caches latent_position_ids, eliminating 40,960 .item() D2H syncs per 2-step window.
  - BAGEL_OPT_FLOW_CUDAGRAPH=1: captures (use_cfg=True, use_cfg=False) _forward_flow passes in generate_image and generate_image_mix into shared-pool torch.cuda.CUDAGraphs (freed on exit).
  - BAGEL_OPT_RESHARD_REF=1 + BAGEL_OPT_SELECTIVE_AC=4: sets reshard_after_forward=True on ref_model (freeing ~28.4 GiB VRAM after ref_model forward) and skips CheckpointWrapper on the trailing 4 Qwen2MoTDecoderLayers (layers 24..27, whose activations free immediately at the start of backward before layers 0..23 recompute).
- time result (/tmp/r4_time/time.json):
  - window_s_per_step: [12.0669, 13.2304, 12.8785] s/step
  - s_per_step: 12.7253 s (vs 13.0234 s Round 3 and 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.8455 (mean window ratio 1.8472, peak allocated memory reduced 126.71 GiB → 119.62 GiB)
- check --quick result (/tmp/r4_quick/check.json):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, peak allocated memory 119.32 GiB.

---
4.0 hRound 5 — Refine Image-Context `B=1` Broadcast + ViT Embed Reuse, Fused `QKNorm+RoPE+Scatter` Kernel, Zero-`h_saved` RMSNorm, & Hybrid MLP-Only AC
- Start time: 2026-11-19T23:36:59Z
- Pre-profile 0-ULP GPU verification (test_b1_vs_b4.py, test_28l_b1_b4.py):
  - Verified 0 differing bytes (det_mode=False & det_mode=True) across all 28 Qwen2MoT layers for vae_model.encode (B=1 vs B=4), SiglipVisionModel + connector (B=1 vs B=4), forward_cache_update_vae + forward_cache_update_vit (B=1 broadcast to 0..3 vs B=4), and system_prompt(B=4) + forward_cache_update_vit(B=1 -> 0..3).
  - Verified text_45 (B=1 vs B=4) is NOT 0-ULP (M=45 vs M=180 changes cuBLAS small-M kernel), so text context updates stay at B=4.
- Profile (/tmp/r5_profile/profile.json, /tmp/r5_profile/timing_profile.profile.txt, steps 11–12, Self CPU 23.340s, Self CUDA 21.572s):
  - aten::_local_scalar_dense (3.341s CPU) and cudaLaunchKernel (4.447s CPU) completely vanished from top 60 (FAST_PACK=1 and FLOW_CUDAGRAPH=1 verified).
  - Exposed PCIe AllGather cost of BAGEL_OPT_RESHARD_REF=1: ncclDevKernel_AllGather_RING_LL rose 444ms → 1,292ms (+848ms / 2 steps = +424ms/step) plus _foreach_copy_ (99ms) & split_with_sizes_copy (92ms), costing ~475ms/step on PCIe GPUs (more than SELECTIVE_AC=4 saved!). Reverting RESHARD_REF=0 recovers +475ms/step, while zero-h_saved RMSNorm + BAGEL_OPT_MLP_AC=2 still skips Attention recompute within safe ~128.9 GiB VRAM.
  - Remaining non-GEMM CUDA kernels in flow/decode: index_copy_ (300ms), copy_ .to(fp32) (201ms), rmsnorm_fwd<float> (136ms), rope_qk_fwd<float> (132ms), rmsnorm_fwd<bf16,128> (99ms), rope_qk_fwd<bf16> (88ms) = 956ms CUDA (~0.48s/step), targeted by BAGEL_OPT_FUSED_QKNORM_ROPE=1.
  - Refine rollout redundant [img]*4 vae_model.encode, 2x4 -> 1 vit_model, and 4 -> 1 28-layer VAE+ViT KV prefill targeted by BAGEL_OPT_DEDUP_ROLLOUT_IMG=1.
- End time: 2026-11-20T00:20:42Z
- Changes (committed in c980ed4 on opt):
  - BAGEL_OPT_FUSED_QKNORM_ROPE=1: 1-warp-per-head sm_90 CUDA kernels gen_qknorm_rope_v_scatter_2stream_warp_kernel (16 launches → 1 launch per layer in mode='gen', eliminating .to(fp32) copies + index_copy_ scatters) and und_qknorm_rope_bf16_warp_kernel (3 launches → 1 launch per layer in mode='und').
  - BAGEL_OPT_DEDUP_ROLLOUT_IMG=1: B=1 → B=4 KV-cache broadcast for identical input_imgs in update_context_image + cross-call packed_vit_token_embed reuse between get_edit_think_and_operation and edit_image.
  - Zero-h_saved Qwen2RMSNorm (rmsnorm_fwd + single-pass (dx, dy_h) rmsnorm_bwd) + cached GPU TimestepEmbedder frequencies (_TIMESTEP_FREQS_CACHE).
  - BAGEL_OPT_RESHARD_REF=0 + BAGEL_OPT_SELECTIVE_AC=0 + BAGEL_OPT_MLP_AC=2: eliminates 475ms/step PCIe ref_model AllGather while skipping Attention recompute on 2 trailing layers.
- time result (/tmp/r5_time/time.json):
  - window_s_per_step: [11.5078, 12.977, 12.4847] s/step (Window 1 reaches 2.0014x!)
  - s_per_step: 12.3232 s (vs 12.7253 s Round 4 and 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.9057 (mean window ratio 1.9091, peak allocated memory 126.72 GiB, reserved 133.71 GiB)
- check --quick result (/tmp/r5_quick/check.json):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, peak allocated memory 126.72 GiB.
- Full check result (/tmp/r5_full_check/check.json, finished 2026-11-20T01:22:34Z):
  - status: PASS, speedup: 1.8995 (window_s_per_step = [11.597, 13.0401, 12.5156], window_ratios = [1.986, 1.8267, 1.8857]), bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, 474/474 inputs verified, peak allocated memory 126.72 GiB.

---
4.9 hRound 6 — Multi-Branch Batched CFG Flow (`2/3` Passes → `1` Pass), Training ViT `12 -> 1` Deduplication, & `MLP_AC=4`
- Start time: 2026-11-20T00:27:48Z
- Pre-profile 0-ULP GPU verification (test_r6_ideas.py, test_r6_bitwise.py):
  - Verified 0 differing bytes (det_mode=False & det_mode=True) for BAGEL_OPT_BATCH_CFG_FLOW=1 (PreparedMultiBranchFlowState + forward_inference_flow_multi_cfg, collapsing 2-way Generate CFG and 3-way Refine CFG flow passes into 1 batched 28-layer pass while preserving M=N_text_1 on x_text projections) across both bs=2 (eval) and bs=4 (train SDE).
  - Verified 0 differing bytes for BAGEL_OPT_DEDUP_TRAIN_VISION=1 (uniform_vit_repeats: 12 -> 1 SiglipVisionModel forward + 12 -> 1 packed_vit_tokens H2D copy in Refine training).
- Profile (/tmp/r6_profile/profile.json, /tmp/r6_profile/timing_profile.profile.txt, steps 11–12, Self CPU 22.642s, Self CUDA 20.548s):
  - Self CUDA dropped 21.572s → 20.548s (-1.024s): gen_qknorm_rope_v_scatter replaced 769ms (rmsnorm_fwd<float> + rope_qk_fwd<float> + .to(fp32) + index_copy_ 15,194 → 1,358 calls) with 108.7ms (7.1x kernel speedup).
  - Top remaining GPU hotspots are multi-branch CFG flow GEMMs/Attention/scatter (nvjet_tst_256x128 4.12s, nvjet_tst_320x128 2.25s, flash_fwd_kernel 1.07s / 2,296 calls, gen_qknorm_rope_v_scatter 109ms / 2,324 calls, out_seq.index_copy_ 99ms), 12x redundant SiglipVisionModel in Refine ref_model training, and AC recompute (BAGEL_OPT_MLP_AC 2 → 4 within 7.0 GiB free VRAM).
- Changes (staged in /tmp/r3_cand6 + /tmp/switches_r6.json, 0-ULP verified in test_r6_bitwise.py):
  - BAGEL_OPT_BATCH_CFG_FLOW=1: PreparedMultiBranchFlowState + forward_inference_flow_multi_cfg, collapsing 2-way Generate CFG and 3-way Refine CFG flow passes into 1 batched 28-layer pass (reading 14 GB moe_gen weights once per step instead of 2–3x, and eliminating self.norm(x_text) + out_seq scatter/gather).
  - BAGEL_OPT_DEDUP_TRAIN_VISION=1: 12 → 1 SiglipVisionModel forward + 12 → 1 packed_vit_tokens H2D copy in Refine training (uniform_vit_repeats).
  - BAGEL_OPT_MLP_AC=4 (up from 2, using +3.0 GiB of the 7.0 GiB free VRAM).
- time result (/tmp/r6_time/time.json):
  - window_s_per_step: [11.4868, 13.0643, 12.6352] s/step (s_per_step = 12.3954, 1.8946x, peak VRAM 129.62 GiB).
  - Diagnosis: Generate steps (k_br=2 CFG) got 150–240ms FASTER (7.389 → 7.232s, 8.287 → 8.231s, 8.059 → 7.820s), while Refine steps (k_br=3 CFG + MLP_AC=4 at 129.62 GiB) got 120–540ms slower (M=4096 already saturates Hopper TensorCores at 1,732 FLOPs/byte, so 3-way concat added repeat/cat overhead and MLP_AC=4 triggered expandable_segments allocator pressure). Not promoted; /submission stays at c980ed4 (1.9057x).

---
5.3 hRound 7 — Asynchronous `pack_batch` + `ref_model` Forward Overlapped with Reward Wait & Cross-Rank `dist.barrier()`, Gen-Only 2-Branch Batched CFG Flow, & 12-to-1 Train ViT Dedup
- Start time: 2026-11-20T00:49:18Z
- Changes (staged in /tmp/r3_cand7 + /tmp/switches_r7.json):
  - BAGEL_OPT_OVERLAP_REF_FWD=1: runs pack_batch (vae_model.encode) + create_block_mask + asynchronous 28-layer ref_model forward (curr_step > train_step, zero NCCL collectives since RESHARD_REF=0) BEFORE blocking on per_round_reward.result() and dist.barrier(), overlapping ref_model compute with GenEval HTTP PNG/reward latency and cross-rank rollout stragglers (fill_packed_advantages populates loss_info once rewards arrive).
  - BAGEL_OPT_BATCH_CFG_FLOW="gen": enables 2-branch batched CFG flow ONLY when cfg_img_scale <= 1.0 (Generate & Eval, where r6_time proved -150..240ms/step), keeping 3-branch Refine on single-branch CUDAGraph.
  - BAGEL_OPT_DEDUP_TRAIN_VISION=1 (12 → 1 SiglipVisionModel forward) + BAGEL_OPT_MLP_AC=2 (126.72 GiB safe VRAM).
- r7_time first attempt (/tmp/r7_time, finished 2026-11-20T01:00:39Z):
  - Before OOMing on Step 6, BAGEL_OPT_OVERLAP_REF_FWD=1 substantially reduced post-barrier training time (Step 1: 41.11s → 37.58s (-3.53s), Step 2: 10.03s → 9.06s (-0.97s), Step 3: 18.09s → 17.74s (-0.35s), Refine grad-accum 5.6s → 3.7–4.3s).
  - Step 6 hit CUDA OOM (296 MiB allocation inside torch.cuda.graph(g, pool=flow_pool) in forward_inference_flow_multi_cfg): 124.10 GiB remained allocated in PyTorch because previous-step training tensors (packed_input, loss_info, loss, v_pred, ref_v_pred, ref_per_token_logps, x_curr, ref_x_curr, log_prob, per_token_logps, raw_per_token_logps) were not deleted at the end of curr_step in train/online_rl.py (holding ~4–6 GiB across the next step's unsharded rollout!), while 9.48 GiB sat reserved in PyTorch's expandable_segments pool unavailable to CUDA Graph's private pool (BATCH_CFG_FLOW="gen" also doubled flow temporary [8192, 18944] inside the private pool).
  - Root-caused the 124.10 GiB rollout memory in r7_time: optimizer.zero_grad() ran at line 1261 *after* rollout_controller.context(), retaining 14.6 GiB of sharded FP32 gradients plus ~4 GiB of ov_* / step-local tensors across the next step's unsharded rollout (+18.6 GiB dead memory). Also noted pre-reward ref_model contended with the GenEval worker's mmdetection on the slowest rank.
  - Round 7b fixes in /tmp/r3_cand7 + /tmp/switches_r7.json: moved BAGEL_OPT_OVERLAP_REF_FWD=1 to run immediately *after* local per_round_reward.result() (when local mmdetection is idle, overlapping early ranks' ref_model with straggler ranks' rollout/reward before all_gather/all_reduce), added BAGEL_OPT_FAST_STEP_SYNC=1 (optimizer.zero_grad(set_to_none=True) right after scheduler.step(), step-local tensor release before/after loss.backward(), batched logging all_reduces 24 -> 3, deferred image loss scalar D2H syncs after optimizer.step(), single-call RolloutBuffer.all_gather), kept BAGEL_OPT_BATCH_CFG_FLOW="gen" and BAGEL_OPT_DEDUP_TRAIN_VISION="1".
- time result (/tmp/r7b_time/time.json, finished 2026-11-20T01:32:49Z):
  - window_s_per_step: [11.4503, 12.28, 12.3729] s/step (all 3 windows improved vs Round 5 [11.5078, 12.977, 12.4847]; Window 1 reaches 2.0115x!)
  - s_per_step: 12.0344 s (vs 12.3232 s Round 5 and 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.9514 (mean window ratio 1.9529, peak allocated memory reduced 126.72 GiB → 126.17 GiB)
- check --quick result (/tmp/r7b_quick/check.json, finished 2026-11-20T01:43:37Z):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, peak allocated memory 126.06 GiB.
- End time: 2026-11-20T01:44:55Z — Promoted to /submission/r3 (1faa86a on opt) and /submission/switches.json.

---
6.3 hRound 8 — 0-ULP `sm_90` Fused Training MoT `QKNorm + RoPE + DisjointScatter + Permute(1,0,2)` & `AttnOut Unpad + Transpose + DisjointGather` Forward/Backward Kernels + `MLP_AC=3`
- Start time: 2026-11-20T01:47:30Z
- Profile motivation (/tmp/r6_profile/timing_profile.profile.txt):
  - PackedAttentionMoT.forward_train (82 layer forwards + 28 layer backwards per step across ref_model, fsdp_model, and AC recompute) executed 15 separate kernels and 9 full-sequence [L, 28, 128] HBM roundtrips per layer (aten::copy_ 176ms, aten::index_copy_ 99ms, rmsnorm_fwd/bwd(128) ~300ms, rope_qk_fwd/bwd ~125ms, _GatherDisjoint2 120ms).
- Pre-benchmark 0-ULP GPU verification (/tmp/test_r8_kernels.py):
  - Verified 0 differing bytes across all 120 forward, backward, dw, padded (pad_size=128), freeze_und, and det_mode=False/True tests (92.40ms → 34.87ms, 2.65x microbenchmark speedup on 28 layers at L=26,496).
- Changes (staged in /tmp/r3_cand8 + /tmp/switches_r8.json):
  - BAGEL_OPT_FUSED_TRAIN_QKV=1: train_qkv_prep_fwd/bwd (fuses 2-stream bf16 q_norm + k_norm + RoPE + _ScatterDisjoint2 + .permute(1,0,2).contiguous() + pad_sequence into 1 warp kernel forward and 1 warp kernel backward) + train_attn_out_split_fwd/bwd (fuses [1, 28, L, 128] unpad + .transpose(0,1).reshape + _GatherDisjoint2 into 1 warp kernel forward/backward).
  - BAGEL_OPT_MLP_AC="3" (using the -0.55 GiB VRAM saved in Round 7 + -0.42 GiB transient tensor elimination).
- r8_time first attempt (MLP_AC="3", finished 2026-11-20T01:59:58Z):
  - Windows 1 & 3 jumped to 11.1541s (2.065x) and 11.9594s (1.973x), with Refine grad-accum dropping to 3.29–3.61s (-0.6s), confirming strong speedup from BAGEL_OPT_FUSED_TRAIN_QKV=1.
  - Window 2 had a +1.34s rollout stutter (Step 12: 9.269s, peak VRAM 127.91 GiB) because MLP_AC="3" (127.91 GiB) + creating fresh torch.cuda.graph_pool_handle() PrivatePools on every generate_text_batch active-set shrink and generate_image_mix triggered synchronous expandable_segments cuMemUnmap reclamation.
  - Round 8b tested sharing a raw graph_pool_handle() across sequential captures, which tripped PyTorch's CUDACachingAllocator.cpp:2630 use_count > 0 assert once all graphs in that pool dropped to use_count == 0.
  - Round 8c reverts bagel.py to Round 7 (1faa86a) and isolates BAGEL_OPT_FUSED_TRAIN_QKV=1 with BAGEL_OPT_MLP_AC="2" (safe ~126 GiB peak VRAM).
- time result (/tmp/r8c_time/time.json, finished 2026-11-20T02:17:06Z):
  - window_s_per_step: [11.3301, 12.462, 11.7449] s/step (Window 1 reaches 2.0328x, Window 3 reaches 2.0095x!)
  - s_per_step: 11.8456 s (vs 12.0344 s Round 7 and 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.9825 (mean window ratio 1.9846, peak allocated memory 126.18 GiB)
- check --quick result (/tmp/r8c_quick/check.json, finished 2026-11-20T02:26:43Z):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, peak allocated memory 126.07 GiB.
- End time: 2026-11-20T02:27:29Z — Promoted to /submission/r3 (246a67e on opt) and /submission/switches.json.
- Full check result (/tmp/r8_full_check/check.json, finished 2026-11-20T02:47:22Z):
  - status: PASS, speedup: 1.9607 (window_s_per_step = [11.3754, 12.3139, 12.2729], window_ratios = [2.0247, 1.9344, 1.923]), bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, 474/474 inputs verified, peak VRAM 126.18 GiB.

---
7.3 hRound 9 — 0-ULP `sm_90` Fused `ResidualAdd + Qwen2RMSNorm` Forward/Backward Kernels + Fast Single-Branch Refine Flow (`BAGEL_OPT_FAST_SINGLE_FLOW=1`) & Layer-0 Text QKV Precompute
- Start time: 2026-11-20T02:48:00Z
- Pre-benchmark 0-ULP GPU verification:
  - /tmp/test_r9_kernels.py: 0 differing bytes across all 140 add_rmsnorm_fwd / add_rmsnorm_bwd tests (M=1..26496, det=False/True, with_upstream=True/False).
  - /tmp/test_r9_e2e.py: 0 differing bytes across 4-layer und prefill, single-branch flow (nonempty_kv & empty_kv), 2-branch flow, and forward_train forward + dx + all parameter gradients (det=False & det=True).
- Changes (staged in /tmp/r3_cand9 + /tmp/switches_r9.json):
  - BAGEL_OPT_FUSED_ADD_RMSNORM=1: add_rmsnorm_fwd + add_rmsnorm_bwd wired into Qwen2MoTDecoderLayer.forward_train, Qwen2Model.forward_inference_flow_multi_cfg (sub-block + cross-layer), and Qwen2Model.forward_inference(mode="und") (sub-block + cross-layer).
  - BAGEL_OPT_FAST_SINGLE_FLOW=1: precomputes Layer-0 (q_text_0, k_text_0, v_text_0) once before the denoising loop and uses three 1-branch PreparedMultiBranchFlowStates on Refine steps (eliminating packed_sequence/out_seq scatter/gather, 63x rotary_emb, 63x Layer-0 x_text projections, and 63x dead Layer-27 x_text o_proj + norm + mlp + self.norm without 3-way concat overhead).
- time result (/tmp/r9_time/time.json, finished 2026-11-20T03:05:09Z):
  - window_s_per_step: [11.1306, 12.3363, 12.1877] s/step (Window 1 reaches 2.0692x; vs r8_full_check [11.3754, 12.3139, 12.2729])
  - s_per_step: 11.8848 s (vs 11.9874 s in r8_full_check and 23.4842 s frozen reference; Refine grad-accum down to 3.24–3.28s, peak VRAM 126.16 GiB)
  - speedup_vs_frozen_reference: 1.9760 (mean window ratio 1.9788)
- check --quick result (/tmp/r9_quick/check.json, finished 2026-11-20T03:17:41Z):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, 474/474 inputs verified, peak VRAM 126.05 GiB.
- End time: 2026-11-20T03:18:10Z — Promoted to /submission/r3 (372fc48 on opt) and /submission/switches.json.

---
7.9 hRound 10 — CUDAGraph-Captured Decode Sampling Prep + 1-Step Pipelined Async Pinned D2H (`BAGEL_OPT_FAST_DECODE_LOOP=1`), 0-ULP `sm_90` Fused Dual Gathered `LogSoftmax` (`BAGEL_OPT_FUSED_DUAL_LOGPS=1`), & Direct Train MoT Split (`BAGEL_OPT_DIRECT_TRAIN_SPLIT=1`)
- Start time: 2026-11-20T03:18:30Z
- Pre-benchmark 0-ULP GPU verification (/tmp/test_r10.py + mid-pipeline EOS shrink test):
  - fused_dual_gathered_log_softmax: 0 differing bytes across V=152064 & V=1027, T=1..640, rand/zeros/neg_zero/only1/only2, det=False/True (1.687ms → 0.505ms, 3.34x faster, saving 466 MB peak VRAM and ~5.1 GB HBM traffic per Refine step).
  - BAGEL_OPT_FAST_DECODE_LOOP=1: 0 differing bytes across top_p=0.9, topk=50, greedy, forced-EOS, and mid-pipeline staggered early-EOS shrinking (lens=[41,20,19,41], [23,14,41,6], ...), det=False/True (captures logits.float() + topk(1000) + logsumexp + cumsum + mask + F.softmax inside the decode CUDAGraph, batches generated_probs D2H to 1 end-of-loop transfer, and hides per-step next_tokens D2H behind the next step's 28-layer graph.replay()).
  - BAGEL_OPT_DIRECT_TRAIN_SPLIT=1: 0 differing bytes across has_vit=False/True and det=False/True (eliminates packed_sequence [L, 3584] zero+scatter in Bagel.forward and _GatherDisjoint2 in Qwen2Model.forward_train, saving ~1.14 GB HBM traffic + 190 MB VRAM).
  - BAGEL_OPT_BF16_REF_SHARDS=1 + BAGEL_OPT_SELECTIVE_AC=1 + BAGEL_OPT_MLP_AC=4: casts ref_model CPU parameters to bfloat16 prior to fully_shard (cutting ref_model _sharded_param_data 14.6 GiB → 7.3 GiB, -7.3 GiB GPU VRAM with 0-ULP equivalence) so 5 trailing layers skip Attention recompute (and Layer 27 skips MLP recompute) safely below 127 GiB.
  - Fixed device="cpu" on pinned_tok under torch.set_default_device("cuda") (caught in r10_time, verified in test_r10.py).
- time result (/tmp/r10b_time/time.json, finished 2026-11-20T03:41:38Z):
  - window_s_per_step: [11.0335, 11.903, 12.4159] s/step (Window 1 reaches 2.0875x, Window 2 reaches 2.0012x; Generate grad-accum down to 0.78–1.03s, Refine grad-accum down to 3.20–3.23s!)
  - s_per_step: 11.7841 s (new all-time best vs 11.8848 s Round 9 and 23.4842 s frozen reference)
  - speedup_vs_frozen_reference: 1.9929 (mean window ratio 1.9965, peak allocated memory reduced 126.16 GiB → 124.59 GiB even with SELECTIVE_AC=1, MLP_AC=4)
  - Also tested torch.compile(flex_attention, dynamic=True) in /tmp/test_dynamic_flex.py: rejected (21,327 differing bytes, max_abs = 0.00195 due to dynamic vs static Triton tiling; violates Tier N0).
- check --quick result (/tmp/r10b_quick/check.json, finished 2026-11-20T03:55:55Z):
  - status: PASS, bitwise: true, measured_tier: "N0", 14 optimizer steps, 3200/3200 tensors identical, 235/235 reward requests identical, 474/474 inputs verified, peak VRAM 124.45 GiB.
- End time: 2026-11-20T03:56:25Z — Promoted to /submission/r3 (507fbd1 on opt) and /submission/switches.json.
- Full check result (/tmp/r10_full_check/check.json, finished 2026-11-20T04:15:05Z):
  - status: PASS, speedup: 1.9557 (window_s_per_step = [11.2737, 12.1694, 12.6418], window_ratios = [2.043, 1.9574, 1.8669]), bitwise: true, measured_tier: "N0", 14 steps / 3200 tensors / 235 reward requests, peak_memory_allocated_gib = 124.59, peak_memory_reserved_gib = 133.73.
  - Root cause of Window 3 12.64s in r10_full_check: (1) SELECTIVE_AC=1, MLP_AC=4 pushed peak_memory_reserved_gib back to the 133.73 GiB ceiling, triggering cuMemUnmap CUDAGraph PrivatePool stutters (+0.35..0.50s on Steps 13–14; immediately mitigated in /submission/switches.json by setting SELECTIVE_AC=0, MLP_AC=2 so BF16_REF_SHARDS=1 keeps peak allocated memory at ~118.8 GiB with ~8 GiB unreserved headroom), and (2) cold-cache create_block_mask + flex_attention static-L recompilations on Step 14 (+0.26s) and Step 15 (+0.82s), targeted in Round 11 (BAGEL_OPT_FAST_BLOCK_MASK=1 + BAGEL_OPT_PREWARM_FLEX=1).

---
8.9 hRound 11 — 0-ULP Custom CUDA `BlockMask` Summary (`BAGEL_OPT_FAST_BLOCK_MASK=1`), Parallel Static-`L` `flex_attention` Warmup Prewarming (`BAGEL_OPT_PREWARM_FLEX=1`), & `-7.3 GiB` Unreserved VRAM Headroom (`SELECTIVE_AC=0, MLP_AC=2`)
- Start time: 2026-11-20T04:20:00Z
- Pre-benchmark 0-ULP GPU verification (/tmp/test_r11.py):
  - create_bagel_block_mask: 0 differing bytes across gen_4doc, refine_complex (L=39,280), and unaligned_L; 47.1x faster warm (79.74ms → 1.69ms) with zero torch.compile overhead.
  - _prewarm_flex_lengths: 0 new Dynamo compilations (frames 9 → 9, 17.01ms vs 456.52ms cold) when later invoked on complex multi-document BlockMask in both inference_mode and grad_mode + backward (0 differing bytes on out, dq, dk, dv for det=False/True).
- Active benchmark: bench.py time --tree /tmp/r3_cand11 --config /tmp/switches_r11.json --out /tmp/r11_time (PID 692317, started 2026-11-20T04:27:50Z).
- r11_time result (/tmp/r11_time/time.json, finished 2026-11-20T04:36:49Z, with SELECTIVE_AC=0, MLP_AC=2):
  - window_s_per_step: [11.4396, 12.4242, 11.7638] s/step (Window 3 improved 12.6418s → 11.7638s (-0.88s/step, 2.0062x) with 0 recompilations across all 4 ranks on Steps 10–15; peak_memory_allocated_gib dropped 124.59 → 119.42 GiB).
- Round 11b additions (staged in /tmp/r3_cand11 + /tmp/switches_r11.json, verified 0-ULP & constant-memory across 25 cycles):
  - BAGEL_OPT_PERSISTENT_GRAPH_POOL="1": keeps one anchored PrivatePool alive across all decode & flow CUDAGraphs so PrivatePool pages never unmap/remap against expandable_segments.
  - BAGEL_OPT_OVERLAP_REF_FWD="pre": launches pack_batch + ref_model forward immediately *before* blocking on per_round_reward.result() (curr_step > train_step + 1), overlapping ref_model with GenEval HTTP even on the slowest rank.
  - Re-enables BAGEL_OPT_SELECTIVE_AC="1", BAGEL_OPT_MLP_AC="4" within the -6.8 GiB allocated headroom (~124.6 GiB allocated + 1.1 GiB persistent pool < 133.7 GiB).
- Active benchmark: bench.py time --tree /tmp/r3_cand11 --config /tmp/switches_r11.json --out /tmp/r11b_time (PID 823362, started 2026-11-20T04:46:08Z).
- r11b_time result & isolation (/tmp/r11b_time/time.json, finished 2026-11-20T04:55:18Z):
  - BAGEL_OPT_OVERLAP_REF_FWD="pre" won strongly across identical trajectory steps (Step 2: 9.78s → 8.80s (-0.98s), Step 4: 9.92s → 9.14s (-0.78s), Step 5: 17.23s → 15.94s (-1.29s), Step 11: 15.98s → 15.22s (-0.76s), Step 14: 7.52s → 7.32s (-0.20s)).
  - However, combining PERSISTENT_GRAPH_POOL=1 (~1.5 GiB held in PrivatePool) with SELECTIVE_AC=1, MLP_AC=4 (124.60 GiB allocated) pushed fsdp_model backward into expandable_segments OOM-retry stalls on Step 13 (3.27s → 4.93s, +1.66s) and Step 15 (3.27s → 4.13s, +0.86s), whereas r11_time (SELECTIVE_AC=0, MLP_AC=2, 119.42 GiB) had rock-solid 3.25–3.34s across every Refine step.
  - Round 11c sets SELECTIVE_AC="0", MLP_AC="2" with FAST_BLOCK_MASK=1, PREWARM_FLEX=1, OVERLAP_REF_FWD="pre", PERSISTENT_GRAPH_POOL=1.
- Active benchmark: bench.py time --tree /tmp/r3_cand11 --config /tmp/switches_r11.json --out /tmp/r11c_time (PID 953776, started 2026-11-20T04:56:38Z).
- r11c_time result (/tmp/r11c_time/time.json, finished 2026-11-20T05:05:45Z):
  - window_s_per_step: [11.3676, 12.5852, 11.774] (s_per_step = 11.9089, 1.9720x). Confirmed SELECTIVE_AC=0, MLP_AC=2 eliminated the Step 13/15 allocator stalls (3.25s and 3.47s vs 4.93s and 4.13s), while r11_time (OVERLAP_REF_FWD="1", PERSISTENT_GRAPH_POOL="0", [11.4396, 12.4242, 11.7638], s_per_step = 11.8759, mean window ratio 1.9789x) was slightly faster overall (3.27s on Step 15, avoiding local mmdetection GPU contention and PrivatePool retention).
  - Selected the r11_time switch configuration (FAST_BLOCK_MASK=1, PREWARM_FLEX=1, OVERLAP_REF_FWD="1", PERSISTENT_GRAPH_POOL="0", SELECTIVE_AC="0", MLP_AC="2") in /tmp/switches_r11.json for Gate 2 bitwise check.
- Active Gate 2 check: bench.py check --quick --tree /tmp/r3_cand11 --config /tmp/switches_r11.json --out /tmp/r11_quick (PID 1084250, started 2026-11-20T05:07:05Z).
- r11_quick result & exact root cause (/tmp/r11_quick/check.json, finished 2026-11-20T05:16:25Z):
  - INCORRECT on Step 0 (Total norm: 0.37540138 vs 0.37770873 reference, whereas Step 1 was 1.5733635425567627 identical to 17 digits!).
  - Reproduced in 3 seconds (task-1766 & task-1768): PyTorch's automatic_dynamic_shapes=True compiles flex_attention's 1st call (Step 0, L_0) with static L_0 and switches to a single SymInt dynamic kernel on the 2nd distinct L (Step 1, L_1), with 0 recompilations on all subsequent steps (step=2, 3, 4!). Prewarming multiple L_w values *before* Step 0 flipped Step 0 from static L_0 to dynamic SymInt (max_diff = 0.00098). All cold recompilations on Steps 14–15 in Round 10 were actually from create_block_mask(..., _compile=True) (new closure per step), which BAGEL_OPT_FAST_BLOCK_MASK=1 eliminates with 0-ULP identity and zero torch.compile.
  - Disabled BAGEL_OPT_PREWARM_FLEX="0", kept BAGEL_OPT_FAST_BLOCK_MASK="1", and set BAGEL_OPT_SELECTIVE_AC="0", BAGEL_OPT_MLP_AC="4" (~121.4 GiB allocated, 12.3 GiB below physical ceiling).
- Active Gate 2 check: bench.py check --quick --tree /tmp/r3_cand11 --config /tmp/switches_r11.json --out /tmp/r11b_quick (PID 1197157, started 2026-11-20T05:29:10Z).

---
↑ R3