From 2c9fe45edbdd11a7fcbd44e449a0ce42c55a3d29 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sat, 3 Oct 2026 00:16:45 +0200 Subject: [PATCH] prefill: the fused layout's smaller MoE buffers only when the native kernels cover EVERY layer fused_layout() (STRATA_PF_FUSED=1) shrinks GU / H / Xq to the fused kernels' needs whenever fused_ring() is true, and fused_ring() was true when ANY layer of a native pack was covered. A pack with an uncovered layer - Unsloth UD-IQ4_XS: 5 layers with Q8_0 down projections - then ran MMQ for those layers at the full chunk in buffers sized for stream_all_min() - 1 tokens: on gfx1151 an 8K prompt answered "!!!!..." and a 64K prompt hung (--prefill 2048: an illegal memory access). Such a pack now keeps MMQ's buffers; its covered layers still take the fused kernels. UD-IQ4_XS 8K retrieval after the fix: 3/3 correct, 837.9 prompt tok/s. (The CUDA path shares this code.) --- src/prefill/prefill.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 0c77ad26..5d46e4bf 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -123,12 +123,16 @@ inline bool fused_ring() { if (core::peer_portable()) return false; // multi-GPU: --peer-device keeps the MMQ path and its buffer sizes const strata::kernels::cpu::ExpertLayout& lay = strata::kernels::cpu::expert_layout(); if (!lay.native) return true; - static const bool any = [&lay] { + // EVERY layer: fused_layout() shrinks the MoE buffers to the fused path's needs, so a layer the native kernels do + // not cover (Unsloth UD-IQ4_XS's Q8_0 down projections) would run MMQ in them at the full chunk and overflow them + // (garbage, an illegal memory access or a hung prompt on gfx1151). A pack with such a layer keeps MMQ's buffers; + // its covered layers still take the fused kernels. + static const bool all = [&lay] { for (const auto& f : lay.fmt) - if (fused::native_supported(f.gu_type, f.d_type)) return true; - return false; + if (!fused::native_supported(f.gu_type, f.d_type)) return false; + return !lay.fmt.empty(); }(); - return any; + return all; } // the largest ring: 512 slots; 1024 with the Q2_0 pack's fused experts (P3's smaller buffers, measured there) - the // native packs' fused layers were measured at 512