Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

MoE decode kernels: prefetch depth 1, no stream-K grid when whole units cover the SMs

YanissAmzd2e05e28ead7
diff --git a/exllamav3/exllamav3_ext/quant/exl3_moe_coop.cu b/exllamav3/exllamav3_ext/quant/exl3_moe_coop.cu
index ed61a3f..ae78cd6 100644
--- a/exllamav3/exllamav3_ext/quant/exl3_moe_coop.cu
+++ b/exllamav3/exllamav3_ext/quant/exl3_moe_coop.cu
@@ -158,8 +158,14 @@ void exl3_moe_coop_launch(const MoeCoopParams& p_in, int K_gu, int K_d, int cb,
if (sk > 0 && wide_a && max_split >= 4 && exl3_moe_coop_ns::sk_rows(p.slots_max, slots, nproj, p.I, p.Ho) >= 2)
{
int sms;
- grid_a = moe_coop_sk_grid(ka, device, sms);
- p.ksplit_a = -((sk == 2 || grid_a <= sms ? 0 : sms) + 1);
+ const int grid_sk = moe_coop_sk_grid(ka, device, sms);
+ // Units that fit one per SM are whole-unit blocks either way (same sums, same results): keep the
+ // per-unit grid rather than launching a grid of resident blocks that mostly exit at once
+ if (sk == 2 || base_a > sms)
+ {
+ grid_a = grid_sk;
+ p.ksplit_a = -((sk == 2 || grid_a <= sms ? 0 : sms) + 1);
+ }
}
void* args[] = { (void*) &p };
diff --git a/exllamav3/exllamav3_ext/quant/exl3_moe_coop_kernel.cuh b/exllamav3/exllamav3_ext/quant/exl3_moe_coop_kernel.cuh
index 09c0f14..3a7a097 100644
--- a/exllamav3/exllamav3_ext/quant/exl3_moe_coop_kernel.cuh
+++ b/exllamav3/exllamav3_ext/quant/exl3_moe_coop_kernel.cuh
@@ -34,7 +34,7 @@ namespace exl3_moe_coop_ns {
constexpr int WK = 16; // k-split (warps per block)
constexpr int WNT = MOE_COOP_WNT; // adjacent n-tiles per warp
-constexpr int PF = 4; // prefetch ring depth
+constexpr int PF = 1; // prefetch ring depth: deeper rings spilled at 64 registers and measured slower at every width
constexpr int FOLD = 4; // fp16 -> fp32 fold cadence
constexpr int THREADS = WK * 32;
constexpr int COLS = WNT * 16; // columns per warp
@@ -495,7 +495,7 @@ __device__ __forceinline__ void gemv_tile
exl3_gemv_ns::mma_ab_h(a01, a23, f1, ch[t][1]);
}
- if ((d + 1) % FOLD == 0 || i + 1 == myn)
+ if ((i + 1) % FOLD == 0 || i + 1 == myn)
{
#pragma unroll
for (int t = 0; t < WNT; ++t)