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 attention: one many-row decode launch for the whole R-row block

YanissAmz97dd961c2ba9
diff --git a/exllamav3/modules/attn.py b/exllamav3/modules/attn.py
index 0241b2f..220098e 100644
--- a/exllamav3/modules/attn.py
+++ b/exllamav3/modules/attn.py
@@ -1399,7 +1399,7 @@ class Attention(Module):
max_kv_len = int(cs_host.max())
if (
1 < seqlen <= MAX_BSZN_GEMV_R and non_causal_spans is None and
- os.environ.get("EXL3_VERIFY_ATTN_LOOP", "0") != "0"
+ knobs.knob_on("EXL3_VERIFY_ATTN_LOOP", "0")
):
# Row-invariant verify: the R-row paged decode tiles the KV span from the batch's single
# cache_seqlens/q_len, a different float order than R batch-1 calls. Run the exact
@@ -1532,7 +1532,7 @@ class Attention(Module):
if max_kv_len is None and seqlen > 16 and not torch.version.hip:
max_kv_len = int(params["cache_seqlens"][sl].max())
# EXL3_VERIFY_ATTN_LOOP: the R-row paged decode as R one-row calls, as decode_flash_attn does
- rows = range(seqlen) if 1 < seqlen <= MAX_BSZN_GEMV_R and os.environ.get("EXL3_VERIFY_ATTN_LOOP", "0") != "0" else None
+ rows = range(seqlen) if 1 < seqlen <= MAX_BSZN_GEMV_R and knobs.knob_on("EXL3_VERIFY_ATTN_LOOP", "0") else None
def call(qq, kk, vv, cs):
return attn_dispatch(
q = qq, k = kk, v = vv,
diff --git a/exllamav3/modules/sliding_attn.py b/exllamav3/modules/sliding_attn.py
index bd67d28..b417d0e 100644
--- a/exllamav3/modules/sliding_attn.py
+++ b/exllamav3/modules/sliding_attn.py
@@ -18,9 +18,17 @@ from ..cache.recurrent import (
new_checkpoint_handle,
)
from ..model.model_tp_alloc import TPAllocation
-from ..util import profile_opt
+from ..util import profile_opt, knobs
import os
+
+def _verify_attn_loop() -> bool:
+ """EXL3_VERIFY_ATTN_LOOP, falling back to EXL3_DEC_MOE_UNION when neither is set (knob table default: "0")"""
+ v = knobs.knob("EXL3_VERIFY_ATTN_LOOP", "0")
+ if "EXL3_VERIFY_ATTN_LOOP" not in os.environ:
+ v = knobs.knob("EXL3_DEC_MOE_UNION", "0")
+ return v != "0"
+
# Sliced Q/K/V(/G) projection bundle at decode (see attn.py); EXL3_QKV_SLICE=0 disables it
_qkv_slice_enable = os.environ.get("EXL3_QKV_SLICE", "1") != "0"
@@ -1157,7 +1165,7 @@ class SlidingAttention(Module):
# call itself.
if (
1 < seqlen <= MAX_BSZN_GEMV_R and params.get("dflash_verify") and
- os.environ.get("EXL3_VERIFY_ATTN_LOOP", os.environ.get("EXL3_DEC_MOE_UNION", "0")) != "0"
+ _verify_attn_loop()
):
if os.environ.get("EXL3_VERIFY_ATTN_ROWS", "1") != "0" and q.shape[0] == 1 and bt.shape[0] == 1:
# one append + one attention launch, bitwise the R batch-1 calls below
diff --git a/exllamav3/util/knobs.py b/exllamav3/util/knobs.py
index 6ba390e..919b552 100644
--- a/exllamav3/util/knobs.py
+++ b/exllamav3/util/knobs.py
@@ -22,6 +22,7 @@ KNOBS = {
"EXL3_DEC_MOE_KBS_B": "0",
"EXL3_PF_CK": "auto",
"EXL3_PF_WAVES_PER_EU": "2",
+ "EXL3_VERIFY_ATTN_LOOP": "0",
"EXL3_QDEC": "1",
"EXL3_QDEC_HIP": "1",
"EXL3_QDEC_GRAPH": "1",
diff --git a/tools/qwen/serve.py b/tools/qwen/serve.py
index b835eef..980b75b 100644
--- a/tools/qwen/serve.py
+++ b/tools/qwen/serve.py
@@ -510,7 +510,18 @@ class Retract(int):
# prefill at 4K/16K), and EXL3_PF_SKIP (the MTP draft prefill fills K/V only and skips the 1-row lm_head, +0.5 % to +2 %).
# Set any of them to 0 to go back.
SERVE_ENV = (("EXL3_HOST_LEAN", "1"), ("EXL3_HOST_CUTS", "1"), # batched verify readback + fewer host dispatches: +0.8 % speculative, ids identical
- ("EXL3_MOE_FUSED", "1"), ("EXL3_MOE_VALU", "1"), ("EXL3_VERIFY_ATTN_LOOP", "1"),
+ # 28/10 gfx1151: the verify block's attention runs as ONE R-row launch (qdec.hip, the ROCm many-row
+ # kernel, counterpart of cu/qdec_rows.cu on the 3090), not as R batch-1 calls: those re-dequantize the same
+ # KV window per row (16 full-attn layers x 5 launches at 5 rows). Price, ONE load per cell,
+ # ABBA, shipped env, k4v4, 10 steps: verify(3 rows) 4K 89.2 -> 83.8 ms, 32K 99.3 -> 87.2,
+ # 131K 128.8 -> 104.4, 262K 169.0 -> 131.3 (-6/-12/-19/-22 %); verify(6 rows) 4K
+ # 108.4 -> 102.6, 131K 181.6 -> 140.7 (-5/-22 %). Numerics: a different reduction order, gated
+ # per row against the bitwise loop at 4K/32K/131K (3 and 6 rows): top-1 equal on every row,
+ # max|dlogit| <= 0.078, KL <= 9.3e-5 (4-bit KV cache noise level). Served, ONE server life,
+ # /admin/knobs ABBA, 12K prompt, 200 tokens: per-round t_verify R2 77.4 -> 74.8, R3 83.6 ->
+ # 79.5, R4 88.5 -> 82.0, R5 97.9 -> 89.2, R8 110.7 -> 100.6 ms (=-3/-5/-7/-9/-9 %), tokens/round
+ # 3.0/3.0. 1 goes back to the batch-1 loop (bitwise vs plain decode).
+ ("EXL3_MOE_FUSED", "1"), ("EXL3_MOE_VALU", "1"), ("EXL3_VERIFY_ATTN_LOOP", "0"),
("EXL3_VERIFY_GEMV_R", "1"), ("EXL3_GEMV_R_DEC1", "1"), ("EXL3_MTP_FUSE_CATCHUP", "0"),
("EXL3_PLE_HIP", "1"), ("EXL3_DQ_HIP", "1"), ("EXL3_GR_HIP", "1"), ("EXL3_GDN_FUSE", "1"), ("EXL3_PF_SKIP", "1"),
# the attention / GDN blocks keep o_proj's fp16 output (the residual apply widens in-kernel) and the ablit projection