From 0f0bb429499d517da9816a863e8b8571bbae853f Mon Sep 17 00:00:00 2001 From: iz0eyj Date: Wed, 2 Dec 2026 01:46:28 +0100 Subject: [PATCH] [Core] VETTA_PROF: sync-isolated real MoE GPU time in moe_batched (profile aid) Under VETTA_PROF, sync before/after moe_batched so EXPERT_NS measures real GPU MoE time, not async launch. Measured: MoE = 2727ms of 4176ms/chunk = 65% of batched prefill (the dominant hotspot; trunk GEMM + flash are minority). Production path (no VETTA_PROF) unchanged. --- crates/vetta-infer-ld/src/layer.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/vetta-infer-ld/src/layer.rs b/crates/vetta-infer-ld/src/layer.rs index 1ee6056..baf0c05 100644 --- a/crates/vetta-infer-ld/src/layer.rs +++ b/crates/vetta-infer-ld/src/layer.rs @@ -763,6 +763,8 @@ fn moe_batched( cache: &WeightCache, ip: usize, mlpin: &DeviceBuf, ids: &DeviceBuf, weights: &DeviceBuf, d: &Dims, h: usize, b: i32, ) -> Result { let t0 = std::time::Instant::now(); + let prof = std::env::var("VETTA_PROF").is_ok(); + if prof { vetta_infer_hip::synchronize()?; } // isolate real MoE GPU time (drain prior work) let w13 = cache.expert_arena(ip, "w13")?; let w2 = cache.expert_arena(ip, "w2")?; let top_k = d.top_k; @@ -791,6 +793,7 @@ fn moe_batched( // Scatter-back + weighted reduce per token. let moeout = DeviceBuf::alloc((b as usize) * h * 4)?; vetta_infer_hip::moe_reduce_buckets_masked(&y_part, &ds2b, weights, &moeout, b, top_k as i32, h as i32)?; + if prof { vetta_infer_hip::synchronize()?; } EXPERT_NS.with(|c| c.set(c.get() + t0.elapsed().as_nanos())); Ok(moeout) }