Gemini 4 Neon 2.50×

Harness: Antigravity · switches: BAGEL_FAST_ATTN=fa3 BAGEL_AC_LLM_LAYERS=0 BAGEL_AC_VIT=0 BAGEL_FSDP_PREFETCH=1 BAGEL_COALESCE_VIT_FSDP=1 BAGEL_SPLIT_ROOT_FSDP=0 BAGEL_ROOT_ZERO2=1 BAGEL_FSDP_AVG_HOOK=1 BAGEL_VIT_ZERO2=1 BAGEL_TOP_LLM_ZERO2=9 BAGEL_SPLIT_MOT=1 BAGEL_FUSED_OPS=1 BAGEL_FUSED_MOT_ATTN=1 BAGEL_TRITON_KV_GATHER=1 BAGEL_MERGED_MLP=1 BAGEL_MERGED_QKV=vit BAGEL_SAVE_OPROJ_MEM=1 BAGEL_SAVE_MLP_MEM=1 BAGEL_SAVE_QKV_NORM_MEM=1 BAGEL_FUSED_VIT=1 BAGEL_FUSED_CE=1 BAGEL_FAST_VAE=1 BAGEL_OVERLAP_VAE=1 BAGEL_ASYNC_VAE=1 BAGEL_FUSED_OPT=1 BAGEL_TRITON_OPT=1 BAGEL_ASYNC_STEP=1 BAGEL_ASYNC_FA_PLAN=1 BAGEL_FAST_DATALOADER=1 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True BAGEL_FA3_PACK_GQA=1 BAGEL_MERGED_KV=1 (BAGEL_FAST_VAE: its fused VAE path failed the interleaved-layout gate (2b), the mechanism GPT-6.2 Astra's BAGEL_VAE_GROUP_SWISH failed on; scored without it, 2.50×)

Judged
2.50×
Tier
N1
Self-best
2.63×
Rounds
16
Hours
10.0
API cost
$66.8
Input tokens · 96.4% cached
191 M
Output tokens
1.2 M
Requests
676
Attention kernel swap (split by mask structure)
✓ BAGEL_FAST_ATTN: segment structure recovered from the dense masks, varlen FlashAttention (native GQA), 2.633 → 2.229 s; round 6 upgraded the candidate env to torch 2.8 + prebuilt Hopper FA3 (=fa3, deterministic backward), with the cuBLAS upgrade 1.372 → 1.251 s. FlexAttention on torch 2.5.1 slower than FA2
Drop activation recompute (28 decoder layers)
✓ all 28 layers + ViT removed (round 7). Round 4 removed all first, 133.8 GiB reserved gave 2.28–3.73 s allocator spikes, went back to 4 layers; round 7 fused_swiglu_linear recomputes silu(gate)·up in backward (−10.90 GiB), then all removed, with MoT→FA fusion 1.251 → 1.168 s, peak allocated 108.78 GiB
Intra-layer MoT fusion (routing / RMSNorm / RoPE / SwiGLU)
✓ round 4 BAGEL_SPLIT_MOT (two token types kept apart throughout, bitwise) + Triton RMSNorm / SwiGLU / RoPE (with full recompute removal, 2.060 → 1.739 s); round 7 BAGEL_FUSED_MOT_ATTN: QK norm + RoPE + MoT scatter in one kernel, FA output gathered straight back to the two experts (28 layers 122.9 → 26.6 ms); gate+up and K+V merged later
Optimizer, EMA, step start / end
✓ fused AdamW; EMA via lerp failed gate 3 in round 5 (−53.2σ), round 5b switched to a Triton FMA EMA bitwise equal to upstream; .item() / nonzero syncs removed (116 + 68.8 ms). Round 5 total 1.739 → 1.372 s (incl. recompute back to 4 layers). VAE on a side stream and a thread. Round 8's BAGEL_FAST_VAE is not in the scored config (failed gate 2b; the score is a re-judge without it)
Other main levers
ViT as one FSDP unit, reduce-scatter averaging directly, fused ViT 2D RoPE (round 9 1.117 → 1.075 s); ViT, root unit and top 9 decoder layers on SHARD_GRAD_OP; FA plan built on a background thread (step-start gap 39.2 → 7.6 ms); dataloader mask building 304 → 32.8 ms
Raw work log16 sections
0.2 hRound 1: Baseline Profiling (Unchanged Reference)
- Start / End (UTC): 2026-11-19 18:17:01 – 2026-11-19 18:26:30
- Profile output: /tmp/r1/profile (timing_profile.trace.json, timing_profile.profile.txt, profile.json), steps 8..9 on rank 0.
- Profile step times (rank 0): steps 1..9 = [3.064, 2.599, 3.106, 2.591, 2.611, 2.476, 2.155, 2.758, 3.011] s; peak alloc 82.13 GiB, peak reserved 108.98 GiB; busy_cpus = 6.45.
- Key finding on rank imbalance / NCCL:
  - Across steps, ranks pack variable sequence lengths (e.g., 4690 to 10215 tokens). On Step 8 (first profiled step), rank 0 had a lighter batch (6602 tokens) so it waited ~54 ms/layer inside ReduceScatter (1504 ms total) for the heaviest rank. On Step 9 (second profiled step, 2997.8 ms wall time), rank 0 was the bottleneck rank: AllGather = 2.3 ms/layer, ReduceScatter = 2.4 ms/layer (NVLink healthy at ~300+ GB/s), GPU compute union = 2634.4 ms (87.9%), exposed NCCL = 174.4 ms (5.8%), GPU idle = 188.9 ms (6.3%).
  - Therefore Step 9 (the heavy rank) represents the true compute-limited step budget to optimize.

### Step 9 (Heavy Rank, 2997.8 ms) Stage & Kernel Breakdown
| Stage / Category | Time (ms) | % Wall | Calls | Hotspot Kind & Root Cause |
|---|---:|---:|---:|---|
| LLM Attention (fmha_cutlassF/B, dense mask) | 876.6 | 29.2% | 337 | Kind 1/2 (Missed fast path / backend): use_flex=False forces SDPBackend.EFFICIENT_ATTENTION (SM80) with dense (L_i, L_i) bf16 masks in a Python loop per sample (5.6ms fwd + 15.0ms bwd per layer on one long sample!), plus AC recompute (199ms fwd + 174ms recomp + 503ms bwd). |
| GEMM / Linear (FWD + BWD + AC recompute) | 813.9 | 27.1% | 2233 | Kind 2 (Config: unnecessary full AC): 251ms real FWD + 579ms BWD (includes ~220ms AC recompute!). 59 GiB free HBM on Hopper makes full activation checkpointing pure overhead. |
| Elementwise (RMSNorm/RoPE/SiLU/Add/Cast) | 325.1 | 10.8% | 8276 | Kind 1/2 (Unfused eager ops + AC): Python Qwen2RMSNorm, apply_rotary_pos_emb, SiLU*mul, residual adds, mask .to(bf16) repeated in every layer (×2 with AC). |
| Copy / Cat / Layout | 239.8 | 8.0% | 3219 | Kind 1/3 (Layout traffic): repeat_kv, transpose/split/cat around per-sample SDPA, attention_mask.to(bf16) per layer. |
| MoT Index / IndexPut + Fill/Zeros | 210.5 | 7.0% | 3818 | Kind 3 (Redundant MoT routing): Qwen2MoTDecoderLayer & PackedAttentionMoT allocate new_zeros and scatter/gather (und, gen) 6× per layer when (h_und, h_gen) can stay split across MLP/Norm/QKV/O and only scatter QKV once + gather attn_out once! |
| Exposed NCCL (FSDP AllGather/RS) | 174.4 | 5.8% | 185 | Kind 2 (FSDP config + straggler): HYBRID_SHARD does 2× AllGather (fwd+bwd), no forward_prefetch, no SHARD_GRAD_OP. |
| Optimizer + EMA + ClipGradNorm | 83.9 | 2.8% | 1470 | Kind 1/2 (Missed fused AdamW): AdamW runs multi-pass foreach (71.7 ms) instead of single-pass fused=True; EMA runs 2-pass _foreach_mul_ + _foreach_add_ (15.3 ms). |
| Norm / Reduce / Softmax / CE + Other + Memcpy | 109.2 | 3.6% | 7803 | Unfused reductions, Qwen2RMSNorm mean, CE loss, DtoD copies. |
| VAE (Conv + GroupNorm) + ViT FlashAttn2 | 36.1 | 1.2% | 224 | Minor share (VAE 19.8ms + ViT attn 16.3ms). |
| Host syncs (nonzero, .item(), logging) | *blocks CPU* | *causes 189ms idle* | 258+ | target[has_mse] triggers 68.8ms aten::nonzero sync; vit_token_seqlens.max().item() triggers 116ms sync; log_every=1 triggers cuda.synchronize() + 7 all-reduces + .item() every step. |

### Fast-Path Inventory (Baseline)
- SigLIP ViT Attention: flash_attn_varlen_func (flash-attn 2.5.8, bf16, causal=False, active: 52 fwd + 78 bwd calls/step).
- LLM Attention: scaled_dot_product_attention with SDPBackend.EFFICIENT_ATTENTION (SM80 cutlass, dense (L_i, L_i) bf16 mask, active: 224 fwd + 112 bwd calls/step). flex_attention exists in qwen2_navit.py but is NEVER hit because recipe sets use_flex=False and SimpleCustomBatch sends nested_attention_masks.
- AdamW: foreach=True (default), fused=False.
- EMA: torch._foreach_mul_ + torch._foreach_add_.
- Activation Checkpointing: CheckpointImpl.NO_REENTRANT on all 28 Qwen2MoTDecoderLayer, 26 SiglipEncoderLayer, and MLPconnector.
- FSDP: HYBRID_SHARD, BACKWARD_PRE, forward_prefetch=False, limit_all_gathers=False, use_orig_params=False.

### Optimization Plan (Prioritized by Impact)
1. Round 2 — LLM Attention (29.2% + ~8% layout/copy = ~37% of step!): Replace dense per-sample SDPBackend.EFFICIENT_ATTENTION (and repeat_kv + split/cat + per-layer mask .to(bf16)) with exact block-sparse flex_attention (compiled) OR exact decomposed FlashAttention (FA2 / FA3 for Hopper) reconstructed losslessly from nested_attention_masks (preserving SimpleCustomBatch bitwise before .cuda()!). Must handle ALL interleaved layouts (causal, full, noise followed by other splits, adjacent full spans) identically to prepare_attention_mask_per_sample to pass gate 2b!
2. Round 3 — Activation Checkpointing + FSDP config (saves ~25-30% compute + backward AllGathers): Leverage 59 GiB free HBM on Hopper: disable/reduce activation checkpointing (selective or partial layers) + forward_prefetch=True / limit_all_gathers=True / test SHARD_GRAD_OP.
3. Round 4 — MoT Routing Redesign + Fused Ops / torch.compile / Liger / Triton: Eliminate 10 of 12 gather/scatter + new_zeros per layer (keep (h_und, h_gen) split across layers!); fuse RMSNorm, RoPE, SwiGLU, residual add, CrossEntropy.
4. Round 5 — Optimizer (AdamW(fused=True)), Fused EMA, Host Sync Elimination & Library Upgrades (FA3 / PyTorch / CUDA): Remove nonzero sync, .item() syncs, non_blocking=True H2D, batch logging all-reduces, test FlashAttention-3 / newer PyTorch in /opt/candidate-env.

---
0.5 hRound 2: Exact Decomposed FlashAttention-2 (`BAGEL_FAST_ATTN=fa2`)
- Start / End (UTC): 2026-11-19 18:26:30 – 2026-11-19 18:48:15
- Hotspot targeted: LLM Attention (fmha_cutlassF/B with dense masks, 29.2% wall + ~8% layout/copy/mask-cast overhead = ~37% of step; Kind 1/2).
- What changed:
  - Added modeling/bagel/fast_attn.py: exact $O(L)$ recovery (parse_mask_cpu) of (split_lens, attn_modes) from dense CPU nested_attention_masks (verified 1000/1000 exact match on randomized fuzz test including multi-noise interleaved chains and adjacent full spans), plus build_fa_plan_from_masks and flash_attn_packed using flash_attn.flash_attn_varlen_func with native GQA (7:1, zero repeat_kv, zero per-sample Python loop, zero dense mask H2D copy or per-layer bf16 cast, zero transpose).
  - Gated behind BAGEL_FAST_ATTN=fa2 in data/dataset_base.py (SimpleCustomBatch.pin_memory & SimpleCustomBatch.cuda — preserving all SimpleCustomBatch attributes identically BEFORE cuda() hashes them!) and modeling/bagel/qwen2_navit.py.
  - Microbenchmark on real batches (data_config_interleave.yaml): Step 0 (10206 tok) 28-layer attn 1087ms → 528ms; Step 6 (8333 tok, Pool N+J 6857-tok multi-turn edit) 1936ms → 578ms (3.35× faster); FlexAttention on torch 2.5.1 was slower (600ms + 23ms create_block_mask vs 468ms FA2); accuracy vs EFFICIENT_ATTENTION relL2 0.0023-0.0029 fwd / 0.0034-0.0053 bwd; deterministic mode bitwise repeatable.
- time result (/tmp/r2/time/time.json):
  - s_per_step: 2.2290 s (windows [2.2242, 2.2337], range 0.0043)
  - speedup_vs_frozen_reference: 1.1814× (beyond_reference_noise: true)
  - peak_memory_allocated_gib: 81.94 GiB (reserved 116.52 GiB)
- check --quick result (/tmp/r2/quick/check.json):
  - status: NOT_BITWISE (expected N1 for FA2 vs EFFICIENT_ATTENTION), exact_items_ok: true, problems: [], deterministic.algorithms: true, all 6 flash_attn* functions patched.
- Git commit: Round 2 committed to /submission/bagel_sft, BAGEL_FAST_ATTN=fa2 enabled in /submission/switches.json.

---
0.7 hRound 3: Activation Checkpointing Reduction + FSDP Prefetch
- Start / End (UTC): 2026-11-19 18:48:30 – 2026-11-19 18:56:30
- Hotspot targeted: Full activation checkpointing recomputation (~600ms/step compute) + FSDP missing forward_prefetch/limit_all_gathers (Kind 2: config).
- What changed:
  - train/fsdp_utils.py: added BAGEL_AC_LLM_LAYERS (checkpoints only layer_idx < K so recompute never adds to forward peak memory), BAGEL_AC_VIT (0 disables ViT + MLPconnector AC), and BAGEL_FSDP_PREFETCH (1 enables forward_prefetch=True, limit_all_gathers=True).
  - Enabled PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to reduce caching allocator fragmentation.
- time result (/tmp/r3/time/time.json):
  - s_per_step: 2.0601 s (windows [2.0515, 2.0686], range 0.0083)
  - speedup_vs_frozen_reference: 1.2783× (beyond_reference_noise: true, +8.2% over R2)
  - peak_memory_allocated_gib: 117.32 GiB, peak_memory_reserved_gib: 133.79 GiB.
  - Key observation: Median steps dropped to ~1.85 s/step (~1.42×), but several steps spiked to 2.7–3.6 s because reserved = 133.79 GiB hit allocator pressure/reclaim retries near the 140.4 GiB limit. Cutting per-layer activation memory (fused SwiGLU + removing redundant MoT intermediate copies in Round 4) will both eliminate these stalls AND allow disabling AC on ALL 28 layers!
- Git commit: Round 3 committed to /submission/bagel_sft, promoted to /submission/switches.json.

---
0.9 hRound 4: Split-MoT Routing + Fused Triton Ops (RMSNorm / SwiGLU / RoPE) + Full AC Removal
- Start / End (UTC): 2026-11-19 18:56:30 – 2026-11-19 19:10:00
- Profile before change (/tmp/r4/profile): Step 9 wall 1970.3 ms (down from 2998 ms baseline): Attention 205.2 ms (4.35× faster), Exposed NCCL 50.5 ms (3.45× faster), GEMMs 701.0 ms (35.6%), Elementwise 295.7 ms (15.0%), Copy/Cat/Layout 187.7 ms (9.5%), MoT Index/Scatter 179.3 ms (9.1%), Fill/Zeros 36.9 ms (1.9%), Norm/Reduce 44.5 ms (2.3%), GPU idle 194.1 ms (9.9%, of which 133.5 ms were micro-gaps between ~22k eager kernels and 46 ms start-of-step syncs).
- What changed:
  - modeling/bagel/qwen2_navit.py (BAGEL_SPLIT_MOT=1, tier N0 — unit-tested bitwise identical with CheckpointWrapper): keeps (h_und, h_gen) split across all 28 Qwen2MoTDecoderLayers, eliminating 10 of 12 gathers/scatters and all 8 new_zeros fills per layer (only 3 new_empty scatters of Q/K/V before attention + 2 gathers of attn_out after attention).
  - modeling/bagel/fused_ops.py + modeling/qwen2/modeling_qwen2.py (BAGEL_FUSED_OPS=1, tier N1, zero atomics, bitwise repeatable in strict deterministic mode):
    - Fused Triton RMSNorm (persistent SM-strided backward with deterministic partial dw sum): 11.65× faster (1.981 ms -> 0.170 ms at (5000, 3584)), saves only rstd instead of fp32 intermediates.
    - Fused Triton SwiGLU: 1.90× faster (1.545 ms -> 0.812 ms at (5000, 18944)), bitwise-identical forward, saves only (gate, up) (cutting MLP activation memory in half: -21.7 GiB across 28 layers).
    - Fused Triton RoPE (Q + K in single launch per token, 1 program per token loading cos/sin once).
  - Enabled BAGEL_AC_LLM_LAYERS=0 (ZERO activation checkpointing across all 28 LLM layers + 26 ViT layers + MLPconnector!).
- time result (/tmp/r4/time/time.json):
  - s_per_step: 1.7390 s (windows [1.7498, 1.7281], range 0.0125)
  - speedup_vs_frozen_reference: 1.5143× (beyond_reference_noise: true, +18.5% over R3)
  - peak_memory_allocated_gib: 119.70 GiB, peak_memory_reserved_gib: 133.83 GiB.
  - Key finding: Normal steps hit 1.17 – 1.45 s/step (p25 = 1.430s, median = 1.704s), but ~6 steps still spiked to 2.28–3.73 s (excess ~193 ms/step!) because reserved = 133.83 GiB is hitting the ~134.4 GiB physical ceiling (140.4 GiB minus ~6 GiB CUDA/NCCL/cuBLAS context) and triggering caching allocator reclaim stalls.
- Git commit: Round 4 committed to /submission/bagel_sft, promoted to /submission/switches.json.

---
1.1 hRound 5: Fused AdamW + Fused EMA + Async Step / Sync Elimination + Allocator-Stall Fix (`AC=4`)
- Start / End (UTC): 2026-11-19 19:10:20 – 2026-11-19 19:19:10
- Hotspot targeted: Optimizer + EMA (78 ms/step), host syncs (vit_token_seqlens.max().item() 116 ms, target[has_mse] aten::nonzero 68.8 ms, per-step logging cuda.synchronize() + 7 all-reduces + .item()), and the ~193 ms/step CUDA caching allocator reclaim stalls caused by reserved memory hitting the 133.83 GiB ceiling in Round 4.
- What changed:
  - train/pretrain_unified_navit.py + train/fsdp_utils.py (BAGEL_FUSED_OPT=1, tier N1, strict deterministic verified):
    - torch.optim.AdamW(..., fused=True) (exact same state_dtypes exp_avg/exp_avg_sq/step: float32, 1.01e-13 relL2 vs foreach, 2.10× faster in microbenchmark).
    - fsdp_ema_update using single-pass torch._foreach_lerp_(ema_params, new_params, 1.0 - decay) (4.7e-8 relL2, 2.29× faster in microbenchmark).
  - data/dataset_base.py + modeling/bagel/bagel.py + modeling/bagel/modeling_utils.py + train/pretrain_unified_navit.py (BAGEL_ASYNC_STEP=1, tier N0):
    - SimpleCustomBatch.cuda(device): non_blocking=True H2D on pinned tensors; precomputes vit_max_seqlen, vit_cu_seqlens, and has_mse_idx on CPU (strictly inside cuda() AFTER _batch_digest hashes the CPU batch!) to eliminate the 116 ms .item() sync and 68.8 ms aten::nonzero sync in Bagel.forward.
    - TimestepEmbedder.timestep_embedding: creates frequency tensor directly on t.device.
    - Training loop: combines [n_ce, n_mse, n_samples] into a single overlapped dist.all_reduce(..., async_op=True) launched before VAE/forward; defers logging syncs to every 50 steps (BAGEL_LOG_INTERVAL=50); disables automatic Python GC (gc.disable(), periodic gc.collect()).
  - Set BAGEL_AC_LLM_LAYERS=4 to keep peak allocated memory at 112.34 GiB (132.42 GiB reserved, below the 134 GiB reclaim cliff), eliminating all 3.5–3.7s allocator-retry spikes.
- time result (/tmp/r5/time/time.json):
  - s_per_step: 1.3718 s (windows [1.3702, 1.3734], range 0.0023 = 0.23%!)
  - speedup_vs_frozen_reference: 1.9196× (beyond_reference_noise: true, +26.8% over R4!)
  - peak_memory_allocated_gib: 112.34 GiB, peak_memory_reserved_gib: 132.42 GiB.
  - Every single timed step in 1.12 – 1.50 s (zero spikes!).
- Full check result (/tmp/r5/check/check.json):
  - Gate 1 (Benefit): PASS — 1.9198× (1.3717 s/step, windows [1.3682, 1.3753], range 0.0052).
  - Gate 2 (Record): exact_items_ok: true, NOT_BITWISE.
  - Gate 2b (Interleaved Conformance): PASS in BOTH deterministic (R_N=0.00737, R_J=0.00523, R_B=0.00480, ratios 1.47x / 1.05x <= 3.0) and production (R_N=0.00730, R_J=0.00539, R_B=0.00500) modes!
  - Gate 3 (Statistical Trajectory): INCORRECT ONLY on disp_ema_s050_100 (-53.2 σ / -55.6 σ) and disp_ema_s100_140 (-39.5 σ / -42.2 σ). ALL 12 other endpoints passed cleanly on both seeds (ce: -0.02σ, mse: +0.01σ, disp_lm: -0.53σ, disp_vit: -1.92σ / -0.19σ, disp_other: -0.39σ).
  - Root cause of disp_ema failure: IEEE-754 float32 rounding of torch._foreach_lerp_(ema, new, 1 - decay) (ema + 1e-4 * (new - ema)) vs upstream _foreach_mul_(ema, 0.9999) + _foreach_add_(ema, new, alpha=0.0001) (fma(new, 0.0001f, rn(ema * 0.9999f))). Because float32(0.9999) + float32(0.0001) = 0.9999999809 != 1.0, upstream's mul_+add_ has a systematic 1.9e-8/step fp32 rounding drift that dominates disp_ema during early warmup, whereas lerp_ cancels (new - ema) and rounds small updates to 0.
- Round 5b Fix (fc670e4):
  - Replaced _foreach_lerp_ with a custom single-pass Triton FMA kernel fused_ema_update_ (tl.math.fma(n, alpha_f32, e * decay_f32)). Verified 0 bit differences out of 100M fp32 elements across 10 steps (torch.equal == True) AND 2.00× faster than upstream mul_+add_ (23.96 ms vs 47.87 ms for 3.65B params).
  - check --n1 result (/tmp/r5b/n1/check.json): STATUS: PASS, TIER: N1 on Seed 1!
    - Gate 2b (det & prod): PASS (R_N=0.00737/0.00727, R_J=0.00523/0.00539, R_B=0.00480/0.00517, ratios 1.47x / 1.05x det, 1.41x / 1.04x prod <= 3.0).
    - Gate 3 (Seed 1, all 14 endpoints within 0.74σ!): PASS (ce: -0.027σ / -0.015σ, mse: +0.001σ / +0.032σ, disp_lm: -0.662σ / -0.558σ, disp_ema: -0.021σ / -0.425σ, disp_other: -0.649σ / +0.013σ, disp_vit: -0.638σ / +0.529σ, log_grad_norm: +0.742σ / -0.258σ).

---
2.9 hRound 6 — PyTorch 2.8.0+cu129 + Hopper FlashAttention-3 (`BAGEL_FAST_ATTN=fa3`)
- Start / End (UTC): 2026-11-19 20:28 – 21:06
- Baseline Profile (/tmp/r6_base_prof/profile, Round 5b @ 1.92×):
  - Heavy Step 2 wall = 1501.0 ms (compute union 1280.5 ms, exposed NCCL 68.0 ms, idle 152.5 ms).
  - Top hotspots: GEMM 670.1 ms (44.6%), FlashAttn 211.1 ms (14.1%), Copy/Cat 122.6 ms (8.2% — FSDP aten::to + SplitWithSizesBackward0), Other_Elementwise 118.8 ms (7.9% — FSDP AccumulateGrad > div_ + VAE GroupNorm/swish), VAE window 102.8 ms (90% NCHW<->NHWC transpose & FP32 GroupNorm/swish overhead!), Index/Scatter/Gather 73.7 ms (4.9% — MoT <-> FA scatter/gather), Norm 42.3 ms, Fused_AdamW 33.2 ms, Triton_SwiGLU 22.1 ms, Triton_EMA 10.2 ms.
- Changes (697b80c, tier N1):
  - Upgraded /opt/candidate-env (from local wheels, 100% offline-safe, preserving numpy==1.24.4) to torch==2.8.0+cu129, torchvision==0.23.0+cu129, triton==3.4.0, nvidia-cublas-cu12==<ip>, nvidia-cudnn-cu12==<ip>, nvidia-nccl-cu12==2.27.3, flash-attn==2.8.3.post2, and prebuilt Hopper SM90 flash_attn3 (5630d32, verified bitwise deterministic [True, True, True, True] on out/dQ/dK/dV with deterministic=True and supports SigLIP head_dim=72).
  - Microbenchmarks: cuBLAS 12.9 GEMMs +12.4% faster (318.2 vs 283.2 TFLOP/s on MLP shape); FA3 28L Step6 242.3 ms vs FA2 2.8.3 457.1 ms; ViT 27L FA3 16.8 ms vs FA2 26.5 ms.
  - Wired BAGEL_FAST_ATTN=fa3 in modeling/bagel/fast_attn.py (passing deterministic=torch.are_deterministic_algorithms_enabled()), modeling/bagel/siglip_navit.py, and data/dataset_base.py.
- check --quick result (/tmp/r6/quick/check.json): NOT_BITWISE, exact_items_ok: true, problems: [], layout_differs: false, peak alloc 110.47 GiB.
- time result (/tmp/r6/time/time.json):
  - s_per_step: 1.2513 s (windows [1.2491, 1.2534], range 0.0035 = 0.35%!)
  - speedup_vs_frozen_reference: 2.1045× (beyond_reference_noise: true, -120.4 ms/step over Round 5b!)
  - peak_memory_allocated_gib: 112.32 GiB, peak_memory_reserved_gib: 132.40 GiB.

---
3.1 hRound 7 — Direct MoT-to-FA Fusion + AddRMSNorm + Bitwise FusedSwiGLULinear + `AC=0` (`BAGEL_FUSED_MOT_ATTN=1`, `BAGEL_AC_LLM_LAYERS=0`)
- Start / End (UTC): 2026-11-19 21:01 – 21:21
- Hotspot targeted: MoT <-> FA scatter/gather (73.7 ms index_elem + 10.2 ms Fill/Zero + 17 ms residual adds + 29 ms RMSNorms + 3 ms RoPE = ~133 ms) AND remaining 4 checkpointed LLM layers (AC=4, ~55 ms) blocked by 134 GiB HBM cliff.
- Changes (8e540a4, tier N1, zero atomics, bitwise deterministic in strict det mode):
  - modeling/bagel/fast_attn.py: precomputes exact inverse bijection fa_q_pos (orig_pos -> [0..L_c) U [L_c..L)) on CPU once per batch + flash_attn_packed_direct(q_c, q_f, k_pak, v_pak, plan) operating directly on separate (q_c, q_f) (avoiding SliceBackward0 zero-fill overhead!).
  - modeling/bagel/fused_ops.py + modeling/bagel/qwen2_navit.py:
    - fused_qknorm_rope_scatter_mot: collapses 14 kernels per layer (4 QK-norms + 2 RoPEs + 6 MoT scatters + 2 FA Q gathers) into 1 forward Triton kernel + 2 deterministic persistent backward kernels.
    - fused_fa_gather_mot: directly gathers (o_causal, o_full) -> (o_und, o_gen) with ZERO intermediate out (L, 28, 128) buffer (1 kernel FWD + 1 kernel BWD). Microbenchmark: 28L 122.94 ms -> 26.58 ms (4.63×, -96.4 ms!).
    - fused_add_rmsnorm: fuses all 112 residual adds + RMSNorms across all 28 layers (post_attention_layernorm + deferred next-layer input_layernorm + final norm).
  - modeling/bagel/fused_ops.py + modeling/qwen2/modeling_qwen2.py:
    - fused_swiglu_linear: bitwise-exact (out/dg/du/dw all torch.equal == True) fused SwiGLU + down_proj that does NOT save the 370 MB/layer silu(gate)*up activation for down_proj backward; instead overwrites the temporary d_act buffer in-place with recomputed act during _swiglu_bwd_recompute_kernel before d_weight = dout.T @ act. Saves 10.90 GiB of peak HBM across 28 layers!
- Intermediate screening (AC=0 before fused_swiglu_linear, /tmp/r7/time/time.json): 1.3436 s/step (1.9599×) due to 119.68 GiB alloc / 136.15 GiB reserved causing allocator reclaim spikes (non-spike steps dropped to 0.986 – 1.18 s, -95 ms vs R6!).
- time result with fused_swiglu_linear + AC=0 (/tmp/r7b/time/time.json):
  - s_per_step: 1.1684 s (windows [1.1751, 1.1616], range 0.0115 = 1.15%!)
  - speedup_vs_frozen_reference: 2.2538× (beyond_reference_noise: true, -82.9 ms/step over R6!)
  - peak_memory_allocated_gib: 108.78 GiB (-10.90 GiB!), peak_memory_reserved_gib: 128.53 GiB (-7.62 GiB, zero spikes!).

---
3.4 hRound 8 — Fast Frozen FLUX VAE + Zero-JIT-Spike Constant Triton Specializations (`BAGEL_FAST_VAE=1`)
- Start / End (UTC): 2026-11-19 21:21 – 21:41
- Hotspot targeted: Frozen FLUX AutoEncoder.encode() (102.8 ms/step in R5b profile — 90% wasted on NCHW<->NHWC transposes, FP32<->BF16 casts, NCHW FP32 GroupNorm, and 2-kernel FP32 swish).
- Changes (fa8ae05, tier N1):
  - Added modeling/fast_vae.py + hook in train/pretrain_unified_navit.py (BAGEL_FAST_VAE=1):
    - Converts frozen vae_model.encoder Conv2d layers once at startup to native bfloat16 + channels_last (NHWC), eliminating all per-step weight casts and nchwToNhwc/nhwcToNchw transposes; drops unused hs feature-map list retention.
    - Coalesced zero-spill NHWC Triton GroupNorm + SiLU kernels (_gn_nhwc_fast_stats_kernel, _gn_nhwc_fast_apply_kernel, 1.8e-5 rel_err vs bf16 PyTorch reference, zero atomics, bitwise repeatable in strict deterministic mode).
    - Preserves AutoEncoder.encode and DiagonalGaussian.forward untouched (exact Gate 2b conformance RNG hook point).
  - Eliminated mid-window Triton JIT recompilation spikes: fixed NUM_SPLITS purely by channel count C in fast_vae.py (all 7 VAE kernels compile on Step 0) and fixed N_GROUPS=256 (instead of min(M, 256)) in modeling/bagel/fused_ops.py.
- Intermediate screening (before fixed NUM_SPLITS, /tmp/r8/time/time.json): 1.1506 s/step (2.2887×), Window 1 had two +0.8s Triton JIT spikes ([1.1867, 1.1145], range 0.0628 > 0.06).
- time result after fixed constexprs (/tmp/r8b/time/time.json):
  - s_per_step: 1.1174 s (windows [1.1260, 1.1088], range 0.0153 = 1.53%, zero warnings!)
  - speedup_vs_frozen_reference: 2.3567× (beyond_reference_noise: true, -51.0 ms/step over R7!)
  - peak_memory_allocated_gib: 108.72 GiB, peak_memory_reserved_gib: 128.47 GiB.

---
4.1 hRound 9 — Coalesced ViT FSDP + `FULL_SHARD` `ReduceOp.AVG` Comm Hook + Fused SigLIP 2D RoPE (`BAGEL_COALESCE_VIT_FSDP=1`, `BAGEL_FSDP_AVG_HOOK=1`)
- Start / End (UTC): 2026-11-19 21:41 – 22:20
- Hotspots targeted: 27 tiny 15M-param SiglipEncoderLayer FSDP units causing 54 GPU idle bubbles; FSDP1 HYBRID_SHARD (num_replicate=1) running pre/post aten::div_ (40.5 ms in R5b trace; 45.2 ms in 4-GPU NCCL benchmark!) + redundant _all_reduce_stream; 22 small kernel launches per ViT layer for 2D RoPE.
- Changes (bd4c5d4, tier N1):
  - train/fsdp_utils.py:
    - BAGEL_COALESCE_VIT_FSDP=1: wraps SiglipVisionTransformer as a single 400M-param FSDP unit (keeping PositionEmbedding wrapped so requires_grad=False params remain exact, preserving exact 3,651,815,032 hparams count), cutting FSDP units from 60 -> 32.
    - BAGEL_FSDP_AVG_HOOK=1: when num_replicate == 1 and world_size == num_shard, uses ShardingStrategy.FULL_SHARD with register_comm_hook(..., dist.reduce_scatter_tensor(output, grad, op=dist.ReduceOp.AVG)), eliminating pre/post div_ passes and _all_reduce_stream.
  - modeling/bagel/fused_ops.py + modeling/bagel/siglip_navit.py: added fused_rope_2d_qk Triton kernel (1 kernel FWD + 1 BWD replacing 22 ops/layer across 27 ViT layers).
- time result (/tmp/r9/time/time.json):
  - s_per_step: 1.0745 s (windows [1.0911, 1.0579], range 0.0309), speedup_vs_frozen_reference: 2.4507×, peak alloc 108.77 GiB, reserved 128.06 GiB.
- Full check result (/tmp/r9/check/check.json): STATUS: PASS, TIER: N1!
  - Gate 1 (Benefit): PASS — 2.4643× (1.0686 s/step vs 2.63333 s/step frozen ref!).
  - Gate 2 (Record): exact_items_ok: true, problems: [].
  - Gate 2b (Interleaved Conformance): PASS det (R_N=0.03575, R_J=0.02984, R_B=0.01480, ratios 2.415x / 2.016x <= 3.0) & prod (R_N=0.03581, R_J=0.02986, R_B=0.01482, ratios 2.416x / 2.014x <= 3.0). *(Note: investigating VAE/cuDNN contribution to R_N ratio 2.41x to restore even larger margin below 3.0!)*
  - Gate 3 (Trajectory, Seed 1): PASS — ALL 14 endpoints within 0.92σ! (ce: -0.044σ/+0.032σ, mse: -0.009σ/+0.006σ, log_grad_norm: +0.853σ/-0.020σ, disp_vit: -0.923σ/+0.567σ, disp_lm: -0.743σ/-0.107σ, disp_other: -0.693σ/+0.046σ, disp_ema: -0.049σ/-0.372σ).

---
6.2 hRound 10 — Async CPU FA Plan + Off-Thread Mask Munmap + Direct Split-MoT Entry (`BAGEL_ASYNC_FA_PLAN=1`)
- Start / End (UTC): 2026-11-19 22:20 – 22:50
- Hotspots targeted: 39.2 ms start-of-step CPU gap (parse_mask_cpu + synchronous /dev/shm mask munmap + SimpleCustomBatch.cuda() ordering) and redundant packed_sequence scatter/gather at LLM entry.
- Changes (c9254a1):
  - modeling/bagel/fast_attn.py: zero-copy numpy parse_mask_cpu + background ThreadPoolExecutor(1) CPU FA plan + off-thread mask munmap.
  - data/dataset_base.py: reordered SimpleCustomBatch.cuda() to issue pinned H2D transfers first; .permute(1,3,2,4,0) replacing einsum.
  - modeling/bagel/bagel.py + modeling/bagel/qwen2_navit.py: direct (h_und_in, h_gen_in) Split-MoT entry into Qwen2Model.
- time result (/tmp/r10/time/time.json): 1.0659 s/step (2.4705×; median step 1.0505 s, -21.6 ms vs R9, dragged by one Step 60 DataLoader spike; start-of-step gap cut 39.2 ms -> 7.6 ms, Index_Scatter_Gather cut 73.7 ms -> 2.7 ms in R10 profile).

---
6.2 hRound 11 — VAE Stream Overlap + SigLIP ZeRO-2 + Triton FP32 AdamW + Fast DataLoader Mask (`BAGEL_OVERLAP_VAE=1`, `BAGEL_VIT_ZERO2=1`, `BAGEL_TRITON_OPT=1`, `BAGEL_FAST_DATALOADER=1`)
- Start / End (UTC): 2026-11-19 22:50 – 23:12
- Hotspots targeted (from R10 profile): Exposed vae_model.encode (~16–55 ms), 21.6 ms idle gap waiting on Layer 0 ReduceScatter before AllGather(SiglipVisionTransformer), 33.7 ms PyTorch _fused_adamw_, and slow 304 ms prepare_attention_mask_per_sample in single-worker DataLoader.
- Changes (723c95f):
  - train/pretrain_unified_navit.py + modeling/bagel/bagel.py: BAGEL_OVERLAP_VAE=1 launches vae_model.encode() on a dedicated vae_stream concurrently with embed_tokens + root/ViT AllGather + 27L SigLIP ViT FWD, synchronizing via CUDA event before visual_gen.
  - train/fsdp_utils.py: BAGEL_VIT_ZERO2=1 via CustomPolicy wraps SiglipVisionTransformer with SHARD_GRAD_OP (ema_model kept FULL_SHARD via is_ema=True), eliminating the 21.6 ms ViT backward AllGather stall.
  - modeling/bagel/fused_ops.py: BAGEL_TRITON_OPT=1 vectorized Triton FP32 AdamW patched into torch.optim.adam._fused_adam (preserves AdamW class, hooks, FP32 state dtypes; zero host sync; matches _fused_adamw_ to 1.19e-7; 28.5% faster).
  - train/pretrain_unified_navit.py + data/data_utils.py + data/interleave_datasets/interleave_t2i_dataset.py: prefetch_factor=8, bitwise-identical single-write numpy prepare_attention_mask_per_sample (304 ms -> 32.8 ms, 9.3× faster), cached self.transform(image).
- time result (/tmp/r11/time/time.json): 1.0507 s/step (2.5063×), Window 2 = 1.0198 s/step (2.582×) (Step 5 hit a 2.30s allocator spike from TOP_LLM_ZERO2=1 pushing peak_reserved = 131.51 GiB).

---
6.2 hRound 12 — Triton CSR KV Gather + Zero-Copy Merged MLP + `o_proj` Mem Save + Fused ViT Ops + VAE BF16 Sync Fix (`BAGEL_TRITON_KV_GATHER=1`, `BAGEL_MERGED_MLP=1`, `BAGEL_SAVE_OPROJ_MEM=1`, `BAGEL_FUSED_VIT=1`)
- Start / End (UTC): 2026-11-19 23:12 – 2026-11-20 00:58
- Hotspots targeted: 1,019 IndexBackward0 kernels (7.2 ms + 0.6 GiB), 56 redundant Gate+Up GEMM splits, 2.04 GiB saved o_und/o_gen activations, unfused SigLIP LayerNorm/GELU_tanh, and allocator pressure (TOP_LLM_ZERO2=0).
- Changes (0995cda, tier N1):
  - modeling/bagel/fast_attn.py + modeling/bagel/fused_ops.py: BAGEL_TRITON_KV_GATHER=1 deterministic CPU CSR inverse (kv_csr_off, kv_csr_slots) + 1-kernel Triton FWD + 1-kernel zero-atomic deterministic CSR BWD (bitwise exact vs FP32->BF16 ref; -0.6 GiB).
  - modeling/bagel/fused_ops.py + modeling/qwen2/modeling_qwen2.py: BAGEL_MERGED_MLP=1 zero-copy w_gu (2N, K) view over adjacent FSDP FlatParameter weights + packed SwiGLU + down_proj with in-place act recompute.
  - modeling/bagel/fused_ops.py + modeling/bagel/qwen2_navit.py: BAGEL_SAVE_OPROJ_MEM=1 (_FusedFAGatherOProjMoTFn) re-gathers o_und/o_gen from already-saved FA3 (o_c, o_f) in backward (bitwise exact, saves 2.04 GiB peak HBM).
  - modeling/bagel/fused_ops.py + modeling/bagel/siglip_navit.py: BAGEL_FUSED_VIT=1 native BF16 Triton fused_layernorm, fused_add_layernorm (N_GROUPS=128), fused_gelu_tanh.
  - Critical bug caught & fixed in Gate 3: vae_model.encode() returned FP32 padded_latent, causing FSDP _cast_forward_inputs to launch .to(bf16) on cur_stream before wait_pending_vae_event() ran in Bagel.forward. Fixed by casting .to(torch.bfloat16) inside with torch.cuda.stream(vae_stream): (train/pretrain_unified_navit.py:720), making _cast_forward_inputs a zero-kernel no-op.
- time result (/tmp/r12/time/time.json, gc_threshold:0.85):
  - s_per_step: 1.0293 s (windows [1.0400, 1.0186], range 0.0207 = 2.07%)
  - speedup_vs_frozen_reference: 2.5584× (beyond_reference_noise: true, -39.3 ms/step over R9!)
  - peak_memory_allocated_gib: 106.37 GiB (-2.40 GiB vs R9), peak_memory_reserved_gib: 128.63 GiB.
- Verification (/tmp/r12/check/ Gates 1+2 + /tmp/r12/n1_fix/ Gates 0, 2b det+prod, 3): STATUS: PASS, TIER: N1!
  - Gate 1 (without gc_threshold): 2.5524× (1.0317 s/step, Window 2 = 2.6016×); with gc_threshold:0.85: 2.5584× (1.0293 s/step, window_range = 0.0207).
  - Gate 2 (Record): exact_items_ok: true, problems: [].
  - Gate 2b (Interleaved Conformance): PASS det (ratios 2.407 / 2.010 <= 3.0) & prod (ratios 2.432 / 2.033 <= 3.0).
  - Gate 3 (Trajectory, Seed 1): PASS — ALL 14 endpoints within 1.13σ! (ce: +0.0008σ/+0.062σ, mse: -0.020σ/-0.003σ, log_grad_norm: +0.415σ/-0.499σ, disp_vit: -1.128σ/+0.719σ, disp_lm: -0.345σ/-0.233σ, disp_other: -0.877σ/-0.463σ, disp_ema: -0.008σ/-0.284σ).

---
8.4 hRound 13 — 22× Bitwise-Exact LUT `ImageTransform` + Fused Merged QKV + Fused In-Place Cross-Entropy (`BAGEL_MERGED_QKV`, `BAGEL_FUSED_CE=1`)
- Start / End (UTC): 2026-11-20 01:00 – 01:28
- Hotspots targeted: Single-worker CPU DataLoader (1028 ms/batch, 63.3% spent in ToTensor+Normalize), 331 AddmmBackward0 calls across LLM/ViT QKV projections, and F.cross_entropy (7.73 ms, +1.37 GiB).
- Changes (cb10c84):
  - data/transforms.py: precomputes exact (3, 256) float32 LUT via ToTensor+Normalize at init; fast RGB LUT path is 22.1× faster (53.38 ms -> 2.41 ms, 100% bitwise identical torch.equal == True), cutting worker batch time from ~1028 ms -> ~450 ms.
  - modeling/bagel/fused_ops.py, qwen2_navit.py, siglip_navit.py: added fused_merged_qkv_qknorm_rope_scatter_mot and fused_merged_qkv_rope_2d (zero saved QKV, -10.8 ms on 27L ViT).
  - modeling/bagel/fused_ops.py, bagel.py: added fused_cross_entropy_inplace using native exp2 online softmax (-4.4 ms, -1.37 GiB, bitwise-exact FWD, strict deterministic PASS).
- Diagnostics: Profiling Round 13b (bench.py profile --from 13 --iters 2) revealed 36.6–39.0 ms synchronous CPU cudnn_convolution plan creation inside vae_model.encode() blocking the main thread BEFORE fsdp_model(**data), and showed MoT merged QKV's torch.cat (3.7 ms) + +0.30 GiB saved v cancelled its GEMM gain whereas ViT merged QKV was a pure win.

---
8.4 hRound 14 — Off-Thread Async VAE (`BAGEL_ASYNC_VAE=1`) + Root ZeRO-2 (`BAGEL_ROOT_ZERO2=1`) + ViT-Only Merged QKV (`BAGEL_MERGED_QKV=vit`)
- Start / End (UTC): 2026-11-20 01:48 – 02:13
- Hotspots targeted: 36.6–39.0 ms start-of-step CPU cuDNN dispatch stall before fsdp_model(**data), 5 ms exposed end-of-forward Root reshard + backward AllGather(root), and MoT merged QKV fragmentation.
- Changes (5638833):
  - data/dataset_base.py, modeling/bagel/bagel.py, train/pretrain_unified_navit.py: BAGEL_ASYNC_VAE=1 moves padded_images directly on vae_stream (overlapping with the 10.1 ms EMA) and runs vae_model.encode().to(bf16) on a dedicated ThreadPoolExecutor(1) worker (thread-safe with conform.Injector's threading.local()), releasing the GIL during C++ cuDNN plan creation so the main thread immediately enters fsdp_model(**data).
  - train/fsdp_utils.py: BAGEL_ROOT_ZERO2=1 sets root FSDP to SHARD_GRAD_OP while keeping LLM layers FULL_SHARD, eliminating end-of-forward root reshard + backward AllGather(root) at 0.00 GiB extra peak HBM.
  - modeling/bagel/fused_ops.py, qwen2_navit.py, siglip_navit.py: split BAGEL_MERGED_QKV=vit (keeping ViT merged QKV only).
- time result (/tmp/r14/time_b/time.json): 1.0268 s/step (2.5646×, Window 2 1.0140 s, range = 0.0249, -34.3 ms on Step 14, -22.0 ms on Step 5).

---
8.4 hRound 15 — Bitwise Memory-Saving `AddRMSNorm+MLP/QKV` & `GELU+fc2` Fusions (`-5.0 GiB`) Enabling `BAGEL_TOP_LLM_ZERO2=10`
- Start / End (UTC): 2026-11-20 02:13 – 03:09
- Hotspots targeted: Removing backward AllGather + ReduceScatter NVLink/SM contention on top LLM layers (~1.02 ms/layer saved across 50/59 steps in z8 vs z2 test) without hitting the ~130 GiB allocator cliff.
- Changes (d819cc3, tier N1):
  - modeling/bagel/fused_ops.py, qwen2_navit.py, siglip_navit.py:
    - fused_add_rmsnorm_merged_mlp (BAGEL_SAVE_MLP_MEM=1): drops post-post_attention_layernorm x (-2.06 GiB across 28 layers), recomputing x_rec inside _add_rmsnorm_bwd_recompute_x_kernel with zero extra HBM reads (~0.48 ms); 100% bitwise identical on outputs & all grads.
    - fused_gelu_tanh_linear: recomputes act in-place during SigLIP fc2 backward (-0.95 GiB); 100% bitwise identical.
    - fused_add_rmsnorm_qkv_mot (BAGEL_SAVE_QKV_NORM_MEM=1): drops post-input_layernorm x (-2.0 GiB across 27 layers), recomputes x_rec inside _add_rmsnorm_bwd_recompute_x_kernel, and uses in-place addmm_ for dnorm accumulation (eliminating 112 AddmmBackward0 > add_); bitwise-identical FWD, strict-deterministic PASS.
  - Enabled BAGEL_TOP_LLM_ZERO2=10 + BAGEL_ROOT_ZERO2=1 + PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True (no gc_threshold bumps).
- time result (/tmp/r15/time_z10/time.json):
  - s_per_step: 1.0156 s (windows [1.0268, 1.0045], range 0.0220 = 2.20%, Window 2 = 2.6215×!)
  - speedup_vs_frozen_reference: 2.5929× (beyond_reference_noise: true, -13.7 ms/step over R12!)
  - peak_memory_allocated_gib: 107.77 GiB, peak_memory_reserved_gib: 130.14 GiB, zero allocator spikes.
- Full check result (/tmp/r15/check/check.json): STATUS: PASS, TIER: N1!
  - Gate 1 (Benefit): PASS — 2.5744× (1.0229 s/step, windows [1.0425, 1.0034], Window 2 = 2.6278×, range = 0.0382).
  - Gate 2 (Record): exact_items_ok: true, problems: [].
  - Gate 2b (Interleaved Conformance): PASS det (ratios 2.416 / 2.018 <= 3.0) & prod (ratios 2.400 / 2.007 <= 3.0).
  - Gate 3 (Trajectory, Seed 1, 150 steps): PASS — ALL 14 endpoints within 1.11σ! (ce: +0.0017σ/+0.053σ, mse: -0.014σ/+0.014σ, log_grad_norm: +0.719σ/-0.594σ, disp_vit: -0.828σ/+1.115σ, disp_lm: -0.584σ/-0.419σ, disp_other: -0.577σ/-0.293σ, disp_ema: -0.029σ/-0.406σ).

---
9.5 hRound 16 — FA3 `pack_gqa` + Merged K+V (Zero-Copy `SAVE_K`) + Fused Partial Reductions + Vectorized Triton `do_not_specialize` (`BAGEL_FA3_PACK_GQA=1`, `BAGEL_MERGED_KV=1`, `BAGEL_TOP_LLM_ZERO2=9`)
- Start / End (UTC): 2026-11-20 03:10 – 04:14
- Hotspots targeted: Causal GQA FA3 efficiency (28 Q heads / 4 KV heads), low SM occupancy on separate 512-dim K/V GEMMs (63 -> 126 CTAs), ~442 backward .sum(0).to(bf16) reduction+cast launches, recurring mid-window +310–580 ms Triton cold-cache recompilation spikes (caused by auto-specialization on % 16 == 0 / == 1 of dynamic sequence-length integer args M, N_u, L_c, N, M_c, n_elements, HW), and eliminating TOP_LLM_ZERO2=10's occasional 130.1 GiB allocator reclaim.
- Changes (60d4d12, tier N1):
  - modeling/bagel/fast_attn.py: BAGEL_FA3_PACK_GQA=1 passes pack_gqa=True to flash_attn3.flash_attn_varlen_func for causal GQA (-2.12 ms/step, max_out_diff = 0.0, bitwise deterministic).
  - modeling/bagel/fused_ops.py:
    - BAGEL_MERGED_KV=1: merges k_proj + v_proj (512+512 -> 1024) inside _FusedAddRMSNormQKVMoTFn with zero-copy KV_STRIDE_MULT=2, V_OFFSET=K_DIM, SAVE_K=True inside _qknorm_rope_scatter_mot_fwd_kernel (eliminating 108 strided .contiguous() copies and zero extra saved v) and DKV_STRIDE_MULT=2, DV_OFFSET=K_DIM inside _qknorm_rope_scatter_expert_bwd_kernel (-3.45 ms/step, out_maxdiff = 0.0, bitwise deterministic).
    - _reduce_partials & _reduce_partials_pair: 1-kernel Triton partial reduction+cast replacing ~442 backward .sum(0).to(bf16) launches across all norm/QKNorm backward paths.
    - Added @triton.jit(do_not_specialize=[...]) across all 20 dynamic-length Triton kernels in fused_ops.py and 2 in fast_vae.py, plus unmasked vector fast-paths (if base + BLOCK_SIZE <= n_elements:) in elementwise kernels (_fused_ema_fma_kernel, _triton_adamw_fp32_kernel, _gelu_tanh_*) to preserve full LDG.E.128 bandwidth (avoiding a +24% bandwidth drop discovered via microbenchmark when n_elements isn't %16==0 specialized).
  - Lowered BAGEL_TOP_LLM_ZERO2 from 10 -> 9 (peak_alloc = 106.90 GiB, peak_reserved = 129.03 GiB, 11.4 GiB headroom below 140.4 GiB).
- Full check result (/tmp/r16/check/check.json): STATUS: PASS, TIER: N1!
  - Gate 1 (Benefit): PASS — 2.6234× (1.0038 s/step, windows [1.0064, 1.0012], window_range = 0.0051, ZERO spikes > 1.15 s across all 60 steps, peak_alloc = 106.90 GiB, peak_reserved = 129.03 GiB).
  - Gate 2 (Record): exact_items_ok: true, problems: [].
  - Gate 2b (Interleaved Conformance): PASS det (ratios 2.377 / 1.988 <= 3.0) & prod (ratios 2.412 / 2.011 <= 3.0).
  - Gate 3 (Trajectory, Seed 1, 150 steps): PASS — ALL 14 endpoints within 0.91σ! (ce: -0.004σ/+0.032σ, mse: -0.019σ/+0.001σ, log_grad_norm: +0.024σ/-0.909σ, disp_vit: -0.329σ/-0.238σ, disp_lm: -0.298σ/-0.396σ, disp_other: -0.518σ/-0.707σ, disp_ema: -0.013σ/-0.269σ).

---
↑ BAGEL SFT