From 25359737768c96a9541b3126c1efe3d22a07dac6 Mon Sep 17 00:00:00 2001 From: cobra91 Date: Thu, 26 Nov 2026 10:33:19 +0100 Subject: [PATCH] fix(poly/expert_card): compute Q8_1 scratch size per row so kCpuRows/kSlots > MAX_NCOLS does not throw (Fixes #355) --- engine/src/poly/expert_card.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/poly/expert_card.cpp b/engine/src/poly/expert_card.cpp index 058b61b79f..394afff49c 100644 --- a/engine/src/poly/expert_card.cpp +++ b/engine/src/poly/expert_card.cpp @@ -37,10 +37,10 @@ ExpertCard::ExpertCard(int device, int n_layer, int n_expert, int n_embd, int n_ stream_ = s; const size_t ff = (size_t) n_ff, row = (size_t) n_embd; ck(cudaMalloc((void**) &xf_, (size_t) kCpuRows * row * sizeof(float)), "--expert-gpu scratch"); - ck(cudaMalloc(&xq_, kernels::native_q8_1_bytes(n_embd, kCpuRows)), "--expert-gpu scratch"); + ck(cudaMalloc(&xq_, kernels::native_q8_1_bytes(n_embd) * (size_t) kCpuRows), "--expert-gpu scratch"); ck(cudaMalloc((void**) &g_, (size_t) kSlots * 2 * ff * sizeof(float)), "--expert-gpu scratch"); ck(cudaMalloc((void**) &h_, (size_t) kSlots * ff * sizeof(float)), "--expert-gpu scratch"); - ck(cudaMalloc(&q8_, kernels::native_q8_1_bytes(n_ff, kSlots)), "--expert-gpu scratch"); + ck(cudaMalloc(&q8_, kernels::native_q8_1_bytes(n_ff) * (size_t) kSlots), "--expert-gpu scratch"); ck(cudaMalloc((void**) &d_, (size_t) kSumRows * row * sizeof(float)), "--expert-gpu scratch"); ck(cudaMalloc((void**) &acc_, (size_t) kCpuRows * row * sizeof(float)), "--expert-gpu scratch"); ck(cudaMallocHost((void**) &out_, (size_t) kCpuRows * row * sizeof(float)), "--expert-gpu scratch");