From 5d958f7cdddb07eb4318d0769444e8cdae13c20d Mon Sep 17 00:00:00 2001 From: Glenn Neuber Date: Fri, 14 Aug 2026 08:41:18 +1000 Subject: [PATCH] CUDA: size MMQ ids-path tail padding from the flattened row count The ids branch of ggml_cuda_mul_mat_q() sizes the src1_q8_1 data term from ne12*n_expert_used but the tail-padding term from ne11. The correct row count is computed just below as ne11_flat. For MoE gate/up the activations are broadcast, so ne11 == 1, and ggml_cuda_mmq_get_J_max() returns 0 for that. The buffer then has no tail padding while MMQ reads in tiles of up to 512 rows past the end. --- ggml/src/ggml-cuda/mmq.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggml/src/ggml-cuda/mmq.cu b/ggml/src/ggml-cuda/mmq.cu index 707437ea3e52..6af7a27e194f 100644 --- a/ggml/src/ggml-cuda/mmq.cu +++ b/ggml/src/ggml-cuda/mmq.cu @@ -203,7 +203,7 @@ void ggml_cuda_mul_mat_q( } const size_t nbytes_src1_q8_1 = ne12*n_expert_used*ne10_padded * y_block_size/y_values_per_block + - ggml_cuda_mmq_get_J_max(src0->type, fallback, cc, ne11) * sizeof(block_q8_1_mmq); + ggml_cuda_mmq_get_J_max(src0->type, fallback, cc, ne12*n_expert_used) * sizeof(block_q8_1_mmq); ggml_cuda_pool_alloc src1_q8_1(ctx.pool(), nbytes_src1_q8_1); ggml_cuda_pool_alloc src1_scale(ctx.pool()); if (src0->type == GGML_TYPE_NVFP4 && use_native_fp4) {