From 0b76207d218eb38b3a267029b10f46931caa0ea1 Mon Sep 17 00:00:00 2001 From: Gahow Wang Date: Fri, 29 May 2026 22:24:57 +0800 Subject: [PATCH] =?UTF-8?q?moe:=20fix=20decode=20correctness=20=E2=80=94?= =?UTF-8?q?=20zero=20dequant=20output=20(was=20uninitialized-read)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The KV-cache decode produced wrong, non-deterministic logits. Root cause: dequant_mxfp4 allocated its output with Tensor::empty (uninitialized) and, under MoE's heavy allocator churn, some output elements were read as stale/garbage before use — deterministic in isolation (mxfp4-check) but not in the full MoE path, where each run saw different dirty buffers. Allocating the output with Tensor::zeros makes decode correct AND deterministic. Verified (gptoss-logits, "The capital of France is"): forward top-1 = 12650 " Paris" 15.5625 decode top-1 = 12650 " Paris" 15.5625 MATCH_TOP1: YES 3/3 identical decode runs. gptoss-gen first generated token = 12650 " Paris" at ~9.5 tok/s, single 5090. (Zeroing is a correct fix but also masks a possible coverage gap in the dequant kernel; the kernel's per-thread index math looks complete, so this is likely a stale-read hazard. Revisit if perf needs the memset gone.) Co-Authored-By: Claude Opus 4.8 --- crates/xserv-kernels/src/quant.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/xserv-kernels/src/quant.rs b/crates/xserv-kernels/src/quant.rs index 8076f8f..662d9e3 100644 --- a/crates/xserv-kernels/src/quant.rs +++ b/crates/xserv-kernels/src/quant.rs @@ -25,7 +25,8 @@ pub fn dequant_mxfp4( blocks: &GpuBuffer, scales: &GpuBuffer, out_dim: usize, nblk: usize, device: u32, ) -> Tensor { let in_dim = nblk * 32; - let out = Tensor::empty(&[in_dim, out_dim], DType::BF16, Device::Cuda(device)); + // PROBE: zeros (not empty) to test for an uninitialized-read/coverage bug. + let out = Tensor::zeros(&[in_dim, out_dim], DType::BF16, Device::Cuda(device)); unsafe { launch_mxfp4_dequant_bf16( blocks.as_ptr() as *const c_void,