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.

Verify rows 5..8: split row-limited launches into 4-row launches behind EXL3_VERIFY_ROW_SPLIT (default off)

YanissAmz23b7227d36a7
diff --git a/exllamav3/modules/moe_fused.py b/exllamav3/modules/moe_fused.py
index d49a41e..078dbb5 100644
--- a/exllamav3/modules/moe_fused.py
+++ b/exllamav3/modules/moe_fused.py
@@ -17,6 +17,8 @@ from ..ext import exllamav3_ext as ext
from .hyperconnections import HyperConnection
MAX_ROWS = 4
+# EXL3_VERIFY_ROW_SPLIT=1: 5..8 rows of one sequence run as fused sub-calls of at most 4 rows (per-row arithmetic unchanged)
+SPLIT_MAX_ROWS = 8 if os.environ.get("EXL3_VERIFY_ROW_SPLIT", "0") != "0" else MAX_ROWS
# EXL3_MOE_FUSED9=<variant>: 0 off, 393216 (0x60000) = forced-inline phases + two blocks per WGP (core9), 917504 = same kernel, ONE block per WGP, 1441792 (0x160000, default) = same phases and block partition as 0x60000, but every grid barrier is a kernel boundary (six stage launches):
@@ -158,10 +160,15 @@ class FusedMoEHalf:
return False
if x.dtype != torch.float or not x.is_contiguous() or x.dim() != 4 or x.shape[2] != self.H or x.shape[3] != self.D:
return False
- return 1 <= x.shape[0] * x.shape[1] <= MAX_ROWS
+ return 1 <= x.shape[0] * x.shape[1] <= SPLIT_MAX_ROWS
def __call__(self, x: torch.Tensor) -> torch.Tensor:
"""x (b, s, H, D) fp32 residual stack, updated in place and returned."""
+ if x.shape[0] * x.shape[1] > MAX_ROWS:
+ assert x.shape[0] == 1
+ for lo in range(0, x.shape[1], MAX_ROWS):
+ self(x[:, lo:lo + MAX_ROWS])
+ return x
gr = self.gr
fq, fsc, uq, usc = gr.q8_set()
if MF9["variant"] and self.native and hasattr(torch.ops, "mf9") and hasattr(torch.ops.mf9, "half"):
diff --git a/exllamav3/modules/quant/exl3.py b/exllamav3/modules/quant/exl3.py
index 1b5d6b6..86ff6a3 100644
--- a/exllamav3/modules/quant/exl3.py
+++ b/exllamav3/modules/quant/exl3.py
@@ -6,6 +6,8 @@ from ...ext import exllamav3_ext as ext
from ...util.tensor import g_tensor_cache
import os
from ...util import profile_opt
+from .. import row_split as _row_split
+_row_split.install()
MAX_BSZN_GEMV_R = 8 # must match MOE_R_MAX in exllamav3_ext/quant/exl3_dec.cu
# K >= this runs R batch-1 launches instead of one gemv_r launch (A/B knob; 99 = never loop)
diff --git a/exllamav3/modules/row_split.py b/exllamav3/modules/row_split.py
new file mode 100644
index 0000000..a750136
--- /dev/null
+++ b/exllamav3/modules/row_split.py
@@ -0,0 +1,54 @@
+"""Row split of the speculative verify (EXL3_VERIFY_ROW_SPLIT=1, default off).
+
+Several verify kernels have a fast path for up to 4 rows (one-pass hc mixer: GRR_MAX_RT = 4) or are fast only up to
+4 rows (exl3_dec_gemv_r / _multi: the 8-row instantiation costs about 4x per row). With 5..8 rows (one sequence,
+q_len = R) they fall to a slow launch. These kernels treat every row independently (one weight decode shared across
+rows, one reduction order per row), so a launch over R rows is split here into launches of at most 4 rows: row r
+runs through exactly the instantiation it uses in a 1..4 row round, same arithmetic, flat cost per row.
+"""
+from __future__ import annotations
+import os
+from ..ext import exllamav3_ext as ext
+
+CHUNK = 4
+ON = os.environ.get("EXL3_VERIFY_ROW_SPLIT", "0") != "0"
+_installed = False
+
+
+def _split(fn, nrows_of, slicer):
+ def wrapped(*a, **kw):
+ R = nrows_of(*a, **kw)
+ if R <= CHUNK:
+ return fn(*a, **kw)
+ for lo in range(0, R, CHUNK):
+ hi = min(lo + CHUNK, R)
+ fn(*slicer(lo, hi, *a, **kw))
+ return None
+ wrapped.__doc__ = getattr(fn, "__doc__", None)
+ wrapped.__wrapped__ = fn
+ return wrapped
+
+
+def _gemv_r(lo, hi, x, trellis, suh, svh, out, scratch, counters, K, mcg = False):
+ return (x[lo:hi], trellis, suh, svh, out[lo:hi], scratch, counters, K, mcg)
+
+
+def _gemv_r_multi(lo, hi, x, trellis, suh, svh, outs, scratch, counters, K, mcg = False):
+ return (x[lo:hi], trellis, suh, svh, [o[lo:hi] for o in outs], scratch, counters, K, mcg)
+
+
+def _gr_mix_q8(lo, hi, s3, fq, fsc, uq, usc, w, eps, dots, post, mixed):
+ return (s3[lo:hi], fq, fsc, uq, usc, w, eps, dots[lo:hi], None if post is None else post[lo:hi], mixed[lo:hi])
+
+
+def install():
+ global _installed
+ if _installed or not ON:
+ return
+ _installed = True
+ if hasattr(ext, "exl3_dec_gemv_r"):
+ ext.exl3_dec_gemv_r = _split(ext.exl3_dec_gemv_r, lambda x, *a, **k: x.shape[0], _gemv_r)
+ if hasattr(ext, "exl3_dec_gemv_r_multi"):
+ ext.exl3_dec_gemv_r_multi = _split(ext.exl3_dec_gemv_r_multi, lambda x, *a, **k: x.shape[0], _gemv_r_multi)
+ if hasattr(ext, "gr_mix_q8"):
+ ext.gr_mix_q8 = _split(ext.gr_mix_q8, lambda s3, *a, **k: s3.shape[0], _gr_mix_q8)