moe: correct + deterministic KV-cached gpt-oss decode (single card)
Root-caused the decode non-determinism: matmul's m==1 custom-GEMV fast path reduces over K with a grid-split atomicAdd, whose float accumulation order is non-deterministic. Negligible for attention's stable pre-transposed weights, but for gpt-oss's wide expert GEMMs (K=2880, N up to 5760) over freshly-dequantized MXFP4 weights it produced visibly different results run-to-run (and a wrong argmax). Added gemm::matmul_dense (plain cublasGemmEx, no GEMV shortcut) and route the expert GEMMs through it. Now decode_step (KV cache + GPU sink-attention + MXFP4 experts) is: - deterministic: 3/3 identical runs - correct: top-1 token 12650 = " Paris" for "The capital of France is", MATCH_TOP1 with the host-attention reference forward - end-to-end: gptoss-gen generates 32 tokens at ~6.85 tok/s on one 5090. Removed the temporary A/B debug dumps. gptoss-logits runs both paths and asserts the top-1 match; gptoss-gen times greedy generation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -35,10 +35,7 @@ fn main() {
|
||||
}
|
||||
|
||||
// (2) KV-cache GPU decode path (token-by-token prefill) — must match top-1.
|
||||
let mut cache = xserv_model::GpuKVCache::new(
|
||||
model.config.num_layers(), model.config.num_kv_heads(),
|
||||
model.config.head_dim(), xserv_tensor::DType::BF16, Device::Cuda(0),
|
||||
);
|
||||
let mut cache = xserv_model::GpuKVCache::new(&model.config, 512, xserv_tensor::DType::BF16, 0);
|
||||
let mut dlog = model.decode_step(tokens[0], &mut cache);
|
||||
for &tok in &tokens[1..] {
|
||||
dlog = model.decode_step(tok, &mut cache);
|
||||
|
||||
Reference in New Issue
Block a user