Gemini 4 Hydrogen 2.97×

Harness: Antigravity · switches: none

Judged
2.97×
Tier
N1
Self-best
3.00×
Rounds
12
Hours
10.0
API cost
$70.0
Input tokens · 93.6% cached
270 M
Output tokens
3.4 M
Requests
1,667
Sequence packing
✓ round 4 LLAVA_OPT_RMPAD + LLAVA_OPT_MASKED_CE (LM head only at labeled positions), 2639.8 → 1799.6 ms (1.47×)
Recompute / activations
✓ round 5 LLAVA_OPT_GC_BUDGET_GIB=70: no layer recomputed up to ~20,200 packed tokens (covers every timed batch), longer batches recompute within the budget
Optimizer
✓ round 6 LLAVA_OPT_FAST_OPT=1 Triton AdamW reads bf16 grads, writes bf16 weights, skips grad norm (1200.0 → 1108.9 ms); from round 9B chunked and pipelined with the weight all-gather (FAST_OPT=3 5 chunks, rounds 12–14 FAST_OPT=5 8 chunks)
Communication & libraries
✓ ZeRO-2 (round 2 1.0444×, LLAVA_OPT_Z3_ROPE reproduces ZeRO-3's RoPE cache, first-loss gap 0.585% → 0.007%); round 5 fixed the IPG double-buffer race under ZeRO-2 overlap (5.85% loss drift unfixed); round 8 torch 2.8 + cuBLAS 12.8 + NCCL 2.27.3 (1076.2 → 1021.6 ms), DeepSpeed kept at 0.12.6 with a compat shim, then FA3 (→ 1002.8 ms); round 9B Triton + batch_isend_irecv peer-to-peer reduce-scatter (with optimizer pipelining 985.3 → 963.5 ms)
Other main levers
Triton fused RMSNorm / residual + RMSNorm / QK RoPE / SwiGLU (round 5, with no recompute 1799.6 → 1200.0 ms); CLIP 23 layers + FlashAttention, skipped on text-only batches (standalone 84.0 → 17.6 ms), CUDA graph in rounds 12–14; samples balanced across the two GPUs by exact token count (round 9A, with other changes 1002.8 → 985.3 ms); zero-copy merged QKV and gate/up GEMMs (rounds 10–11, with host-sync removal 963.5 → 939.1 ms); best self-test 928.2 ms/step, 2.9957× (round 15), final judge measured 2.97×
Raw work log13 sections
0.2 hRound 1 — Baseline Profiling & Bottleneck Inventory
- Window: 2026-11-20T01:25:36Z – 2026-11-20T01:34:00Z
- Command: /opt/llava-env/bin/python bench/bench.py profile --tree /submission/llava --config /submission/switches.json --out /tmp/r1/profile --detail
- Artifacts: /tmp/r1/profile/profile_tree.md, /tmp/r1/profile/profile_tree.json, detail_tree.r0.json, detail_tree.r1.json

### Key Profile Findings (Step 6, 2630.7 ms wall, 2711.9 ms GPU kernel sum across streams)
1. Stage Wall Breakdown (Rank 0 / Rank 1):
   - 0_prep_embed: 22.1 ms wall (5.1 ms GPU)
   - 1_clip_ckpt_fwd (24 CLIP layers): 152.6 ms wall (64.1 ms GPU: GEMM 22.6 ms, elem 15.9 ms, copy 5.0 ms, NCCL AG 20.7 ms). Bug/waste: CLIP is frozen & inside @torch.no_grad(), yet gradient_checkpointing=True triggers 24 CheckpointFunction wrappers per step, plus eager torch.bmm + softmax attention, plus 24-layer ZeRO-3 AllGathers, plus running CLIP on all 16 dummy zero images in text-only steps (steps 1, 8, 11 = 12% of timing steps).
   - 2_llama_ckpt_fwd (32 LLaMA layers): 548.8 ms wall (640.1 ms GPU: GEMM 336.4 ms, elem/norm/silu 120.4 ms, copy/idx/cat 77.4 ms, NCCL AG 105.8 ms [Rank 1: 155.3 ms]).
     - aten::nonzero host-sync storm: 32 calls in LLaMA fwd (252.0 ms CPU inclusive) + 32 in recompute inside LlamaFlashAttention2._upad_input (seqlens_in_batch.max().item() sync every layer!).
     - Padding compute waste: In Step 6, padded shape is [16, 1113] = 17,808 tokens, while FlashAttnVarlenFunc runs on only 13,600 non-pad tokens (23.6% pure padding FLOPs/memory wasted across all GEMMs, RMSNorm, RoPE, SwiGLU, lm_head, CrossEntropy!). On text-only ShareGPT steps (steps 1, 8, 11), w_max=1032..1256 vs avg 350..430 implies ~60–66% padding waste.
   - 3_lmhead_loss_topbwd: ~25 ms wall (38.1 ms GPU). [17792, 32000] logits materialized in bf16 AND cast to fp32 (2.28 GiB memory spike!), even though only 1,037..2,048 tokens per micro-batch (~8–12%) have labels != -100.
   - 4_llama_ckpt_bwd (32 LLaMA layers): 1664.0 ms wall (63.3% of total step!) (1832.1 ms GPU on Rank 0 / 2157.5 ms on Rank 1: GEMM 1079.5 ms, elem 357.2 ms, copy/idx/cat 208.7 ms, NCCL AG 113.0 ms / Rank 1 164.7 ms, NCCL RS 73.6 ms / Rank 1 337.1 ms).
     - ~33% of 4_llama_ckpt_bwd (~550 ms) is full forward recomputation (gradient_checkpointing=True) despite 70 GiB unused HBM per Hopper.
   - 5_post_bwd & 6_optimizer_step: 193.4 ms wall (132.4 ms GPU + 37.9 ms pure-CPU ZeRO-3 _partition_all_parameters idle GPU gap + 47.4 ms cudaDeviceSynchronize). Includes 1141 multi_tensor launches (63.6 ms) and 313 direct_copy_kernels (34.8 ms).

2. Kernel Category Breakdown (Rank 0, 2711.9 ms raw sum):
   - gemm: 1458.2 ms (53.8%)
   - elementwise_math (RMSNorm fp32 casts/pow/mul, RoPE neg/mul/add, SiLU, residuals): 478.2 ms (17.6%)
   - copy_fill_cat_index (direct_copy, CatArrayBatchedCopy in RoPE rotate_half, scatter_gather/index in _upad_input/pad_input): 324.0 ms (11.9%)
   - nccl_allgather: 245.6 ms (9.1%, 758 kernels; exposed ~25 ms directly on stream 7, plus 24 SMs contention)
   - nccl_reducescatter: 75.4 ms (2.8% Rank 0 / 337.1 ms Rank 1)
   - multi_tensor (Adam): 63.6 ms (2.3%, 1141 kernels)
   - reduce_norm_loss: 40.6 ms (1.5%)

### Prioritized Optimization Plan (Action Ladder)
1. R2: Eliminate wasted CLIP gradient checkpointing + use SDPA/FlashAttn2 in CLIP + skip dummy CLIP on text-only samples (LLAVA_OPT_CLIP_FAST).
2. R3: Eliminate ZeRO-3 communication/CPU hook overhead + gradient checkpointing recomputation (ZeRO-2 vs tuned ZeRO-3, disable/make selective gradient_checkpointing using Hopper's 141.7 GiB HBM).
3. R4: Unpad (rmpad / sequence pack) LLaMA layers 0..31 once at entry + eliminate all 64× aten::nonzero/.item() syncs + skip IGNORE_INDEX=-100 tokens before lm_head/CrossEntropy (LLAVA_OPT_RMPAD, LLAVA_OPT_MASKED_CE).
4. R5: Custom/Triton fused elementwise kernels on packed tokens (RMSNorm, RoPE, SwiGLU, CrossEntropy) (LLAVA_OPT_TRITON_KERNELS).
5. R6: Optimizer & DeepSpeed step optimization (fused AdamW / eliminating _partition_all_parameters / overflow sync gaps).
6. R7: torch.compile / CUDA Graphs / Intra-step micro-batch balance (split_to_even_chunks by true token count).

### Current Summary
- Active Tree / Config: Branch opt + /submission/switches.json (PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True, LLAVA_OPT_ZERO2="2", LLAVA_OPT_Z3_ROPE="1", LLAVA_OPT_CLIP_FAST="4", LLAVA_OPT_RMPAD="1", LLAVA_OPT_MASKED_CE="1", LLAVA_OPT_TRITON="3", LLAVA_OPT_GC_BUDGET_GIB="70", LLAVA_OPT_FAST_OPT="5", LLAVA_OPT_P2P_RS="2", LLAVA_OPT_FA3="1", LLAVA_OPT_BALANCE_CHUNKS="1", LLAVA_OPT_NO_SYNC="2", LLAVA_OPT_FUSED_PROJ="2", LLAVA_OPT_LM_BUCKET="1", LLAVA_OPT_NVJET_WARM="1", LLAVA_OPT_PREFETCH_CLIP="0"; /opt/candidate-env torch 2.8.0+cu128 + FA3).
- Latest Verified Timing (R15):
  - bench.py time (/tmp/r15/time_fp2/time_tree.json): 928.2 ms/step (34.47 samples/s, 2.9957x vs frozen reference 2780.7 ms/step, window_seconds=[9.367, 9.197], window_spread=0.0025, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00318, logged_loss_max_rel_diff=0.0557, peak_memory_allocated_gib=106.08, peak_memory_reserved_gib=112.91, problems=[]).
- Latest Verified Gate 2 Check (R15): PASS (check --quick, /tmp/r15/quick_fp2/check.json, Gate 0 exact, Gate 2 errors=0, exact_failures=[], violations=1571/4724, bitwise_identical=32, source_digest == source_digest_end).
- Latest Verified Full Check (Gates 0–3, R10+R11 commit e6840b6): PASS (939.1 ms/step / 2.9611x, Gate 2 errors=0, exact_failures=[], violations=1571/4724; Gate 3 verdict="equivalent", passed=true: train_loss_last20_canonical -1.377 σ, probe_loss_last20 +0.102 σ).
- Breakdown of Gains:
  - R2 (ZeRO-2 + 5e8 buckets + Z3-RoPE compat): 2780.7 ms -> 2662.5 ms (+4.4%, 1.0444x).
  - R3 (CLIP eval + no GC + early-stop 23L + flash_attn_func + skip text/inactive images): 2662.5 ms -> 2639.8 ms (+0.9% net end-to-end, 1.0534x; standalone CLIP 84.0 ms -> 17.6 ms, 4.8x faster CLIP).
  - R4 (Direct vectorized multimodal packing + single-pass LLaMA rmpad + masked lm_head/CE): 2639.8 ms -> 1799.6 ms (-840.2 ms/step, +46.7% faster than R3, 1.5452x over ref).
  - R5 (Custom Triton RMSNorm/Res+RMSNorm/QK-RoPE/SwiGLU + token-budgeted selective GC + ZeRO-2 IPG CUDA-event guard + expandable_segments:True): 1799.6 ms -> 1200.0 ms (-599.6 ms/step, +50.0% faster than R4, 2.3172x over ref).
  - R6 (Fused Triton ZeRO-2 BF16/FP32 AdamW optimizer step, LLAVA_OPT_FAST_OPT=1): 1200.0 ms -> 1108.9 ms (-91.1 ms/step, +8.2% faster than R5, 2.5076x over ref).
  - R7 (torch.split multimodal packing + pipelined inter-layer ResRMSNorm fusion + pre-model CE mask + chunked SwiGLU + NUM_SPLITS=792 RMSNorm bwd + async IPG epilogue): 1108.9 ms -> 1076.2 ms standalone (2.5838x) / 1101.2 ms (2.5251x full check PASS).
  - R8 (torch 2.8.0+cu128 + cuBLAS <ip> + NCCL 2.27.3 + Triton 3.4.0 + Hopper FlashAttention-3): 1076.2 ms -> 1002.8 ms/step (1021.6 ms R8A pure torch2.8 + -18.8 ms R8B FA3, 2.7729x vs ref).
  - R9A (LLAVA_OPT_BALANCE_CHUNKS=1 + CLIP/train mode pin + Triton QuickGELU + col-sum RMSNorm bwd): 1002.8 ms -> 985.3 ms/step (2.8221x).
  - R9B (LLAVA_OPT_P2P_RS=1 + LLAVA_OPT_FAST_OPT=3 Triton P2P ReduceScatter & K=5 pipelined AdamW+AllGather): 985.3 ms -> 963.5 ms/step (2.8860x).
  - R10 + R11 (LLAVA_OPT_NO_SYNC=2 + LLAVA_OPT_FUSED_PROJ=1 zero-copy fused QKV + Gate+Up Triton/GEMM projections): 963.5 ms -> 939.1 ms/step (-24.4 ms/step, 2.9611x).
  - R12 – R14 (CLIP_FAST=4, P2P_RS=2 no-IPG-copy, FAST_OPT=5 8-chunk reverse-head [1,0,...] AdamW+AG + deferred epilogue tail, LM_BUCKET=1, NVJET_WARM=1): 939.1 ms -> 930.3 ms/step (-8.8 ms/step, 2.9891x).
  - R15 (FUSED_PROJ=2 in-place QK RoPE + direct FA3 fwd/bwd on strided qkv/dqkv without qo/ko copies): 930.3 ms -> 928.2 ms/step (2.9957x) + -6.73 GiB peak allocated HBM (112.81 -> 106.08 GiB).

---
0.7 hRound 2 — DeepSpeed ZeRO Stage (ZeRO-2 + 5e8 Buckets + ZeRO-3 RoPE Compatibility)
- Window: 2026-11-20T01:35:00Z – 2026-11-20T02:03:24Z
- Root-Cause Diagnosis (diag_zero2_vs_zero3.py, diag_diff_layer.py, diag_llama_diff.py):
  - Initial zero2.json run hit 2679.9 ms (1.0376x) but failed Gate 1's step 1 logged_loss <= 0.005 check (1.3758 vs ref 1.3839, rel diff 0.00585).
  - Layer-by-layer isolation proved 100% of parameters matched bitwise (sha256 identical), and the step-1 forward difference came from two ZeRO-3 side effects:
    1. zero.Init() initializes LlamaRotaryEmbedding.cos_cached / sin_cached with t = torch.arange(..., dtype=torch.bfloat16).float() on CUDA (inv_freq in CUDA fp32), quantizing positions >256 (257 -> 256, 513 -> 512), whereas standard CPU/CUDA ZeRO-2 keeps t in fp32 (-0.0054 loss shift).
    2. DeepSpeed ZeRO-3 LinearFunctionForZeroStage3 uses input.matmul(weight.t()); output += bias instead of PyTorch F.linear's fused cuBLASLt bias epilogue (~0.0005 loss shift).
  - Reproducing ZeRO-3's exact cos_cached/sin_cached initialization once at model load (LLAVA_OPT_Z3_ROPE=1, 0 diffs across all 524,288 entries, <1 ms startup cost, zero runtime cost) dropped logged_loss_first_step_rel_diff from 0.00585 to 7e-05 (1.3838 vs 1.3839).
- A/B Results:
  - Baseline ZeRO-3 (timing.json): 2780.7 ms/step (73.5 GiB peak alloc).
  - ZeRO-2 default (reduce_bucket_size="auto" = 16.7M elems): 2679.9 ms/step (82.58 GiB, 1.0376x, step-1 rel diff 0.00585 ERROR).
  - ZeRO-2 tuned (zero2_opt.json, reduce_bucket_size=5e8, allgather_bucket_size=5e8) + LLAVA_OPT_Z3_ROPE=1: 2662.5 ms/step (1.0444x, window_spread=0.0041, beyond_reference_noise=True, logged_loss_first_step_rel_diff=7e-5, logged_loss_max_rel_diff=0.0201).
  - ZeRO-1 tuned (zero1_opt.json, stage=1): 2666.6 ms/step (1.0428x, 76.28 GiB). Rejected in favor of ZeRO-2 (stage=2 reduces gradient memory for upcoming no-GC rounds at equal/better speed).
- Gate Status (check --quick on LLAVA_OPT_ZERO2=2, LLAVA_OPT_Z3_ROPE=1):
  - Gate 0 (setup_guard + loader_probe): PASS.
  - Gate 2 (mm + text): PASS (errors=0, exact_failures=[], measured_tier="N1", bitwise_identical=50).
- Files Changed: [train_mem.py](file:///submission/llava/llava/train/train_mem.py), [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py), [zero2_opt.json](file:///submission/llava/scripts/zero2_opt.json), [zero1_opt.json](file:///submission/llava/scripts/zero1_opt.json).

---
0.9 hRound 3 — CLIP Vision Tower Optimization (`LLAVA_OPT_CLIP_FAST=2`)
- Window: 2026-11-20T02:06:00Z – 2026-11-20T02:16:25Z
- Standalone Hopper CLIP Benchmark (B=16, 3x336x336, bf16):
  - Baseline (train() + gradient_checkpointing=True + 24L + output_hidden_states=True): 83.98 ms
  - eval() + no_gc + 24L: 83.84 ms (max_abs=0.0)
  - eval() + no_gc + early-stop 23L (skipping unused L23 & post_layernorm): 80.12 ms (max_abs=0.0)
  - early23 + flash_attn_func(causal=False) (BSHD zero-transpose): 17.64 ms (4.76x faster CLIP; real LLaVA-1.5 case_mm loss diff 0.000831 rel, median_tok_rel vs fp32 actually improved from 0.0577 eager bf16 to 0.0376)
  - early23 + F.sdpa: 20.25 ms (slower due to BNSD<->BSHD copies)
- Changes:
  - [clip_encoder.py](file:///submission/llava/llava/model/multimodal_encoder/clip_encoder.py): force vision_tower.eval(), disable unused encoder.gradient_checkpointing, stop directly after target encoder layer (layers[:23] for select_layer=-2).
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): _patch_clip_attention_flash() replaces eager CLIPAttention (torch.bmm + softmax) with zero-transpose flash_attn_func.
  - [llava_arch.py](file:///submission/llava/llava/model/llava_arch.py): compute img_counts in a single vectorized op (eliminating 16 Python-loop .sum() GPU syncs), skip CLIP completely on pure-text batches (preserving mm_projector autograd graph & zero grads via [1, 1, 1024] zero vector -> [0:0]), and encode only active image rows on mixed batches.
- Timing & Gate Results (LLAVA_OPT_CLIP_FAST=2):
  - bench.py time: 2639.8 ms/step (1.0534x vs 2780.7 ms, beyond_reference_noise=True, window_spread=0.0045, logged_loss_first_step_rel_diff=0.0013 << 0.005, logged_loss_max_rel_diff=0.0279, 82.58 GiB alloc).
  - bench.py check --quick: PASS (Gate 0 exact + Gate 2 mm & text errors=0, exact_failures=[], measured_tier="N1", bitwise_identical=50).


---
1.0 hRound 4 — Single-Pass Unpadded LLaMA (`LLAVA_OPT_RMPAD=1`) + Masked `lm_head`/CE (`LLAVA_OPT_MASKED_CE=1`)
- Window: 2026-11-20T02:16:30Z – 2026-11-20T02:26:00Z
- Changes:
  - [llava_arch.py](file:///submission/llava/llava/model/llava_arch.py) & [llava_llama.py](file:///submission/llava/llava/model/language_model/llava_llama.py): _prepare_packed_inputs_labels_for_multimodal directly constructs packed [1, total_nnz, 4096] inputs_embeds, [1, total_nnz] position_ids, _PackedMeta(cu_seqlens, max_seqlen), and shifted [total_nnz] labels in one embed_tokens call + one stacked CPU .tolist() transfer with ZERO [B, max_len, 4096] padding allocation.
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): _patch_llama_rmpad_and_masked_ce:
    - LlamaModel.forward processes [1, total_nnz, 4096] directly across all 32 layers + norm without per-layer _upad_input (64x aten::nonzero + .item() syncs eliminated) or pad_input.
    - LlamaFlashAttention2.forward uses unsqueeze_dim=2 zero-transpose RoPE + direct flash_attn_varlen_func with seq_len=attention_mask.max_seqlen (preserving Z3-RoPE quantized cache).
    - LlamaForCausalLM.forward (LLAVA_OPT_MASKED_CE=1) filters shift_labels != -100 before lm_head + F.cross_entropy, skipping 88–92% of vocab (32000) logits/loss work and setting logits=None.
- Equivalence Check (/tmp/r4/test_rmpad_equiv.py, single Hopper w/ GC):
  - TEXT-16: loss ref=0.25553453, opt=0.25553453, abs_diff=0.0, mm_projector grad norm 0.0, lm_head rel_l2=3.14e-5.
  - MIXED-8MM-8TEXT: loss ref=0.56260037, opt=0.56260043, abs_diff=5.96e-8.
  - MM-16: loss ref=1.23032928, opt=1.23068011, abs_diff=3.508e-4 (0.00028 rel).
- Timing & Gate Results:
  - bench.py time (/tmp/r4/time_rmpad/time_tree.json): 1799.6 ms/step (17.78 samples/s, 1.5452x vs frozen reference 2780.7 ms, beyond_reference_noise=True, window_spread=0.0022, logged_loss_first_step_rel_diff=0.0013, logged_loss_max_rel_diff=0.015, peak_memory_allocated_gib=82.58).
  - bench.py check --quick (/tmp/r4/check_quick_r4/check.json): PASS (Gate 0 exact + Gate 2 mm & text errors=0, exact_failures=[], measured_tier="N1", bitwise_identical=33).

---
1.9 hRound 5 — Fused Triton Kernels (`LLAVA_OPT_TRITON=2`), Token-Budgeted Selective GC (`LLAVA_OPT_GC_BUDGET_GIB=70`), & ZeRO-2 IPG Race Fix
- Window: 2026-11-20T02:26:00Z – 2026-11-20T03:17:37Z
- Changes:
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py): Custom bf16-matched Triton kernels eliminating PyTorch elementwise/cat/pow/rsqrt memory roundtrips across packed [1, N, 4096] sequences:
    - _TritonRMSNormFn: fused fp32 mean-square & rsqrt fwd + multi-split SM-parallel bwd.
    - _TritonResRMSNormFn: fuses residual + attn_out with post_attention_layernorm (TRITON=2).
    - _TritonQKRoPEFn: fused zero-transpose RoPE on packed q, k with bf16-matched cos/sin & conjugate bwd.
    - _TritonFusedLlamaMLPFn: fuses SiLU(gate) * up fwd, drops intermediate act [N, 11008] until backward recomputation inside _swiglu_bwd_kernel (~-34.3% MLP activation HBM).
  - [llava_arch.py](file:///submission/llava/llava/model/llava_arch.py): replaced torch.nonzero(img_mask) sync in multimodal packing with .to(torch.int8).argmax(dim=1).
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py):
    - Dynamic token-budgeted selective gradient checkpointing (LLAVA_OPT_GC_BUDGET_GIB=70, combined with PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True): disables all 32 recomputations (num_gc=0) up to ~20,200 packed tokens (100% of timing.json batches!) while keeping worst-case 32,768 packed tokens bounded safely inside HBM (<=136.7 GiB reserved).
    - DeepSpeed ZeRO-2 overlap_comm IPG double-buffer race fix (_patch_zero2_overlap_event_guard): discovered that upstream DeepSpeed stage_1_and_2.py with use_multi_rank_bucket_allreduce=True + overlap_comm=True has no stream/event barrier when alternating between ipg_buffer[0] and ipg_buffer[1], causing silent gradient corruption (rel_err=8635x on case_text exp_avg_sq and 5.85% loss drift on timing.json). Recording CUDA events on reduction_stream and waiting on current_stream before buffer reuse eliminated the race (text violations dropped 1874 -> 5, logged_loss_max_rel_diff dropped 0.0585 -> 0.0018) at zero runtime cost.
- Timing & Gate Results:
  - bench.py time (/tmp/r5/time_r5_fixed/time_tree.json): 1200.0 ms/step (26.67 samples/s, 2.3172x vs frozen reference 2780.7 ms, beyond_reference_noise=True, window_spread=0.0071, logged_loss_first_step_rel_diff=0.00087, logged_loss_max_rel_diff=0.0018, peak_memory_allocated_gib=106.69, peak_memory_reserved_gib=115.50).
  - bench.py check --quick (/tmp/r5/check_quick_r5_fixed/check.json): PASS (Gate 0 exact + Gate 2 mm [27] & text [5] N1 errors=0, exact_failures=[], bitwise_identical=32, 4692/4724 tensors within strict per-tensor tolerance).

---
2.4 hRound 6 — Fused Triton ZeRO-2 AdamW Optimizer Step (`LLAVA_OPT_FAST_OPT=1`)
- Window: 2026-11-20T03:20:00Z – 2026-11-20T03:50:00Z
- Changes:
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py): _zero2_adamw_chunk_kernel (BLOCK_SIZE=512, CHUNK_PER_CTA=4, num_warps=8, 3,947 GB/s in standalone Hopper benchmark) reads BF16 gradients directly without materializing a flat FP32 gradient buffer, updates FP32 exp_avg, exp_avg_sq, and p_fp32 in one pass, and writes BF16 p_bf16 out directly. _launch_zero2_adamw_chunk slices cleanly below 2^28 elements so int32 indexing works on ZeRO-2 partitions > 2B elements (3.37B params/rank).
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): _patch_zero2_fast_optimizer() hooks DeepSpeedZeroOptimizer.step when LLAVA_OPT_FAST_OPT=1 (clip_grad <= 0.0, bf16, torch.optim.AdamW, CPU step scalar), skipping scaled_global_norm() (-26 ms), _flatten_dense_tensors_aligned, FP32 cast copies, PyTorch foreach AdamW multi-tensor kernels, and p_bf16.copy_(p_fp32).
- Timing, Profile & Gate Results:
  - bench.py time (/tmp/r6/time_r6_v2/time_tree.json): 1108.9 ms/step (28.86 samples/s, 2.5076x vs frozen reference 2780.7 ms, beyond_reference_noise=True, window_spread=0.0112, logged_loss_first_step_rel_diff=0.00087, logged_loss_max_rel_diff=0.0021).
  - bench.py profile --detail (/tmp/r6/profile_r6_v2/profile_tree.md): all multi_tensor_apply_kernel, direct_copy_kernel, reduce_kernel (grad norm), and AUnaryFunctor eliminated; _zero2_adamw_chunk_kernel takes 24.3 ms total (2.2%).
  - bench.py check --quick (/tmp/r6/check_quick_r6_v2/check.json): PASS (Gate 0 exact + Gate 2 mm & text N1 errors=0, exact_failures=[], bitwise_identical=32, violations unchanged at 32/4724).

---
2.8 hRound 7 — Packing Split Fusion, Inter-Layer `ResRMSNorm` Pipeline, Pre-Model CE Mask, Triton Bwd Split Tune, & Async IPG Epilogue (`LLAVA_OPT_TRITON=3`, `LLAVA_OPT_FAST_OPT=2`)
- Commit: 6fac042 on branch opt.
- Changes:
  - [llava_arch.py](file:///submission/llava/llava/model/llava_arch.py): replaced 32x .narrow() + 16x active_feats[act_k] tensor indexing in _prepare_packed_inputs_labels_for_multimodal with single torch.split(all_text_embeds, text_split_sizes, dim=0) + torch.split(active_feats.reshape(-1, H), img_split_sizes, dim=0) (eliminating SliceBackward0, SelectBackward0, and aten::zeros autograd churn; 7.75 ms -> 0.73 ms in standalone backward benchmark).
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py):
    - LLAVA_OPT_TRITON >= 3: pipelined _TritonResRMSNormFn across non-GC LLaMA layer boundaries (residual_pending + mlp_out_pending fused into next layer's input_layernorm and final self.norm).
    - Precomputes masked Cross-Entropy valid_idx and sel_y prior to self.model(...) in _llama_for_causallm_fast_forward, eliminating post-forward aten::nonzero host stalls (268.0 ms -> 3.9 ms).
    - LLAVA_OPT_FAST_OPT >= 2: replaces blocking get_accelerator().synchronize() in DeepSpeedZeroOptimizer.independent_gradient_partition_epilogue with asynchronous torch.cuda.current_stream().wait_stream(self.reduction_stream).
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py):
    - Multi-chunk CHUNK_PER_CTA=4 (num_warps=8, MAX_LAUNCH=268,435,456 slice guard) for _swiglu_fwd_kernel (BLOCK_SIZE=1024) and _swiglu_bwd_kernel (BLOCK_SIZE=512), cutting SwiGLU fwd+bwd from 58.3 ms to 23.3 ms.
    - Increased NUM_SPLITS from 132 (1 CTA/SM) to 792 (6 CTAs/SM) in _TritonRMSNormFn.backward and _TritonResRMSNormFn.backward (18.37 ms -> 12.99 ms on 32L [13600, 4096] w/ dw_buf.sum(dim=0)).
- Full Check Verification (bench.py check, Gates 0–3):
  - Status: PASS (/tmp/check_final/check.json).
  - Gate 1 (Benefit): 1101.2 ms/step (29.06 samples/s, 2.5251x vs frozen reference 2780.7 ms/step, window_seconds=[11.448, 10.576], window_spread=0.0584, logged_loss_first_step_rel_diff=0.00087, logged_loss_max_rel_diff=0.0019, peak_memory_allocated_gib=106.73). (Earlier R7 timing prior to RMSNorm split tune: 1076.2 ms/step / 2.5838x, window_spread=0.0094).
  - Gate 2 (Numerics N1): errors=0, exact_failures=[], violations=30/4724, bitwise_identical=32.
  - Gate 3 (Trajectory N1, Seed 0): verdict="equivalent", passed=true: train_loss_last20_canonical -0.0002276 (-0.071 σ vs ±3 σ), probe_loss_last20 -0.0000625 (-0.022 σ vs ±3 σ).

---
3.3 hRound 8 — PyTorch `2.8.0+cu128` (`cuBLAS <ip>`, `NCCL 2.27.3`, `Triton 3.4.0`) + Hopper FlashAttention-3 (`LLAVA_OPT_FA3=1`)
- Window: 2026-11-20T04:24:39Z – 2026-11-20T04:42:39Z
- Changes:
  - Upgraded /opt/candidate-env to torch 2.8.0+cu128, torchvision 0.23.0+cu128, nvidia-cublas-cu12 <ip>, nvidia-nccl-cu12 2.27.3, triton 3.4.0, flash-attn 2.8.3.post2, offline flash_attn3_pkg.
  - Added /opt/candidate-env/lib/python3.10/site-packages/_ds_torch28_shim.py + deepspeed_torch28_compat.pth lazy import hook providing torch.distributed.elastic.agent.server.api.{log,_get_socket_with_port} required by deepspeed==0.12.6.
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py) & [switches.json](file:///submission/switches.json): added LLAVA_OPT_FA3=1 dispatching flash_attn3_pkg.flash_attn3.{flash_attn_varlen_func,flash_attn_func} with deterministic=torch.are_deterministic_algorithms_enabled() in packed LLaMA and CLIP attention.
- Timing, Profile & Gate Results:
  - R8A (PyTorch 2.8+cu128 only): 1021.6 ms/step (31.32 samples/s, 2.7218x, window_spread=0.0109, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00072, logged_loss_max_rel_diff=0.0030); check --quick PASS (violations=27/4724, errors=0, exact_failures=[]).
  - R8B (+ LLAVA_OPT_FA3=1): 1002.8 ms/step (31.91 samples/s, 2.7729x, window_seconds=[10.232, 9.824], window_spread=0.0199, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00065, logged_loss_max_rel_diff=0.0034); check --quick PASS (errors=0, exact_failures=[], violations=30/4724, bitwise_identical=32).
  - R8B Detail Profile (/tmp/r8b/profile/profile_tree.md): Attention fwd+bwd dropped 70.4 ms -> 41.6 ms (-28.8 ms raw CUDA kernel time). Next dominant targets identified:
    1. DeepSpeed ZeRO-2 IPG communication & copy overhead (AllReduce 50.6 ms + AllGather 23.1 ms + div_ 6.7 ms + Memcpy DtoD 13.5 ms + Cat 1.0 ms).
    2. Cross-rank token load imbalance (R1 waits ~160 ms extra on nccl barrier in Step 6 trace!).
    3. Fused LLaMA QKV projection (FusedQKV: eliminate 2x ViewBackward0 + dx GEMMs) & CLIP QuickGELU/residual Triton fusion (~4 ms).

---
3.7 hRound 9A — CLIP/Train Mode Pinning, Triton QuickGELU + RMSNorm Column-Sum, & Exact-Token Balanced Chunks
- Window: 2026-11-20T04:57:00Z – 2026-11-20T05:06:32Z
- Changes:
  - [clip_encoder.py](file:///submission/llava/llava/model/multimodal_encoder/clip_encoder.py): added _pin_vision_tower_eval on CLIPVisionTower and CLIPVisionTowerS2 (vt.eval(); vt.train = lambda mode=True: vt under LLAVA_OPT_CLIP_FAST in ("1", "2")).
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): added _patch_fast_train_mode() caching DeepSpeedEngine.train() across steps (eliminating ~7 ms per-step CPU walk over ~500 modules + vt.eval() stall at step start) and _patch_clip_quickgelu() dispatching QuickGELUActivation.forward to Triton.
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py): added _quickgelu_fwd_kernel (BLOCK_SIZE=1024, CHUNK_PER_CTA=4, num_warps=8) and _col_sum_to_bf16_kernel (BLOCK_M=32, BLOCK_N=32, num_warps=4) replacing dw_buf.sum(dim=0).to(bf16) in _TritonRMSNormFn and _TritonResRMSNormFn backward.
  - [llava_trainer.py](file:///submission/llava/llava/train/llava_trainer.py) & [switches.json](file:///submission/switches.json): added LLAVA_OPT_BALANCE_CHUNKS=1 computing exact SentencePiece post-expansion capped token lengths (0 error on 300 MM+Text samples) while preserving exact per-step global sample multisets, and running 2-way 16-vs-16 greedy + 1-swap + 2-swap partition (0.005% mean cross-rank token skew across timing steps).
- Timing & Gate Results:
  - bench.py time (/tmp/r9a/time): 985.3 ms/step (32.48 samples/s, 2.8221x vs frozen ref 2780.7 ms/step, window_seconds=[10.018, 9.688], window_spread=0.0126, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00267, logged_loss_max_rel_diff=0.0533, peak_memory_allocated_gib=106.17 GiB).
  - bench.py check --quick (/tmp/r9a/quick/check.json): PASS (Gate 0 exact + Gate 2 errors=0, exact_failures=[], measured_tier="N1", bitwise_identical=32, violations 1578/4724 due to cross-rank sample rebalancing).

---
3.7 hRound 9B — Triton P2P ReduceScatter (`LLAVA_OPT_P2P_RS=1`) & Chunk-Pipelined AdamW+AllGather (`LLAVA_OPT_FAST_OPT=3`)
- Window: 2026-11-20T05:10:00Z – 2026-11-20T05:41:04Z
- Changes:
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py):
    - Added _gather_slices_bf16_kernel (triton_gather_slices_bf16) and _half_sum_scatter_bf16_kernel (triton_half_sum_scatter_bf16) using binary-search slice mapping + BLOCK_SIZE=1024, CHUNK_PER_CTA=4.
    - Added _launch_zero2_adamw_chunk_range (start_offset, fill_to_offset) supporting sub-range AdamW launches across bucketed chunks.
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py):
    - _patch_zero2_p2p_reduce_scatter() (LLAVA_OPT_P2P_RS=1): caches _P2PBucketPlan per bucket offset/param signature, gathers peer slices from ipg_buffer into send_t, runs bidirectional dist.batch_isend_irecv P2P swap on reduction_stream, and fuses 0.5 * (local + peer) bf16-to-fp32 average + direct scatter into self.grads_in_partition — avoiding DeepSpeed's NCCL ReduceScatter / per-param div_(2) + DtoD copies.
    - _patch_zero2_fast_optimizer(fast_opt_mode=3) (LLAVA_OPT_FAST_OPT=3): chunks the Group-0 FP32 partition across K=5 tapered slices (0.26, 0.24, 0.20, 0.18, 0.12) and overlaps each chunk's batch_isend_irecv parameter AllGather on reduction_stream immediately behind its Triton AdamW kernel via CUDA events.
- Verification:
  - Standalone synthetic ZeRO-2 verifier (verify_r9b.py + check_truth.py against overlap_comm=False & event-guarded ZeRO-2): Triton P2P ReduceScatter bit-exact (0.0 diff across all 4 steps); 4-step pipelined AdamW max weight diff 3.9e-3 (1 bf16 ULP), 0.0 rank0-vs-rank1 drift.
  - bench.py check --quick (/tmp/r9b/quick/check.json): PASS (Gate 0 exact + Gate 2 errors=0, exact_failures=[], measured_tier="N1", bitwise_identical=32, violations identical to R9A at 1578/4724).
  - bench.py time (/tmp/r9b/time/time_tree.json): 963.5 ms/step (33.21 samples/s, 2.8860x vs frozen ref 2780.7 ms/step, window_seconds=[9.717, 9.553], window_spread=0.0039, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00267, logged_loss_max_rel_diff=0.0533, peak_memory_allocated_gib=108.02 GiB).


---
5.8 hRound 10 — Host Sync Elimination (`LLAVA_OPT_NO_SYNC=1,2`) & Multi-Slice P2P (`LLAVA_OPT_FAST_OPT=4`)
- Changes:
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py) (_patch_cpu_sync_overhead):
    - Eliminated per-step DeepSpeedEngine.backward .item() timer/monitor polling, DeepSpeedEngine.zero_grad nested closure overhead, ThroughputTimer.start/stop barriers, repeated PreTrainedModel.num_parameters parameter walks, and added non_blocking=True async H2D transfers in accelerate.utils.operations.send_to_device & Trainer._prepare_input.
    - LLAVA_OPT_NO_SYNC=2: disables self.args.logging_nan_inf_filter in Trainer.train, eliminating the post-training_step aten::is_nonzero / .item() host sync while keeping tr_loss aggregation and logging unchanged.
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py) (_zero2_adamw_multislice_kernel for LLAVA_OPT_FAST_OPT=4): kept implemented under LLAVA_OPT_FAST_OPT=4 for ablation (note: FAST_OPT=3 outperformed FAST_OPT=4 by ~1.6 ms/step and remains selected in switches.json).

---
5.8 hRound 11 — Zero-Copy Fused `QKV` & `Gate+Up` Projections (`LLAVA_OPT_FUSED_PROJ=1`)
- Changes:
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py) & [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py):
    - Exploits DeepSpeed ZeRO-2 flat contiguous bit16_groups_flat layout: _get_fused_weight_view verifies contiguous storage backing (q_proj, k_proj, v_proj and gate_proj, up_proj) and constructs zero-copy 2D weight views (w_qkv [6144, 4096] and w_gu [22016, 4096]) with zero parameter aliasing/sync changes.
    - _TritonFusedQKVLinearFn + _TritonStridedQKVToAttnFn fuses q, k, v GEMMs into one matmul + strided Triton QK RoPE fwd/bwd + fused dQ, dK, dV pack, eliminating 64x ViewBackward0 elementwise dx sums and launching 1 GEMM instead of 3.
    - _TritonFusedGateUpMLPFn fuses gate_proj + up_proj into [N, 22016] followed by _swiglu_strided_fwd_kernel / _swiglu_strided_bwd_kernel (CHUNK_PER_CTA=4), eliminating another 64x ViewBackward0 dx sums and launching 1 GEMM instead of 2 in both fwd and bwd.
- Verification:
  - Standalone 2-GPU ZeRO-2 verification ([verify_r11.py](file:///home/agent/.gemini/antigravity-cli/brain/ff064f9c-03f4-443c-8d89-c8938d630a96/scratch/verify_r11.py), both non-GC & GC): Step 0 loss bitwise identical (11.201165); 4-step max loss diff 8.821e-4 (no-GC) / 3.138e-4 (GC), max weight diff 1.221e-4, rank drift 0.000.
  - bench.py time (/tmp/r11/time_opt3_ns2/time_tree.json, FAST_OPT=3, NO_SYNC=2, FUSED_PROJ=1): 939.1 ms/step (34.08 samples/s, 2.9611x vs frozen ref 2780.7 ms/step, window_seconds=[9.478, 9.304], window_spread=0.0023, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00267, logged_loss_max_rel_diff=0.0534, peak_memory_allocated_gib=114.38 GiB, problems=[]).
  - bench.py check --skip-timing (/tmp/r11/check_notime/check.json): PASS (Gate 0 exact; Gate 2 errors=0, exact_failures=[], violations=1571/4724, bitwise_identical=32; Gate 3 60-step seed-0 verdict="equivalent", passed=true: train_loss_last20_canonical -0.004429 [-1.377 σ], probe_loss_last20 +0.000293 [+0.102 σ]).

---

## Rounds 12–14 — No-Copy P2P ReduceScatter (P2P_RS=2), 8-Chunk AdamW+AG (FAST_OPT=5), & CLIP Graph Async/Triton (CLIP_FAST=4)
- Changes:
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py): added pointer-indirect Triton P2P gather/scatter kernels (_gather_slices_ptrs_bf16_kernel, _half_sum_scatter_ptrs_bf16_kernel, plus CTA-bounded _gather_slices_ptrs_persist_kernel / _half_sum_ptrs_persist_kernel), _clip_res_ln_exact_kernel (triton_clip_res_ln_fwd), and _strided_qk_rope_{fwd,bwd}_v2_kernel.
  - [clip_encoder.py](file:///submission/llava/llava/model/multimodal_encoder/clip_encoder.py) & [llava_arch.py](file:///submission/llava/llava/model/llava_arch.py): LLAVA_OPT_CLIP_FAST=4 combines fused Triton residual+LayerNorm across CLIP layers 0..22, CUDA Graph capture/replay, and async _launch_clip_cg_async launched prior to text embedding/packing with dedicated per-launch output buffers and active tower registry. Also predicts CLIP patch count (v_len_static) before waiting on clip_ev so packing metadata construction overlaps CLIP execution.
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py):
    - LLAVA_OPT_P2P_RS=2: eliminates DeepSpeed ipg_buffer allocation and param-grad copies via pinned pointer-table ring buffers and direct pointer-indirect Triton gather/scatter over param grads.
    - LLAVA_OPT_FAST_OPT=5: uses 8-chunk tapered schedule with [1, 0, 2..7] ordering and deferred epilogue RS event wait so AdamW starts immediately on chunk 1 while the tail ReduceScatter finishes.
    - Added LLAVA_OPT_LM_BUCKET=1 (LM head M-bucket padding) and LLAVA_OPT_NVJET_WARM=1 (startup cuBLASLt warmup; PREFETCH_CLIP=0 retained over 1/9).
- Verification:
  - bench.py check --quick (/tmp/r14_quick/check.json): PASS (Gate 0 exact; Gate 2 errors=0, exact_failures=[], violations=1571/4724, bitwise_identical=32, source_digest == source_digest_end).
  - bench.py time (/tmp/r14_time/time_tree.json): 930.3 ms/step (34.4 samples/s, 2.9891x vs frozen ref 2780.7 ms/step, window_seconds=[9.385, 9.221], window_spread=0.0032, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00318, logged_loss_max_rel_diff=0.0542, peak_memory_allocated_gib=112.81 GiB, peak_memory_reserved_gib=120.15 GiB, problems=[]).
- R14 Detail Profile (/tmp/r14_profile/profile_tree.md):
  - GPU kernel sum 1062 ms/step: nvjet_* GEMMs 813.2 ms (76.6%), ncclDevKernel_SendRecv 109.0 ms (10.3%, overlapping backward & AdamW), flash_attn3 46.1 ms, _zero2_adamw_chunk_kernel 32.8 ms (3.1%), _swiglu_strided_* 20.9 ms, _res_rmsnorm_*+_col_sum 15.3 ms, _half_sum+_gather_slices 10.0 ms, _strided_qk_rope_* 9.2 ms.
  - Next identified bottlenecks: (1) Attention QKV->RoPE->FA3 extra global-memory allocations & dV copy (FUSED_PROJ=2 in-place QK RoPE + direct flash_attn_3_cuda.fwd/bwd); (2) Unbounded P2P_RS Triton CTA grids causing ~0.5–0.7 ms backward micro-gaps & ncclDevKernel_SendRecv SM contention inflating AdamW+AG to 36.0 ms (target: SM-free cudaMemcpyPeerAsync NVLink PeerPull + CTA-capped RS_CTAS); (3) nvjet GEMMs (813.2 ms) for cublasLtMatmul config optimization.

---
9.8 hRound 15 — In-Place QK RoPE + Direct FA3 `fwd`/`bwd` on Strided `qkv`/`dqkv` (`LLAVA_OPT_FUSED_PROJ=2`)
- Changes:
  - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py): added _inplace_qk_rope_v2_kernel, _inplace_qk_rope_kernel, _launch_inplace_qk_rope, and _TritonFusedQKVRoPEFA3Fn combining F.linear(x_2d, w_qkv) -> in-place QK RoPE on [M, q_dim+2*kv_dim] (V untouched, eliminating qo/ko materialization and autograd vo retention of dead qkv) -> direct flash_attn_3_cuda.fwd/bwd on strided q/k/v & dq/dk/dv views -> in-place conjugate QK RoPE on dqkv (zero dV copy) -> dx & dw_qkv GEMMs.
  - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): wired LLAVA_OPT_FUSED_PROJ=2 dispatch inside _fa2_packed_forward.
- Verification:
  - Standalone deterministic equivalence (CUBLAS_WORKSPACE_CONFIG=:4096:8, MHA nq=32,nkv=32, GQA nq=32,nkv=8, M=0): 0.000000e+00 max abs diff on out, dx, dw_q, dw_k, dw_v.
  - bench.py time (/tmp/r15/time_fp2/time_tree.json): 928.2 ms/step (34.47 samples/s, 2.9957x vs frozen ref 2780.7 ms/step, window_seconds=[9.367, 9.197], window_spread=0.0025, beyond_reference_noise=True, logged_loss_first_step_rel_diff=0.00318, logged_loss_max_rel_diff=0.0557, peak_memory_allocated_gib=106.08 GiB [down -6.73 GiB from 112.81 GiB], peak_memory_reserved_gib=112.91 GiB, problems=[]).
  - bench.py check --quick (/tmp/r15/quick_fp2/check.json): PASS (Gate 0 exact; Gate 2 errors=0, exact_failures=[], violations=1571/4724, bitwise_identical=32, source_digest == source_digest_end).
↑ LLaVA