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
§ 02Key levers
- 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=1Triton 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=35 chunks, rounds 12–14FAST_OPT=58 chunks) - Communication & libraries
- ✓ ZeRO-2 (round 2 1.0444×,
LLAVA_OPT_Z3_ROPEreproduces 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_irecvpeer-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×
§ ARaw trace
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 mswall (5.1 msGPU) -1_clip_ckpt_fwd(24 CLIP layers):152.6 mswall (64.1 msGPU: GEMM22.6 ms, elem15.9 ms, copy5.0 ms, NCCL AG20.7 ms). Bug/waste: CLIP is frozen & inside@torch.no_grad(), yetgradient_checkpointing=Truetriggers 24CheckpointFunctionwrappers per step, plus eagertorch.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 mswall (640.1 msGPU: GEMM336.4 ms, elem/norm/silu120.4 ms, copy/idx/cat77.4 ms, NCCL AG105.8 ms[Rank 1:155.3 ms]). -aten::nonzerohost-sync storm:32calls in LLaMA fwd (252.0 msCPU inclusive) +32in recompute insideLlamaFlashAttention2._upad_input(seqlens_in_batch.max().item()sync every layer!). - Padding compute waste: In Step 6, padded shape is[16, 1113] = 17,808tokens, whileFlashAttnVarlenFuncruns on only13,600non-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..1256vs avg350..430implies ~60–66% padding waste. -3_lmhead_loss_topbwd:~25 mswall (38.1 msGPU).[17792, 32000]logits materialized in bf16 AND cast to fp32 (2.28 GiBmemory spike!), even though only1,037..2,048tokens per micro-batch (~8–12%) havelabels != -100. -4_llama_ckpt_bwd(32 LLaMA layers):1664.0 mswall (63.3%of total step!) (1832.1 msGPU on Rank 0 /2157.5 mson Rank 1: GEMM1079.5 ms, elem357.2 ms, copy/idx/cat208.7 ms, NCCL AG113.0 ms/ Rank 1164.7 ms, NCCL RS73.6 ms/ Rank 1337.1 ms). - ~33% of4_llama_ckpt_bwd(~550 ms) is full forward recomputation (gradient_checkpointing=True) despite70 GiBunused HBM per Hopper. -5_post_bwd & 6_optimizer_step:193.4 mswall (132.4 msGPU +37.9 mspure-CPU ZeRO-3_partition_all_parametersidle GPU gap +47.4 mscudaDeviceSynchronize). Includes1141multi_tensorlaunches (63.6 ms) and313direct_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,CatArrayBatchedCopyin RoPErotate_half,scatter_gather/indexin_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-2vs tunedZeRO-3, disable/make selectivegradient_checkpointingusing 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 + skipIGNORE_INDEX=-100tokens beforelm_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_chunksby true token count). ### Current Summary - Active Tree / Config: Branchopt+/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-envtorch 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.9957xvs frozen reference2780.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 2errors=0,exact_failures=[],violations=1571/4724,bitwise_identical=32,source_digest == source_digest_end). - Latest Verified Full Check (Gates 0–3, R10+R11 commite6840b6):PASS(939.1 ms/step/2.9611x, Gate 2errors=0,exact_failures=[],violations=1571/4724; Gate 3verdict="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 (CLIPeval+ 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 CLIP84.0 ms -> 17.6 ms,4.8xfaster CLIP). - R4 (Direct vectorized multimodal packing + single-pass LLaMArmpad+ maskedlm_head/CE):2639.8 ms -> 1799.6 ms(-840.2 ms/step,+46.7%faster than R3,1.5452xover ref). - R5 (Custom TritonRMSNorm/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.3172xover 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.5076xover ref). - R7 (torch.splitmultimodal packing + pipelined inter-layerResRMSNormfusion + pre-model CE mask + chunkedSwiGLU+NUM_SPLITS=792RMSNorm bwd + async IPG epilogue):1108.9 ms -> 1076.2 msstandalone (2.5838x) /1101.2 ms(2.5251xfullcheckPASS). - R8 (torch 2.8.0+cu128+cuBLAS <ip>+NCCL 2.27.3+Triton 3.4.0+ HopperFlashAttention-3):1076.2 ms -> 1002.8 ms/step(1021.6 msR8A pure torch2.8 +-18.8 msR8B FA3,2.7729xvs 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=3Triton 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=1zero-copy fusedQKV+Gate+UpTriton/GEMM projections):963.5 ms -> 939.1 ms/step(-24.4 ms/step,2.9611x). - R12 – R14 (CLIP_FAST=4,P2P_RS=2no-IPG-copy,FAST_OPT=58-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=2in-place QK RoPE + direct FA3fwd/bwdon stridedqkv/dqkvwithoutqo/kocopies):930.3 ms -> 928.2 ms/step(2.9957x) +-6.73 GiBpeak 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): - Initialzero2.jsonrun hit2679.9 ms(1.0376x) but failed Gate 1'sstep 1 logged_loss <= 0.005check (1.3758vs ref1.3839, rel diff0.00585). - Layer-by-layer isolation proved 100% of parameters matched bitwise (sha256identical), and the step-1 forward difference came from two ZeRO-3 side effects: 1.zero.Init()initializesLlamaRotaryEmbedding.cos_cached/sin_cachedwitht = torch.arange(..., dtype=torch.bfloat16).float()on CUDA (inv_freqin CUDA fp32), quantizing positions >256 (257 -> 256,513 -> 512), whereas standard CPU/CUDA ZeRO-2 keepstin fp32 (-0.0054loss shift). 2. DeepSpeed ZeRO-3LinearFunctionForZeroStage3usesinput.matmul(weight.t()); output += biasinstead of PyTorchF.linear's fused cuBLASLt bias epilogue (~0.0005loss shift). - Reproducing ZeRO-3's exactcos_cached/sin_cachedinitialization once at model load (LLAVA_OPT_Z3_ROPE=1, 0 diffs across all 524,288 entries, <1 ms startup cost, zero runtime cost) droppedlogged_loss_first_step_rel_difffrom0.00585to7e-05(1.3838vs1.3839). - A/B Results: - Baseline ZeRO-3 (timing.json):2780.7 ms/step(73.5 GiBpeak alloc). - ZeRO-2 default (reduce_bucket_size="auto"= 16.7M elems):2679.9 ms/step(82.58 GiB,1.0376x, step-1 rel diff0.00585ERROR). - 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=2reduces gradient memory for upcoming no-GC rounds at equal/better speed). - Gate Status (check --quickonLLAVA_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)(BSHDzero-transpose):17.64 ms(4.76x faster CLIP; real LLaVA-1.5case_mmloss diff0.000831rel,median_tok_relvs fp32 actually improved from0.0577eager bf16 to0.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): forcevision_tower.eval(), disable unusedencoder.gradient_checkpointing, stop directly after target encoder layer (layers[:23]forselect_layer=-2). - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py):_patch_clip_attention_flash()replaces eagerCLIPAttention(torch.bmm+ softmax) with zero-transposeflash_attn_func. - [llava_arch.py](file:///submission/llava/llava/model/llava_arch.py): computeimg_countsin a single vectorized op (eliminating 16 Python-loop.sum()GPU syncs), skip CLIP completely on pure-text batches (preservingmm_projectorautograd 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.0534xvs2780.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 GiBalloc). -bench.py check --quick: PASS (Gate 0 exact + Gate 2mm&texterrors=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_multimodaldirectly constructs packed[1, total_nnz, 4096]inputs_embeds,[1, total_nnz]position_ids,_PackedMeta(cu_seqlens, max_seqlen), and shifted[total_nnz]labels in oneembed_tokenscall + 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.forwardprocesses[1, total_nnz, 4096]directly across all 32 layers +normwithout per-layer_upad_input(64x aten::nonzero+.item()syncs eliminated) orpad_input. -LlamaFlashAttention2.forwardusesunsqueeze_dim=2zero-transpose RoPE + directflash_attn_varlen_funcwithseq_len=attention_mask.max_seqlen(preserving Z3-RoPE quantized cache). -LlamaForCausalLM.forward(LLAVA_OPT_MASKED_CE=1) filtersshift_labels != -100beforelm_head+F.cross_entropy, skipping88–92%of vocab (32000) logits/loss work and settinglogits=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_projectorgrad norm0.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.00028rel). - Timing & Gate Results: -bench.py time(/tmp/r4/time_rmpad/time_tree.json):1799.6 ms/step(17.78 samples/s,1.5452xvs frozen reference2780.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 2mm&texterrors=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: fusesresidual + attn_outwithpost_attention_layernorm(TRITON=2). -_TritonQKRoPEFn: fused zero-transpose RoPE on packedq, kwith bf16-matchedcos/sin& conjugate bwd. -_TritonFusedLlamaMLPFn: fusesSiLU(gate) * upfwd, drops intermediateact[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): replacedtorch.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 withPYTORCH_CUDA_ALLOC_CONF=expandable_segments:True): disables all 32 recomputations (num_gc=0) up to ~20,200 packed tokens (100% oftiming.jsonbatches!) while keeping worst-case 32,768 packed tokens bounded safely inside HBM (<=136.7 GiBreserved). - DeepSpeed ZeRO-2overlap_commIPG double-buffer race fix (_patch_zero2_overlap_event_guard): discovered that upstream DeepSpeedstage_1_and_2.pywithuse_multi_rank_bucket_allreduce=True+overlap_comm=Truehas no stream/event barrier when alternating betweenipg_buffer[0]andipg_buffer[1], causing silent gradient corruption (rel_err=8635xoncase_textexp_avg_sqand5.85%loss drift ontiming.json). Recording CUDA events onreduction_streamand waiting oncurrent_streambefore buffer reuse eliminated the race (textviolations dropped1874 -> 5,logged_loss_max_rel_diffdropped0.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.3172xvs frozen reference2780.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 2mm[27] &text[5] N1errors=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/sin standalone Hopper benchmark) reads BF16 gradients directly without materializing a flat FP32 gradient buffer, updates FP32exp_avg,exp_avg_sq, andp_fp32in one pass, and writes BF16p_bf16out directly._launch_zero2_adamw_chunkslices cleanly below2^28elements so int32 indexing works on ZeRO-2 partitions > 2B elements (3.37Bparams/rank). - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py):_patch_zero2_fast_optimizer()hooksDeepSpeedZeroOptimizer.stepwhenLLAVA_OPT_FAST_OPT=1(clip_grad <= 0.0,bf16,torch.optim.AdamW, CPUstepscalar), skippingscaled_global_norm()(-26 ms),_flatten_dense_tensors_aligned, FP32 cast copies, PyTorchforeachAdamW multi-tensor kernels, andp_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.5076xvs frozen reference2780.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): allmulti_tensor_apply_kernel,direct_copy_kernel,reduce_kernel(grad norm), andAUnaryFunctoreliminated;_zero2_adamw_chunk_kerneltakes24.3 mstotal (2.2%). -bench.py check --quick(/tmp/r6/check_quick_r6_v2/check.json): PASS (Gate 0 exact + Gate 2mm&textN1errors=0,exact_failures=[],bitwise_identical=32, violations unchanged at32/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:6fac042on branchopt. - Changes: - [llava_arch.py](file:///submission/llava/llava/model/llava_arch.py): replaced32x.narrow()+16xactive_feats[act_k]tensor indexing in_prepare_packed_inputs_labels_for_multimodalwith singletorch.split(all_text_embeds, text_split_sizes, dim=0)+torch.split(active_feats.reshape(-1, H), img_split_sizes, dim=0)(eliminatingSliceBackward0,SelectBackward0, andaten::zerosautograd churn;7.75 ms -> 0.73 msin standalone backward benchmark). - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): -LLAVA_OPT_TRITON >= 3: pipelined_TritonResRMSNormFnacross non-GC LLaMA layer boundaries (residual_pending + mlp_out_pendingfused into next layer'sinput_layernormand finalself.norm). - Precomputes masked Cross-Entropyvalid_idxandsel_yprior toself.model(...)in_llama_for_causallm_fast_forward, eliminating post-forwardaten::nonzerohost stalls (268.0 ms -> 3.9 ms). -LLAVA_OPT_FAST_OPT >= 2: replaces blockingget_accelerator().synchronize()inDeepSpeedZeroOptimizer.independent_gradient_partition_epiloguewith asynchronoustorch.cuda.current_stream().wait_stream(self.reduction_stream). - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py): - Multi-chunkCHUNK_PER_CTA=4(num_warps=8,MAX_LAUNCH=268,435,456slice guard) for_swiglu_fwd_kernel(BLOCK_SIZE=1024) and_swiglu_bwd_kernel(BLOCK_SIZE=512), cutting SwiGLU fwd+bwd from58.3 msto23.3 ms. - IncreasedNUM_SPLITSfrom132(1 CTA/SM) to792(6 CTAs/SM) in_TritonRMSNormFn.backwardand_TritonResRMSNormFn.backward(18.37 ms -> 12.99 mson 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.5251xvs frozen reference2780.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-envtotorch 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, offlineflash_attn3_pkg. - Added/opt/candidate-env/lib/python3.10/site-packages/_ds_torch28_shim.py+deepspeed_torch28_compat.pthlazy import hook providingtorch.distributed.elastic.agent.server.api.{log,_get_socket_with_port}required bydeepspeed==0.12.6. - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py) & [switches.json](file:///submission/switches.json): addedLLAVA_OPT_FA3=1dispatchingflash_attn3_pkg.flash_attn3.{flash_attn_varlen_func,flash_attn_func}withdeterministic=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 --quickPASS (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 --quickPASS (errors=0,exact_failures=[],violations=30/4724,bitwise_identical=32). - R8B Detail Profile (/tmp/r8b/profile/profile_tree.md): Attention fwd+bwd dropped70.4 ms -> 41.6 ms(-28.8 msraw 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 (R1waits~160 msextra onncclbarrier in Step 6 trace!). 3. Fused LLaMA QKV projection (FusedQKV: eliminate2xViewBackward0+dxGEMMs) & 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_evalonCLIPVisionTowerandCLIPVisionTowerS2(vt.eval(); vt.train = lambda mode=True: vtunderLLAVA_OPT_CLIP_FAST in ("1", "2")). - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): added_patch_fast_train_mode()cachingDeepSpeedEngine.train()across steps (eliminating~7 msper-step CPU walk over ~500 modules +vt.eval()stall at step start) and_patch_clip_quickgelu()dispatchingQuickGELUActivation.forwardto 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) replacingdw_buf.sum(dim=0).to(bf16)in_TritonRMSNormFnand_TritonResRMSNormFnbackward. - [llava_trainer.py](file:///submission/llava/llava/train/llava_trainer.py) & [switches.json](file:///submission/switches.json): addedLLAVA_OPT_BALANCE_CHUNKS=1computing exact SentencePiece post-expansion capped token lengths (0error on 300 MM+Text samples) while preserving exact per-step global sample multisets, and running 2-way16-vs-16greedy + 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.8221xvs frozen ref2780.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 2errors=0,exact_failures=[],measured_tier="N1",bitwise_identical=32, violations1578/4724due 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-stepDeepSpeedEngine.backward.item()timer/monitor polling,DeepSpeedEngine.zero_gradnested closure overhead,ThroughputTimer.start/stopbarriers, repeatedPreTrainedModel.num_parametersparameter walks, and addednon_blocking=Trueasync H2D transfers inaccelerate.utils.operations.send_to_device&Trainer._prepare_input. -LLAVA_OPT_NO_SYNC=2: disablesself.args.logging_nan_inf_filterinTrainer.train, eliminating the post-training_stepaten::is_nonzero/.item()host sync while keepingtr_lossaggregation and logging unchanged. - [triton_ops.py](file:///submission/llava/llava/train/triton_ops.py) (_zero2_adamw_multislice_kernelforLLAVA_OPT_FAST_OPT=4): kept implemented underLLAVA_OPT_FAST_OPT=4for ablation (note:FAST_OPT=3outperformedFAST_OPT=4by ~1.6 ms/step and remains selected inswitches.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_TritonFusedQKVRoPEFA3FncombiningF.linear(x_2d, w_qkv)-> in-place QK RoPE on[M, q_dim+2*kv_dim](V untouched, eliminatingqo/komaterialization and autogradvoretention of deadqkv) -> directflash_attn_3_cuda.fwd/bwdon stridedq/k/v&dq/dk/dvviews -> in-place conjugate QK RoPE ondqkv(zerodVcopy) ->dx&dw_qkvGEMMs. - [opt_patches.py](file:///submission/llava/llava/train/opt_patches.py): wiredLLAVA_OPT_FUSED_PROJ=2dispatch inside_fa2_packed_forward. - Verification: - Standalone deterministic equivalence (CUBLAS_WORKSPACE_CONFIG=:4096:8, MHAnq=32,nkv=32, GQAnq=32,nkv=8,M=0):0.000000e+00max abs diff onout, 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.9957xvs frozen ref2780.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 GiBfrom112.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 2errors=0,exact_failures=[],violations=1571/4724,bitwise_identical=32,source_digest == source_digest_end).