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.

Add EXL3_PLAIN_ROWS_VERIFY: plain multi-session decode steps take the R-row exact paths

YanissAmz5217591db000
diff --git a/exllamav3/generator/generator.py b/exllamav3/generator/generator.py
index 22f3b0a..67ef892 100644
--- a/exllamav3/generator/generator.py
+++ b/exllamav3/generator/generator.py
@@ -44,7 +44,7 @@ from .job import Job, _ttrace_begin, _ttrace_end, _TAIL_REPLY as _TAIL_REPLY_GEN
_REPLY_FIRST = os.environ.get("EXL3_REPLY_FIRST", "0") == "1"
from . import spec_sample
from .filter import Filter
-from .row_groups import plan_groups, group_rows_cap, GROUPS as ROW_GROUPS
+from .row_groups import plan_groups, group_rows_cap, plain_rows_verify, GROUPS as ROW_GROUPS
from ..util.row_inv import ROW_INV
from concurrent.futures import ThreadPoolExecutor
from .sampler import Sampler
@@ -1655,7 +1655,7 @@ class Generator:
# sliding_attn.py's qkv gemv_r_multi branch) all require this marker in addition to
# the row-count bound, so they only ever fire on the one call they were verified
# bit-exact against.
- "dflash_verify": draft_tokens is not None,
+ "dflash_verify": draft_tokens is not None or plain_rows_verify(batch_ids.shape[0] * batch_ids.shape[1], False),
}
if own_pages is not None:
params["dflash_table_pages"] = own_pages
diff --git a/exllamav3/generator/row_groups.py b/exllamav3/generator/row_groups.py
index bcfc117..0d760fc 100644
--- a/exllamav3/generator/row_groups.py
+++ b/exllamav3/generator/row_groups.py
@@ -14,11 +14,24 @@ EXL3_ROW_INV_GROUP_ROWS overrides the row cap (1 = one forward per job, the slow
"""
import os
-from ..util.row_inv import ROW_INV_MAX_ROWS
+from ..util.row_inv import ROW_INV, ROW_INV_MAX_ROWS
GROUPS = {"on": os.environ.get("EXL3_ROW_INV_GROUPS", "0") not in ("", "0")}
+# Plain multi-job decode (nothing drafted, several one-token sequences in one forward) through the R-row exact paths.
+# Those paths (union MoE on the device table, R-row GEMV, batched router, per-sequence attention loops) are marked by
+# params["dflash_verify"], which only a drafted verify forward carries; a plain step of N sessions otherwise falls to the
+# per-expert eager loops and the generic multi-row kernels: N x the weight reads, and thousands of host launches.
+# Rows 2..ROW_INV_MAX_ROWS only (the range those paths are bit-exact for), one-row steps are untouched.
+# EXL3_PLAIN_ROWS_VERIFY=1 turns it on; PLAIN_ROWS["on"] is mutable at run time for one-load A/B (purge the block graphs).
+PLAIN_ROWS = {"on": os.environ.get("EXL3_PLAIN_ROWS_VERIFY", "0") not in ("", "0")}
+
+
+def plain_rows_verify(rows: int, drafted: bool) -> bool:
+ return PLAIN_ROWS["on"] and not drafted and ROW_INV["on"] and 1 < rows <= ROW_INV_MAX_ROWS
+
+
def group_rows_cap() -> int:
v = os.environ.get("EXL3_ROW_INV_GROUP_ROWS", "")
return max(1, int(v)) if v.strip() else ROW_INV_MAX_ROWS
diff --git a/tests/test_plain_rows_cpu.py b/tests/test_plain_rows_cpu.py
new file mode 100644
index 0000000..a473405
--- /dev/null
+++ b/tests/test_plain_rows_cpu.py
@@ -0,0 +1,26 @@
+"""CPU gate: which decode steps take the R-row exact paths (params["dflash_verify"]) without drafting."""
+from exllamav3.generator.row_groups import PLAIN_ROWS, plain_rows_verify
+from exllamav3.util.row_inv import ROW_INV, ROW_INV_MAX_ROWS
+
+
+def test_off_by_default_state_is_respected():
+ old = PLAIN_ROWS["on"]
+ try:
+ PLAIN_ROWS["on"] = False
+ assert not any(plain_rows_verify(r, False) for r in range(0, 20))
+ finally:
+ PLAIN_ROWS["on"] = old
+
+
+def test_on_covers_rows_two_to_max_only():
+ old, old_inv = PLAIN_ROWS["on"], ROW_INV["on"]
+ try:
+ PLAIN_ROWS["on"] = True
+ ROW_INV["on"] = True
+ got = [r for r in range(0, 20) if plain_rows_verify(r, False)]
+ assert got == list(range(2, ROW_INV_MAX_ROWS + 1))
+ assert not plain_rows_verify(4, True) # a drafted step is already marked by its caller
+ ROW_INV["on"] = False
+ assert not plain_rows_verify(4, False) # the exact paths need row invariance on
+ finally:
+ PLAIN_ROWS["on"], ROW_INV["on"] = old, old_inv