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.

Hy4 prefill: dense fp16 GEMMs of a chunk above 8192 rows run in pieces of 8192 (HY4_PF_MM_SPLIT, 0 = off): the TunableOp results only cover M = 4096 / 8192, so a merged tail chunk (8192 + up to 2048 rows) used the default GEMM solution (35 TF instead of 42, wo K = 16384 24 instead of 34 TF); 9000-row chunk 11.97 -> 11.34 s (two reps each), KL vs noise nulls in band (0.107 / 0.102 vs 0.099-0.105)

YanissAmzaa41e9581928
diff --git a/exllamav3/loader/dense_req.py b/exllamav3/loader/dense_req.py
index 49338ae..d8ec039 100644
--- a/exllamav3/loader/dense_req.py
+++ b/exllamav3/loader/dense_req.py
@@ -93,7 +93,7 @@ def raw16(lin, x, tm=None):
if lin.ty == 8:
return pk.qdense_raw16(x, lin.packed, tm)
x2 = pk.to_f16(x.reshape(-1, lin.shape[1])).contiguous()
- return torch.mm(x2, dequant16(lin))
+ return pk.mm_rows(x2, dequant16(lin))
def full(lin, x, tm=None):
@@ -108,7 +108,7 @@ def qdense_kq(lin, x):
pk = _pk()
lead = x.shape[:-1]
x2 = pk.to_f16(x.reshape(-1, lin.shape[1])).contiguous()
- o = torch.mm(x2, dequant16(lin))
+ o = pk.mm_rows(x2, dequant16(lin))
out = torch.nan_to_num(o.float(), nan=0.0, posinf=pk.F16MAX, neginf=-pk.F16MAX)
return out.reshape(*lead, lin.shape[0])
diff --git a/exllamav3/loader/prefill_kernels.py b/exllamav3/loader/prefill_kernels.py
index 5efc63d..7304e19 100644
--- a/exllamav3/loader/prefill_kernels.py
+++ b/exllamav3/loader/prefill_kernels.py
@@ -962,6 +962,19 @@ def dequant_q8(packed):
return out
+def mm_rows(x2, w):
+ """torch.mm(x2 [M, K] fp16, w [K, N] fp16) in row pieces of HY4_PF_MM_SPLIT (default 8192, 0 = off): the TunableOp results only cover M = 4096 / 8192, so a merged
+ tail chunk (8192 + up to 2048 rows) fell back to the default GEMM solution (35 TF instead of 42, wo K = 16384 24 instead of 34): the first 8192 rows take the tuned entry"""
+ M = x2.shape[0]
+ S = int(os.environ.get("HY4_PF_MM_SPLIT", "8192"))
+ if S <= 0 or M <= S:
+ return torch.mm(x2, w)
+ out = torch.empty(M, w.shape[1], dtype=x2.dtype, device=x2.device)
+ for a in range(0, M, S):
+ torch.mm(x2[a:a + S], w, out=out[a:a + S])
+ return out
+
+
def qdense_tm(x, packed, tm=None):
"""x [.., K] -> [.., N] fp32 = x @ W.T: dequantise the stored Q8_0 weight to fp16 once per call, then the vendor fp16 GEMM (tm = optional stage timers)"""
N, nb, bb = packed.shape
@@ -973,7 +986,7 @@ def qdense_tm(x, packed, tm=None):
with t(f"f dense N={N} K={K}: dequant"):
w16 = dequant_q8(packed)
with t(f"f dense N={N} K={K}: mm"):
- o = torch.mm(x2, w16)
+ o = mm_rows(x2, w16)
with t(f"f dense N={N} K={K}: float"):
out = f32_sat(o)
return out.reshape(*lead, N)
@@ -1059,7 +1072,7 @@ def qdense_raw16(x, packed, tm=None, tag=""):
with t(f"f dense N={N} K={nb * 32}: dequant"):
w16 = dequant_q8(packed)
with t(f"f dense N={N} K={nb * 32}: mm"):
- return torch.mm(x2, w16)
+ return mm_rows(x2, w16)
@triton.jit