From 25a1f6e046afeb20bf0daa342a5548b2d22c04bb Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 6 Oct 2026 19:52:15 +0100 Subject: [PATCH] APR on 0.1.40: the sub-16 gate/up rows assume 80 dots per row; trellis types (qk 128) take the full-warp kernel v0.1.40's row_dot_80_sub16 covers (n_embd / qk) * ipb == 80, true for the 256-value i-quants but not for TQ2_T / TQK6 / TQK7 (160 dots at n_embd 2560): half of every gate/up row was dropped (native_expert_parity gpu rel 0.87, garbage output). Restores gpu rel 2.13e-2 / decode-once bitwise. Ported from agentionai/Strata rc2 c4ba288 (rc2 = 9ff02c9), author Laurent. --- src/kernels/cuda/iq_kernels.cu | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kernels/cuda/iq_kernels.cu b/src/kernels/cuda/iq_kernels.cu index 6e440ea7..e291fb2f 100644 --- a/src/kernels/cuda/iq_kernels.cu +++ b/src/kernels/cuda/iq_kernels.cu @@ -1497,7 +1497,7 @@ __global__ void __launch_bounds__(256) native_gu_multi_kernel(const unsigned lon const uint32_t* s_grid = stage_iq_grid(s_grid_buf, threadIdx.x, 256); const int nb = (int) (L.n_embd / Fmt::qk), xb = (int) (L.n_embd / 32); if constexpr (SUB16) { - if (xb == 80) { + if (xb == 80 && nb * Fmt::ipb == 80) { // row_dot_80_sub16 covers exactly 80 dots (not the 128-value TQ blocks) const int subwarp = threadIdx.x >> 4, t = threadIdx.x & 15; const int row = blockIdx.x * 16 + subwarp; // 0 .. 2*n_ff if (row >= 2 * L.n_ff) return; @@ -3013,6 +3013,9 @@ template void launch_gu(dim3 grid, cudaStream_t s, const unsigned long long* grp_ptr, const int32_t* grp_start, const int32_t* n_groups, const int32_t* ent_tok, const block_q8_1* X, const NativeExpertLayout& L, float* gate, float* up) { + // the sub-16 rows (row_dot_80_sub16) assume 80 dots per row: (n_embd / qk) * ipb == 80. The APR trellis types + // (qk 128, ipb 8: 160 dots at n_embd 2560) take the full-warp multi kernel, as before the sub-16 kernels. + const bool g_no_sub16_gu = ::strata::kernels::g_no_sub16_gu || (L.n_embd / Fmt::qk) * Fmt::ipb != 80; if constexpr (!kSplit) native_gu_kernel<<>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); else if (g_old_kernels) native_gu_kernel<<>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); else if constexpr (kStageIqGrid) { @@ -3931,7 +3934,8 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long long } const bool v1 = g_grouped_v1; const int64_t gy = (v1 || grid_groups <= 0 || grid_groups > cap_groups) ? cap_groups : grid_groups; - const int gu_rows = (!g_old_kernels && !g_no_sub16_gu && L.n_embd == 2560 && gu_split(L.gu_type)) ? 16 : GU_ROWS; + const int gu_rows = (!g_old_kernels && !g_no_sub16_gu && L.n_embd == 2560 && gu_split(L.gu_type) && + gu_qk(L.gu_type) != 128) ? 16 : GU_ROWS; // qk 128 (APR trellis): no sub-16 rows, see launch_gu const dim3 ggu((unsigned) ((2 * L.n_ff + gu_rows - 1) / gu_rows), (unsigned) gy); #if STRATA_EXP_LAYOUTS #if defined(STRATA_HIP_GFX906)