Gemini 4 Neon 2.19×
Harness: Antigravity · switches: PYTORCH_ALLOC_CONF=expandable_segments:True OPT_DECODE_GRAPH=1 OPT_DIFFUSION_FAST=1 OPT_TRAIN_FAST=1 OPT_AC_BUDGET_GIB=52.0 OPT_FUSED_KERNELS=1 OPT_TRAIN_FUSED_NORM=1 OPT_OVERLAP_FSDP_REWARD=1 OPT_ROLLOUT_FAST=1 OPT_ROLLOUT_V2=1 OPT_TRAIN_V2=1 OPT_ROLLOUT_V3=1 OPT_TRAIN_V3=1
API stalls passed the 6 h pause allowance, so the lost time was run as a continuation of the same conversation on the saved submission (51 min); the judged result is the continuation's. The time axis leaves out the held time of both segments.
- Judged
- 2.19×
- Tier
- N0
- Self-best
- 2.16×
- Rounds
- 8
- Hours
- 10.0
- API cost
- $73.7
- Input tokens · 95.5% cached
- 196 M
- Output tokens
- 1.3 M
- Requests
- 664
§ 02Key levers
- Text-decode CUDA graph
- ✓
OPT_DECODE_GRAPH, round 1 full check 1.25× (first attempt hit a 740 MiB backward OOM; passed after reusing one stream,g.reset()and expandable segments); top-p prep moved into the graph in round 4, one-step async pipeline in round 6, persistent graph pool + manualcapture_begin/capture_endin round 7 - Reward wait hidden behind forward
- ✓ round 3 moves packing and the reference-model forward before the wait, advantages filled in afterwards; round 5
OPT_OVERLAP_FSDP_REWARDalso moves the policy forward and the advantage-independent loss terms (together with train-side fusion, full check 1.85× → 1.99×) - Rollout-side bitwise fused kernels
- ✓ round 2 Triton pure-copy scatter / split; round 4 custom CUDA extension
r3_fused_ops: RMSNorm (with residual add), q/k norm + RoPE + scatter (21 kernels per denoise layer → 1), SwiGLU, also wired into training in the same round, full check 1.55× → 1.85×; round 8 gate/up concat + fused SwiGLU - Train-side bitwise kernels / freeing memory
- ✓ round 3 reference model keeps bf16 params only and reshards after forward, peak 130.76 → 112.18 GiB, freed memory spent on less recompute per layer under a budget (
OPT_AC_BUDGET_GIB); round 5 train-side RMSNorm, q/k norm + RoPE + scatter fwd/bwd (OPT_TRAIN_FUSED_NORM), all 13 full-recompute layers in the refine step removed; round 8 custom single-pass AdamW (83.08 → 29.13 ms/step); final peak 121.77 GiB - Other main levers
- round 2 denoise desync + pre-merged KV, CFG text context shared zero-copy (no repeated VAE + ViT + LLM prefill), full check 1.25× → 1.49×; frozen-ViT dedup of repeated images, block mask / ViT output shared between reference and policy (round 3); CFG branch batching,
create_block_mask(H=None)(round 6 → 2.05×); refine image context B=1 broadcast, step-0 CFG merge (round 7 → 2.10×); policy model kept unsharded from rollout on (round 8 → 2.16×); denoise CUDA graph measured only 4.35 ms faster per forward, not used
§ ARaw trace
Raw work log18 sections
-8.1 hRound 1: Baseline Profile & Text Generation Rollout (Host/Sync + CUDA Graphs)
- Start: 2026-11-19 19:40:50 UTC ### Baseline Profile Findings (/tmp/prof-ref-r1, steps 6–7, Gen + Refine) - Total trace span: 62.61s (instrumented; uninstrumented steps 10–11 = 46.2s pair: Gen 14.5s, Refine 31.7s) - GPU active time (union): 26.95s (43.0% of wall clock — heavily host/sync-bound) - CUDA runtime overhead (2 steps): -cudaLaunchKernel: 1,466,461 calls (9.03s) -cudaStreamSynchronize: 269,373 calls (8.54s) —aten::_local_scalar_dense: 250,220 calls (9.27s CPU),aten::nonzero: 19,405 calls (1.47s CPU) -cudaFree+cudaMalloc: 419 + 428 calls (1.73s) from 4xtorch.cuda.empty_cache()per step -cudaMemcpyAsync: 280,253 calls (1.21s) - Stage breakdown (uninstrumented steady-state Gen+Refine pair, ~46.6s): 1. Text rollout (generate_text_batch): ~15.5–17.5s (~35% of pair, incl. 2–4s rank straggling in Refine). Only 18–19% GPU utilization (35 tok/s; GEMMs + flash_fwd_splitkv only need ~2.7s GPU time across both steps!). Kind 2 (Launch/Sync): 84+.item()syncs/token in_static_kv_cache_attention+ 17 syncs/token ingenerate_text_batch+ eager Python launches. 2. Image diffusion rollout (edit_image+generate_image_with_think+_forward_flow): ~19–20s (~42% of pair). 61–67% GPU utilization (37k kernels/s). Kind 2/3 (Sync + Layout/Copy + Redundant Compute):_merge_static_kv_prefix_and_querydoes 7.item()+ 4nonzerosyncs + full KV cache copy per layer × 28 layers × 90 passes;edit_imageruns duplicate VAE+ViT+28-layer LLM prefill forcfg_text_context;mode="gen"scatters/gathers 4096 VAE vs 8 text tokens 10× per layer. 3. Training step (ref_model+fsdp_model+ backward + AdamW): ~9.7s (~21% of pair: Gen 2.1s, Refine 7.6s). 95–100% GPU utilization. Kind 2/3 (Recompute + Redundant Compute + Layout): Full Activation Checkpointing on all 28 layers (ref_modelkept in fp32 + unsharded bf16 wastes ~36 GiB VRAM); duplicate frozenvit_modelforward (12 images) and duplicatecreate_block_maskinref_modelandfsdp_model;und/genscatter-gather between layers. 4. Reward wait +empty_cache+all_gatheridle gaps: ~2.5s (two ~1.25s 0%-GPU gaps).
-8.1 hPlanned Round 1 Change
- Target hotspot #1: Text rollout (generate_text_batch+_static_kv_cache_attention) - Switch:OPT_DECODE_GRAPH=1(off by default) - Remove per-layer syncs in_static_kv_cache_attention, eliminate 16/17 syncs/token ingenerate_text_batch, and capture CUDA graphs per active batch size for the 28-layer decode +lm_headforward pass.
-8.1 hRound 1 Results
- End: 2026-11-20 03:13 UTC (finished 2026-11-19 20:49:53 UTC) - Changed:modeling/bagel/qwen2_navit.py(Qwen2ForCausalLM.decode_step_static_cache),modeling/bagel/bagel.py(Bagel._generate_text_batch_graph), gated behindOPT_DECODE_GRAPH=1(+PYTORCH_ALLOC_CONF=expandable_segments:True). - Note on first attempt (/tmp/check-r1, deleted): Creating a newtorch.cuda.Stream()per call and not callingg.reset()caused ~740 MiB OOM on step 1 backward (3.58 GiB reserved unallocated fragmentation). Reusing a single_decode_warmup_stream, callingg.reset()infinally:, and enablingPYTORCH_ALLOC_CONF=expandable_segments:Trueresolved it completely (peak 130.76 GiB vs ref 130.72 GiB). - Fullcheck(/tmp/check-r1b): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[18.4424, 18.9967, 18.4511]s/step (mean18.6301s/step vs ref23.3224s/step; Gen ~11.9s, Refine ~25.2s) - Window ratios:[1.2405, 1.2420, 1.2734]->speedup = 1.2520- Committed to/submission/r3(opt) and activated in/submission/switches.json. ---
-0.2 hRound 2: Diffusion Flow Rollout, Zero-Copy CFG Prefix Views & ViT Reuse (`OPT_DIFFUSION_FAST=1`)
- Start: 2026-11-20 03:15 UTC - End: 2026-11-20 03:56:32 UTC ### Target & Findings - Post-Round-1 bottleneck #1: Diffusion rollout (~22.4s/pair, ~60% of wall clock). - Root causes: 1.bagel.py(torch.tensor([t] * x_t.shape[0])) triggered 4,096.item()syncs per denoising step (~143,360/pair). 2._merge_static_kv_prefix_and_querydid 7.item()+ 4nonzerosyncs + full static prefix copy per layer × 28 layers × ~81 diffusion passes/pair. 3.Qwen2MoTDecoderLayer.forward_inference(mode='gen')did 10+ full-sequencezeros_like+ gather/scatter ops per layer to separate 8 BOI/EOI text tokens from 4,096 VAE tokens (~1.26 TB/pair traffic). 4.edit_imageranupdate_context_image(..., vae=True, vit=True)twice (duplicate VAE+ViT+28-layer LLM prefill forcfg_text_context), did 2× largedeepcopys ofStaticKVCache, and recomputed frozen ViT embeddings already computed inget_edit_think_and_operation. - Micro-benchmark (bench_flow.py, 28 layers): eager Split-MoT + Prebuilt-KV + pure-copy Triton scatter/split improved 251.46 -> 138.95 ms/pass (1.81×, bitwise N0). Diffusion CUDA Graph only added 4.35 ms/pass (outweighed by ~280ms×3 capture cost/step) so was intentionally not used.time_embedder(t.unsqueeze(0)).expand(4096, -1)was rejected due to 7.63e-6 cuBLAS tile drift (keptt.expand(4096)which is bitwise N0). ### Changes (OPT_DIFFUSION_FAST=1) -modeling/bagel/opt_kernels.py: pure bf16 load/store Triton kernelsscatter_qkv_genandsplit_attn_gen. -modeling/bagel/qwen2_navit.py:StaticKVCache.readonly_view(),StaticFlowKVWorkspace(pre-allocates merged K/V and copies static prefix once before denoising loop),Qwen2ForCausalLM.forward_flow_branch_fast(keeps(h_text, h_vae)split across all 28 layers), and_prefill_metafast path in_static_kv_cache_attention/Qwen2Model.forward_inference. -modeling/bagel/bagel.py:_prepare_flow_fast_context,_forward_flow_fast(usingt.expand(N)+ hoistedh_text_init/packed_pos_embed/timesteps_cpu), wired intogenerate_image,generate_image_sde,generate_image_mix; optionalcached_vit_embedsreuse inforward_cache_update_vit. -train/rollout_controller.py: zero-copyreadonly_view()forcfg_text_contextingenerate_image_with_thinkandedit_image(eliminates duplicate VAE+ViT+LLM prefill anddeepcopys), compactmax_cache_lenforcfg_img_context, and identity-checked ViT embedding cache fromget_edit_think_and_operation->edit_image(cleared immediately after use and incontext()finally:).
-0.2 hRound 2 Results
- Unit bitwise test (test_r2_bitwise.py): 14/14 PASS (bothdeterministic=Falseanddeterministic=True). - Fullcheck(/tmp/check-r2/check.json): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[15.1728, 15.9887, 15.9314]s/step (mean15.6976s/step vs ref23.3224s/step; Gen ~9.8s, Refine ~21.4s) - Window ratios:[1.5078, 1.4756, 1.4748]->speedup = 1.4861- Peak allocated memory:130.76GiB (reserved133.72GiB) - Committed to/submission/r3(opt) and activated in/submission/switches.json. ---
0.7 hRound 3: Training Step, Memory Headroom, Reward Overlap & Zero-Sync Packing (`OPT_TRAIN_FAST=1`)
- Start: 2026-11-20 04:10 UTC - End: 2026-11-20 04:51:21 UTC ### Post-Round-2 Profile Findings (/tmp/prof-r2, steps 10–11, Gen + Refine) - Trace span: 31.97s, GPU active: 24.48s (76.6%). - Major remaining bottlenecks uncovered: 1.cudaFree(1.120s, 431x) +cudaMalloc(1.018s, 432x) = 2.14s/pair from 3xtorch.cuda.empty_cache()per step. 2. 36,976aten::_local_scalar_densesyncs (~532ms CPU) inrollout_controller.pypack_batchfromtorch.tensor([cuda_scalar] * N)onpacked_timesteps,dts,packed_timesteps_for_loss. 3. 1.12s + 0.32s zero-GPU reward HTTP wait gaps after rollout. 4. Refine training step ([23-31s]):index_put_(380ms) +gather(133ms) +pad_sequenceCatArrayBatchedCopy(128ms) +direct_copy(168ms) + duplicatecreate_block_mask(114ms) + duplicate 27-layer frozenvit_model(12 identical images) + full AC on all 28 layers (ref_modelkept fp32 + unsharded bf16 wasted 35.5 GiB). - Probes (probe_r3.py,probe_r3_part2.py,probe_fsdp2_r3.py): -flex_attention = torch.compile(flex_attention, dynamic=True)hadmax_diff=9.77e-4(non-N0 -> rejected). -pad_sequenceskip whenpad_size == 0-> bitwise N0. - 27-layer SigLIP ViTB=1repeated 4x/12x vsB=4/B=12-> bitwise N0 (max_diff=0.0) in both det=False/True. - 4-GPU FSDP2ref_modelparam-only bf16 +FULL_SHARD(reshard_after_forward=True)andfsdp_modelFULL_SHARD+ Split-MoT + dynamic AC (full/mlp_only/none) -> bitwise N0 (max_diff=0.0). - Single-layer Refine (L=38,912) benchmark: upstream full AC178.85 ms/layer-> Split-MoT full AC160.96 ms/layer-> Split-MoTmlp_onlyAC148.78 ms/layer(+3.05 GiB) -> Split-MoTno_ac124.92 ms/layer(+9.32 GiB). ### Changes (OPT_TRAIN_FAST=1) -modeling/bagel/opt_kernels.py: pure-copy Triton autograd kernelsScatterQkvMotTrainFn,SplitAttnMotTrainFn,SplitHiddenMotFn,MergeHiddenMotFn. -modeling/bagel/qwen2_navit.py:Qwen2MoTDecoderLayer.forward_train_split+ dynamic per-step AC scheduler inQwen2Model.forward_train(allocatesmlp_only/nonefrom layer 27 down usingOPT_AC_BUDGET_GIB=48.0, so saved activations free beforefullAC recompute spikes);pad_sequencefast path forpad_size == 0. -modeling/bagel/bagel.py: frozen ViT identical-image deduplication (_run_vit_model), plus sharedprecomputed_block_maskandprecomputed_vit_outputforwarding fromref_modeltofsdp_model. -train/fsdp2_utils.py: skip staticCheckpointWrapper(replaced by dynamic AC) and removetorch.cuda.empty_cache()infsdp2_rollout_context. -train/rollout_controller.py: removetorch.cuda.empty_cache()incontext(), fix 37k.item()syncs via_materialize_scalar_runs, memoize PIL/patchify transforms inpack_batch, and adddefer_advantages/populate_advantages. -train/online_rl.py: param-only bf16ref_model+FULL_SHARD(reshard_after_forward=True)onref_model/fsdp_model; overlap reward HTTP futures withprepack+pack_batch+ref_model(torch.no_grad()so sharedBlockMask/ViT are normal tensors); shareblock_mask+ frozen ViT output withfsdp_model; defer non-control-flow.item()logging syncs and fuseloss_dict/statsall_reduces.
0.7 hRound 3 Results
- 4-GPU FSDP2 E2E bitwise test (test_r3_e2e_fsdp2.py): PASS (all logits, mse, grad norm, post-AdamW params bitwise identical). - Fullcheck(/tmp/check-r3/check.json): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[14.8194, 15.2758, 15.1335]s/step (mean15.0762s/step vs ref23.3224s/step; Gen ~9.4s, Refine ~20.6s) - Window ratios:[1.5438, 1.5445, 1.5525]->speedup = 1.5470- Peak allocated memory:112.18GiB (down 18.58 GiB from130.76GiB!) - Committed to/submission/r3(opt, commitb329096) and activated in/submission/switches.json. ---
1.5 hRound 4: Bitwise-Exact Custom CUDA Kernels & Graphed Top-P Prep (`OPT_FUSED_KERNELS=1`)
- Start: 2026-11-20 04:53 UTC - End: 2026-11-20 05:37:07 UTC ### Target & Findings - Post-Round-3 remaining kernel-launch and HBM-bandwidth hotspots across Decode, Diffusion Flow, and Training (ref_model&fsdp_model): 1. Unfused PyTorchQwen2RMSNorm(3584) + residual add: 8 kernels/norm reading/writing fp32 intermediates across 28 layers × (Decode + 81 Diffusion passes + Training). 2. Unfusedq_norm/k_norm(128) +apply_rotary_pos_emb+ scatter: 21 kernels/layer + ~1.1 GB HBM/layer in Diffusion Flow, 14 kernels/layer in Training fwd+bwd, 26 kernels/layer inref_model. 3. UnfusedF.silu(gate) * up(SwiGLU) forward and backward: extra HBM passes + savingsig_gate(1.37 GiB/no-AC Refine layer). 4. Top-p sampling prep (topk(1000),logsumexp,cumsum,masked_fill,F.softmax) running eagerly outside the Decode CUDA Graph on every token. - Exact PyTorchReduce.cuh(setReduceConfig) analysis verified exact reduction order (N=3584:vec44-acc + shared-mem tree + ascendingshfl_down(1,2,4,8,16)+float(1.0/3584.0);N=128: scalarvt0=4, stride=bwwithbw=32/64/128sorotate_halfpartners live in the same warp thread registers; SwiGLU bwddg = __fmul_rn(__fmul_rn(dsg, sig), fmaf(gf, 1.0f - sig, 1.0f))). - 28-layer E2E micro-benchmarks (test_r4_e2e.py): - Diffusion Flow:138.56 -> 110.40 ms/pass(2.28× faster than upstream's 251.46 ms), 100% bitwise N0. - Decode CUDA Graph (64 tok):621.4 -> 445.2 ms(103.0 -> 143.8 tok/s, +40% faster on top of R1), 100% bitwise N0. - Note: first check attempt withOPT_AC_BUDGET_GIB=64.0hit a 740 MiB OOM on step 1 backward (123.6 GiBallocated +10.1 GiBreserved unallocated); keepingOPT_AC_BUDGET_GIB=48.0avoided the OOM completely (5 extramlp_onlylayers only save ~30 ms/step). ### Changes (OPT_FUSED_KERNELS=1) -modeling/bagel/csrc/fused_ops.cu&setup.py: pre-built CUDA C++ extensionr3_fused_opsinstalled into/opt/candidate-env(nvcc 12.8 -O3 --fmad=false -gencode=arch=compute_90,code=sm_90, 0.0s cold compile): -rmsnorm_3584_bf16,add_rmsnorm_3584_bf16(exactReduce.cuh+ smem row cache) -fused_qknorm_rope_scatter_gen(1 register-only kernel replacing 21 kernels/layer in Diffusion Flow) -fused_qknorm_rope_128_bf16(exactBW=32/64/128QK-Norm + RoPE for Decode) -fused_swiglu_bf16,fused_swiglu_bwd_bf16(vectorized 128-bituint4, exact FMA bwd) -fused_rope_scatter_mot_train_fwd,fused_rope_scatter_mot_train_bwd(replaces 14 RoPE+scatter/gather kernels in training) -fused_qknorm_rope_scatter_mot_ref(replaces 26 kernels/layer inref_model) -modeling/bagel/opt_kernels.py:get_fused_ops(),FusedSwiGLUBf16Fn,FusedRopeScatterMotTrainFn. -modeling/bagel/qwen2_navit.py: wired fused kernels intoforward_flow_branch_fast(residual-fused across 28 layers),decode_step_static_cache(residual-fused across 28 layers), andforward_train_split(ref_model&fsdp_model); loweredupgrade_no_acfrom6.27 -> 4.90whenOPT_FUSED_KERNELS=1. -modeling/bagel/bagel.py: captured_decode_and_prep_topp(topk(1000)+logsumexp+filtered_probs+F.softmax) inside the Decode CUDA Graph.
1.5 hRound 4 Results
- Unit & 28-layer E2E bitwise tests (test_r4_kernels.py,test_r4_e2e.py): 100% PASS (0 bits diff across all shapes, bothdeterministic=Falseanddeterministic=True). - Fullcheck(/tmp/check-r4/check.json): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[12.0956, 13.1320, 12.6362]s/step (mean12.6213s/step vs ref23.3224s/step; Gen ~7.45–8.47s, Refine ~16.74–17.80s) - Window ratios:[1.8914, 1.7966, 1.8594]->speedup = 1.8492- Peak allocated memory:110.77GiB (timing) /110.37GiB (record) — down1.41 GiBfrom R3 and20.0 GiBbelow ref! - Committed to/submission/r3(opt, commit0c011d0) and activated in/submission/switches.json. ---
2.4 hRound 5: Bitwise-Exact Training Fused RMSNorm/QKNorm+RoPE+Scatter & FSDP-Reward Overlap (`OPT_TRAIN_FUSED_NORM=1`, `OPT_OVERLAP_FSDP_REWARD=1`)
- Start: 2026-11-20 05:49 UTC - End: 2026-11-20 06:32:14 UTC ### Post-Round-4 Profile Findings (/tmp/prof-r4, steps 10–11, Gen + Refine) - Trace span: 24.738s, GPU active: 20.657s (83.5% of wall clock). - Major remaining training & wait bottlenecks uncovered: 1. Unfused PyTorchQwen2RMSNorm(3584) +q_norm/k_norm(128) infsdp_modeltraining:~737 msof Refine training kernels (OTHER = 856 ms) +~200 mson Gen, AND saved400 MB/RMSNorm +1259 MB/QKNorm of fp32 intermediates forcingmlp_onlyAC to cost2.79 GiB/layer(leaving 13 Refine layers infullAC). 2. Hiddentorch.cuda.empty_cache()inRolloutBuffer.all_gather()(train/online_rl.py:528) causingcudaFree(664ms) +cudaMalloc(574ms) allocator thrashing (FSDP::all_gather (layers.19)blocked 168ms incudaMalloc). 3. Reward HTTP & rank-straggle wait gaps:1.280 szero-GPU idle gap on Gen waiting forper_round_reward.result()and1.040 sexposedAllReducestall on Refine waiting for slower ranks' reward workers. - Note on FSDP2FULL_SHARDvsSHARD_GRAD_OP: trace showedfsdp_modelforward/backwardAllGatherwas already 95–99% overlapped (< 23 msexposed), so keepingFULL_SHARDand spending the freed HBM on eliminatingfullAC layers + allocator headroom is strictly better. - Unit & full-layer benchmarks (test_r5_kernels.py,bench_r5_layer.py, RefineL=38912): -FusedRMSNorm3584TrainFn: 7.98× faster (2.817 -> 0.353 ms), saved memory400.1 -> 1.1 MB, 0 bits diff (det=False/True). -FusedQKNormRopeScatterMotTrainFn: 5.82× faster (8.256 -> 1.419 ms), saved memory1258.8 -> 347.3 MB, 0 bits diff (det=False/True). - FullQwen2MoTDecoderLayer:mlp_onlysaved memory dropped2.79 -> 1.42 GiB/layer(all 28 Refine layers fit withoutfullAC!) and backwardpeak_deltadropped9.78 -> 7.37 GiB(-2.41 GiB); 100% bitwise N0 across all params and AC modes. ### Changes (OPT_TRAIN_FUSED_NORM=1,OPT_OVERLAP_FSDP_REWARD=1) -modeling/bagel/csrc/fused_ops.cu: added 4 bitwise-exact CUDA kernels (rmsnorm_3584_fwd_rstd_bf16,rmsnorm_3584_bwd_bf16matching PyTorch1.0 / 3584.0reciprocal multiply + exactprod = dout * y_norm_bf16,fused_qknorm_rope_scatter_mot_train_fwd,fused_qknorm_rope_scatter_mot_train_bwd), rebuilt into/opt/candidate-env(r3_fused_ops). -modeling/bagel/opt_kernels.py:FusedRMSNorm3584TrainFnandFusedQKNormRopeScatterMotTrainFn(calling exact PyTorch.sum(...)onprodfor guaranteed bitwise-exactdw). -modeling/bagel/qwen2_navit.py: wired fused training norms + QK-Norm+RoPE+Scatter intoQwen2MoTDecoderLayer.forward_train_splitand finalnorm/norm_moe_geninQwen2Model.forward_train; recalibrated dynamic AC costs (cost_mlp=1.45, upgrade_no_ac=4.45) withOPT_AC_BUDGET_GIB=52.0(eliminates all 13fullAC layers on Refine + upgrades 2 Refine / 20 Gen layers tono_ac). -train/online_rl.py: fusedRolloutBuffer.all_gather()into a singleall_gather_objectwithout redundantdist.barrier()ortorch.cuda.empty_cache(); movedfsdp_modelforward and all advantage-independent loss ops (log_softmax,gather_text_policy_logps,per_token_kl,apply_cfg,get_x_t_distribution,log_prob,kl_img_loss) beforeper_round_reward.result()so GPU training overlaps asynchronously with GenEval HTTP latency.
2.4 hRound 5 Results
- Fullcheck(/tmp/check-r5/check.json): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[10.9622, 12.0606, 12.1529]s/step (mean11.7253s/step vs ref23.3224s/step; Gen ~7.11–7.73s, Refine ~14.81–16.61s) - Window ratios:[2.0870, 1.9563, 1.9333]->speedup = 1.9922- Peak allocated memory:119.31GiB (timing) /118.89GiB (record) - Committed to/submission/r3(opt, commitbd87b80) and activated in/submission/switches.json. ---
3.6 hRound 6: Pipelined Decode CUDA Graph, Batched CFG Flow, Fused Prefill & `create_block_mask(H=None)` (`OPT_ROLLOUT_FAST=1`)
- Start: 2026-11-20 06:34 UTC - End: 2026-11-20 07:44:46 UTC ### Target & Findings - Rollout (Decode + Diffusion Flow + Prefill) accounted for ~70% of remaining wall clock after Round 5. - Probes (probe_r6.py,probe_r6_gpu.py,probe_r6_e2e.py,probe_r6_flow_prefill.py): 1. Decode 1-token async pipeline (bagel.py): Upstream EOS dropout checkscurr_tokens[orig_idx] == end_token_id(input token, known at stepk-1), NOTnext_tokens(output token of stepk). Capturingtorch.multinomial(register_generator_state),gather, ands_tok/s_pos/s_slupdates inside the CUDA graph lets stepk+1launch on GPU before reading stepk's pinned D2Hnext_tokens(6.51 -> 5.97 ms/tok, 100% bitwise N0 onseq/probs/kv/rngacross staggered EOS and forcedmax_length-1EOS). 2. Rollout horizontalKV_cat(k_proj + v_proj,512+512->1024, bias=True): 2.0× faster pure GPU (13.6 -> 7.0 us/layer) atM=1..24, bitwise N0 on_KV_CAT_SAFE_M = {1, 2, 3, 4, 8, 16, 24, 2048, 2052, 4096, 4104, 8192, 12288}(det=False/True), but differs by 1–2 ULPs atM ∈ [100..200](caught in first Round 6 check at Eval Round 0 prompt prefill -> fixed via strict_KV_CAT_SAFE_Mwhitelist). 3. Batched CFG Diffusion Flow: Merging 2-branch Gen (B=8) and 3-branch Refine (B=12) into oneStaticFlowKVWorkspacewith zero-copycond_view(), Layer-0 shared QKV (src_b_mod=4),forced_bw=64text RMSNorm,down_proj16+8split atM=24, and Layer-27 dead text skip saved+10.14 ms/stepon Gen and+14.09 ms/stepon Refine (0 bits diff). 4. Fused Prefill (Qwen2Model.forward_inference): Residual-fusedmode="und"(126.05 -> 104.05 ms, 0 bits diff) and Split-MoTmode="gen"(150.28 -> 109.22 ms, 0 bits diff). 5.create_block_mask(..., H=None): 3.0× faster (17.11 -> 5.61 msatL=38912), 0 bits diff acrossflex_attentionfwd+bwd. ### Changes (OPT_ROLLOUT_FAST=1) -modeling/bagel/csrc/fused_ops.cu: addedrmsnorm_3584_bw_bf16/add_rmsnorm_3584_bw_bf16(explicitforced_bwmatching single-branchM=8'sBW=64),fused_qknorm_rope_scatter_gen_ex(src_b_modfor Layer-0 shared QKV + zero-copy strided KV inputs), and strided dim-0 support infused_qknorm_rope_128_bf16; rebuiltr3_fused_opsin/opt/candidate-env. -train/fsdp2_utils.py: create temporary_rollout_wkv/_rollout_bkv&_rollout_wkv_gen/_rollout_bkv_gen(410 MBtotal) onfsdp2_rollout_contextentry and delete beforereshard()(0 training memory overhead). -modeling/bagel/qwen2_navit.py:StaticFlowKVWorkspace.from_branches()&cond_view(); Batched CFG + Layer-0 shared QKV + Layer-27 dead text skip inforward_flow_branch_fast;_KV_CAT_SAFE_M-guardedKV_catin Decode, Flow, and Prefill; residual-fusedmode="und"and Split-MoTmode="gen"inQwen2Model.forward_inference. -modeling/bagel/bagel.py:create_block_mask(..., H=None); Batched CFG wiring in_prepare_flow_fast_context/_forward_flow_fast(B=4); 1-token async pipelined Decode CUDA Graph in_generate_text_batch_graph.
3.6 hRound 6 Results
- 28-layer E2E bitwise test (test_r6_e2e.py): 100% PASS (det=False/True). - Fullcheck(/tmp/check-r6/check.json): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[10.6422, 11.8629, 11.7516]s/step (mean11.4189s/step vs ref23.3224s/step; Gen ~6.62–7.67s, Refine ~14.06–16.08s) - Window ratios:[2.1498, 1.9889, 1.9993]->speedup = 2.0460- Peak allocated memory:119.28GiB (timing) /118.84GiB (record) - Committed to/submission/r3(opt, commitb0c0656) and activated in/submission/switches.json. ---
6.8 hRound 7: Anchored Decode Graph Pool, B=1 VAE/ViT Dedup, Step-0 CFG, Unsharded Shared ViT & Zero-Sync Training (`OPT_ROLLOUT_V2=1`, `OPT_TRAIN_V2=1`)
- Start: 2026-11-20 08:20 UTC - End: 2026-11-20 10:55 UTC ### Target & Findings - Post-Round-6 profile (prof-r6, 21.438s pair) revealed: 1.with torch.cuda.graph(...)unconditionally callsgc.collect()(~40 ms × 8) andtorch.cuda.empty_cache(), flushing 50+ GiB of warm caching-allocator blocks 8×/pair and causing964.5 ms cudaMalloc+840.3 ms cudaFreethrashing in Refine forward/backward. 2.torch.set_default_device("cuda")placed all 800AdamWstate["step"]tensors on CUDA, triggering 1,600 synchronousaten::item->cudaStreamSynchronizestalls per optimizer step (~128 ms/pair). 3.img_latent_lengthslist comprehension on CUDA tensor triggered 8 synchronousaten::item+aten::is_nonzerostalls. 4.fsdp2_rollout_contextandref_modelunsharded/resharded all 27 frozenSiglipEncoderLayers every step (79 mson Refine + wasted AllGathers on Gen). 5. Refine ran redundantvae_transform/vit_transform4× on identicalinput_imgs,forward_cache_update_vae(M=4104) andforward_cache_update_vit(M=2312) on 4 identical inputs, and Step-0cfg_texton 4 identical initial latents. 6. 3×–4× redundantImage.fromarray(img[i])copies (72 msGen +117 msRefine GPU idle gaps) delayedreward_fnHTTP submission on Gen's reward-server-bound critical path. ### Changes (OPT_ROLLOUT_V2=1,OPT_TRAIN_V2=1,OPT_AC_BUDGET_GIB=42.0) -modeling/bagel/qwen2_navit.py:StaticKVCache.broadcast_slot0()&_all_slots_identical;StaticFlowKVWorkspace.step0_view();num_seqs >= 1+forced_text_bwinQwen2Model.forward_inference;shared_l0remainder handling inforward_flow_branch_fast; expanded_KV_CAT_SAFE_Mwith(10, 18, 578, 1024, 1026, 5120, 9216)(all verified N0). -modeling/bagel/bagel.py: dedupedtransforms(image)inprepare_vit_images/prepare_vae_images;dedup_b1=Trueinforward_cache_update_vae&forward_cache_update_vit(broadcasting fromactual_start = int(past_key_values.seq_lens[0].item())to match upstreamStaticKVCachewrite offset!); Stepi=0cfg_textB=4->1via zero-copyws_cfg_step0(B=5Gen,B=9Refine withcfg_text_last=True); Decodeuse_v2using a persistent anchored 64 MiBgraph_pool+ directg.capture_begin/g.capture_end(zerogc.collect(), zeroempty_cache()except< 512 MiBOS-VRAM guard forcudaGraphInstantiate), 1-time warmup per(device, num_active), and immediate capture ((max_length - step) >= 3). -train/rollout_controller.py:dedup_b1orchestration & skipprepare_vit_imageson_cached_vit_embedshit; single pinned CPU D2H copy indecode_image; singleImage.fromarrayper sample; earlyreward_submit_fnright afterdecode_image; CPUloss_info['_img_latent_lengths']. -train/fsdp2_utils.py:apply_fsdp2_with_activation_checkpointing(..., skip_vit=True)(ignored_params=set(model.vit_model.parameters())) +_vit_bf16_cast_pre_hookonSiglipEncoderLayer(matching FSDP2cast_forward_inputs=Trueduring training/ref and bypassed duringfsdp2_rollout_context). -train/online_rl.py: unsharded shared bf16 frozenvit_modelacrossfsdp_model&ref_model;with torch.device("cpu"): optimizer.step(); CPU_img_latent_lengths; batchedavg_vals.tolist(); fused 2-element mem statsall_reduce. ### Bugs Caught & Fixed - PaddedB=4decode graph diverged from exactnum_activeafter EOS dropout -> switched to exact-num_activegraphs in persistent anchored pool. -broadcast_slot0initially usedkey_values_lens[0](1026) instead ofpast_key_values.seq_lens[0](0, matching upstreamupdate_context_imagewhich syncsseq_lensafter both VAE and ViT) -> fixed toactual_start = int(past_key_values.seq_lens[0].item()). -cudaGraphInstantiateing.capture_end()hit CUDA OOM in deterministicrecordmode whenexpandable_segments:Truereserved 135.9 GiB leaving< 16 MiBOS VRAM -> fixed with persistent anchored 64 MiB pool +< 512 MiBmem_get_infoguard + OOM retry.
6.8 hRound 7 Results
- Fullcheck(/tmp/check-r7e/check.json): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[10.6065, 11.3325, 11.4275]s/step (mean11.1222s/step vs ref23.3224s/step; earlier r7c/r7d timing runs measured2.1225x/2.1173x) - Window ratios:[2.1570, 2.0819, 2.0560]->speedup = 2.0983- Peak allocated memory:115.11GiB (timing) /114.71GiB (record) — 4.17 GiB lower than Round 6! - Committed to/submission/r3(opt, commit8a6046e) and activated in/submission/switches.json. ---
7.4 hRound 8: Rollout `GU_cat`, FSDP2 `keep_unsharded` + Dynamic Reshard, Zero-Duplicate Training Autograd & Single-Pass Bitwise-Exact CUDA AdamW (`OPT_ROLLOUT_V3=1`, `OPT_TRAIN_V3=1`)
- Start: 2026-11-20 10:57 UTC - End: 2026-11-20 11:33 UTC ### Target & Findings - Probes (probe_r8.py,test_r8_kernels.py,test_r8_e2e.py): 1. HorizontalGU_cat(cat([W_gate, W_up]),3584 -> 37888): 100% bitwise N0 across allM ∈ {1..12288}(det=False/True), and+33.5–38.3 us/layerfaster at smallM ∈ {1, 2, 3, 4, 8, 16, 24}(lifts SM utilization from 99/132 = 75% to full GPU saturation across 26,000+ Decode GEMMs/pair). 2. FSDP2keep_unsharded=Trueacross Rollout -> Training Forward + Genreshard_after_forward=False: FSDP2'sunshard()is a no-op whenself.is_unshardedis alreadyTrue, andinit_unsharded_param()setsrequires_grad=self.sharded_param.requires_gradeven underno_grad(). Keepingfsdp_modelunsharded out offsdp2_rollout_contexteliminates allfsdp_modelforward AllGathers on BOTH Gen and Refine for+0.0 GiBpeak VRAM on Refine (since Layerkreshards immediately after Layerkforward, while"none"layers sit at the end), and disablingreshard_after_forwardon Gen eliminates Gen backward AllGathers too. 3. Zero-Duplicate Training Autograd (FusedSplitAttnOProjFn+FusedSwiGLUDownProjFn+FusedAddRMSNorm3584TrainFn): -FusedSplitAttnOProjFnreusesattn_outalready saved byflex_attentioninstead of saving duplicate(ao_u, ao_g)foro_proj/o_proj_moe_gen(-0.26 GiB * scaleper layer across all 28 layers =-6 GiBon Refine!). -FusedSwiGLUDownProjFnrecomputesa = bf16(silu(g) * u)insideswiglu_bwd_with_a_bf16(1 extra register mul + write), droppingastorage (-1.373 GiB * scaleper"none"layer ->upgrade_no_acshrinks from4.45 -> 3.05 GiB * scale), upgrading ~8 more Refine layers from"mlp_only"to"none". -FusedAddRMSNorm3584TrainFnfuses both forwardres + deltaadd + RMSNorm and backwarddx + dh_outadd insidermsnorm_3584_bwd_add_bf16. 4. Single-Pass Bitwise-Exact Multi-Tensor FP32 AdamW + Fusedclip_coef(r3_fused_ops.fused_adamw_step_fp32): Replaces 7 separate PyTorch_foreach_*passes (284 GBHBM traffic +14.2 GBexp_avg_sq_sqrttemp buffer =83.08 ms/step) with a single pass (99.4 GB,4.0 TB/seffective HBM3e =24.71 ms/step+4.42 msget_total_norm=29.13 ms/step, saving107.9 ms/pair, 0 bit diffs across clipped/unclipped steps and heterogeneousstate['step']groups). ### Changes (OPT_ROLLOUT_V3=1,OPT_TRAIN_V3=1,OPT_AC_BUDGET_GIB=52.0) -modeling/bagel/csrc/fused_ops.cu: added 4 bitwise-exact CUDA kernels (fused_swiglu_gu_bf16,fused_swiglu_bwd_with_a_bf16,add_rmsnorm_3584_fwd_rstd_bf16/rmsnorm_3584_bwd_add_bf16,fused_adamw_step_fp32); rebuiltr3_fused_opsin/opt/candidate-env. -modeling/bagel/opt_kernels.py: addedFusedAddRMSNorm3584TrainFn,FusedSplitAttnOProjFn,FusedSwiGLUDownProjFn. -modeling/bagel/qwen2_navit.py:_GU_CAT_SAFE_M-guarded_rollout_wgu+fused_swiglu_gu_bf16in Decode, Flow text MLP, and Prefill; wired V3 autograd functions and updated AC cost model (cost_mlp=1.18,upgrade_no_ac=3.05) inforward_train_split/forward_train. -train/fsdp2_utils.py:fsdp2_rollout_context(..., keep_unsharded=False)+ temporary_rollout_wgucreation/cleanup;fsdp2_reshard_all,fsdp2_set_reshard_after_forward,clip_grad_norm_fsdp2_no_mul,fast_adamw_step_context(with per-step_valgrouping for Refine-only connector params). -train/rollout_controller.py&train/online_rl.py: wiredkeep_unsharded=train_v3, dynamic Gen/Refinereshard_after_forward, post-backwardfsdp2_reshard_all, and fused clip+AdamW step.
7.4 hRound 8 Results
- Single-GPU + 2-rank FSDP2 E2E bitwise tests (test_r8_kernels.py,test_r8_e2e.py): 0 bit diffs across all 3ac_modes, DecodeGU_cat, and 3 mixed Gen/Refine FSDP2 steps (det=False/True). - Fullcheck(/tmp/check-r8/check.json): PASS (N0 bitwise identical: 3200/3200 tensors, 235/235 reward requests) - Windows[10-11, 12-13, 14-15]:[10.4784, 10.8956, 11.0679]s/step (mean10.8140s/step vs ref23.3224s/step; Gen6.40–7.11s, Refine13.42–15.06s) - Window ratios:[2.1834, 2.1654, 2.1229]->speedup = 2.1572- Peak allocated memory:121.77GiB (timing) /121.76GiB (record) — still 9.0 GiB below reference! - Committed to/submission/r3(opt, commit10ae10d) and activated in/submission/switches.json. ---
7.4 hCurrent Summary (updated after Round 8)
- Active switch file (/submission/switches.json):{"environment": {"PYTORCH_ALLOC_CONF": "expandable_segments:True", "OPT_DECODE_GRAPH": "1", "OPT_DIFFUSION_FAST": "1", "OPT_TRAIN_FAST": "1", "OPT_AC_BUDGET_GIB": "52.0", "OPT_FUSED_KERNELS": "1", "OPT_TRAIN_FUSED_NORM": "1", "OPT_OVERLAP_FSDP_REWARD": "1", "OPT_ROLLOUT_FAST": "1", "OPT_ROLLOUT_V2": "1", "OPT_TRAIN_V2": "1", "OPT_ROLLOUT_V3": "1", "OPT_TRAIN_V3": "1"}}- Latest full check:/tmp/check-r8/check.json— PASS (N0),speedup = 2.1572(10.8140vs23.3224s/step, peak mem121.77GiB) - Breakdown of gains: - Round 1 (OPT_DECODE_GRAPH=1):23.3224 -> 18.6301s/step (1.2520x, saves ~4.69 s/step) - Round 2 (OPT_DIFFUSION_FAST=1):18.6301 -> 15.6976s/step (1.1868x incremental, 1.4861x cumulative, saves ~2.93 s/step) - Round 3 (OPT_TRAIN_FAST=1):15.6976 -> 15.0762s/step (1.0412x incremental, 1.5470x cumulative, saves ~0.62 s/step, frees 18.6 GiB HBM) - Round 4 (OPT_FUSED_KERNELS=1):15.0762 -> 12.6213s/step (1.1945x incremental, 1.8492x cumulative, saves ~2.45 s/step) - Round 5 (OPT_TRAIN_FUSED_NORM=1,OPT_OVERLAP_FSDP_REWARD=1):12.6213 -> 11.7253s/step (1.0764x incremental, 1.9922x cumulative, saves ~0.90 s/step) - Round 6 (OPT_ROLLOUT_FAST=1):11.7253 -> 11.4189s/step (1.0268x incremental, 2.0460x cumulative, saves ~0.31 s/step) - Round 7 (OPT_ROLLOUT_V2=1,OPT_TRAIN_V2=1):11.4189 -> 11.1222s/step (1.0267x incremental, 2.0983x cumulative, saves ~0.30 s/step, frees 4.17 GiB HBM) - Round 8 (OPT_ROLLOUT_V3=1,OPT_TRAIN_V3=1,AC=52.0):11.1222 -> 10.8140s/step (1.0285x incremental, 2.1572x cumulative, saves ~0.31 s/step) - Negative / dead-end directions: -time_embedder(t.unsqueeze(0)).expand(4096, -1): cuBLAS tile drift7.63e-6vs M=4096 (non-N0, abandoned). - Diffusion flow CUDA Graph: only 4.35 ms/pass over eager Split+PreKV+Triton, outweighed by ~280ms×3 capture cost/step (abandoned). -flex_attention = torch.compile(flex_attention, dynamic=True):max_diff=9.77e-4vs static compile (non-N0, abandoned). -QKVhorizontal GEMM concat atM=1..8: non-N0 due to cuBLAS split-K tile mismatch (abandoned). -KV_cathorizontal concat atM ∈ [100..200]: 1–2 ULP cuBLAS mismatch (whitelisted to_KV_CAT_SAFE_M). -SHARD_GRAD_OPonfsdp_model:FULL_SHARDAllGatherduring forward/backward is already 95–99% overlapped (< 23 msexposed), so HBM is far better spent eliminating AC layers.