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.

qdec: default the single-buffered S exchange (SMM) on for single-sequence calls

YanissAmzf6de4a3e5c30
diff --git a/exllamav3/modules/attention_fn/qdec_hip.py b/exllamav3/modules/attention_fn/qdec_hip.py
index 3d881cd..389630c 100644
--- a/exllamav3/modules/attention_fn/qdec_hip.py
+++ b/exllamav3/modules/attention_fn/qdec_hip.py
@@ -65,8 +65,9 @@ def geometry(hd, nqh, nkv, qlen, nw, dw, smm = 0, sxmul = 0):
def make_cfg(q_len, n_q_heads, n_kv_heads, head_dim, k_bits, v_bits, page_size, causal, sm_scale,
- window_left, window_right, softcap, kv_append_len, has_sinks, key_lo = 0, tq = False):
- """Kernel config for a call, or None when the Triton kernels must run it. key_lo: KVWIN, positions below it are not attended"""
+ window_left, window_right, softcap, kv_append_len, has_sinks, key_lo = 0, tq = False, bsz = 1):
+ """Kernel config for a call, or None when the Triton kernels must run it. key_lo: KVWIN, positions below it are not attended
+ bsz: sequences in the call; it only feeds the EXL3_QDEC_HIP_SMM default (auto: on for one sequence, see below)"""
if (not ENABLED or window_left >= 0 or window_right >= 0 or softcap or kv_append_len != q_len
or not (2 <= k_bits <= 8) or not (2 <= v_bits <= 8)):
return None
@@ -77,8 +78,11 @@ def make_cfg(q_len, n_q_heads, n_kv_heads, head_dim, k_bits, v_bits, page_size,
dw = pick_dw(head_dim, nt, nw)
if dw is None:
return None
- smmv = int(knob_int("EXL3_QDEC_HIP_SMM", 0))
- smm = int(smmv != 0 and dw > 1 and nt >= 3) # measured: nt3 -39 %, nt2 +1 %, nt1 flat
+ smmk = knob("EXL3_QDEC_HIP_SMM", "auto")
+ smmv = (1 if bsz == 1 else 0) if smmk == "auto" else int(smmk)
+ # measured (131K, 36/48 rows, 3 q tiles): single buffer -37 % with one sequence, +1 % with 2 or 4
+ # sequences batched (fewer, longer splits hide the extra per-slab barrier); nt2 +1 %, nt1 flat
+ smm = int(smmv != 0 and dw > 1 and nt >= 3)
sxmul = 2 if smmv == 2 else 0 # SMM=2: same kernel as SMM=1 but the old (double) allocation, a footprint probe
_, _, shared = geometry(head_dim, n_q_heads, n_kv_heads, q_len, nw, dw, smm, sxmul)
if shared > 64 * 1024:
diff --git a/exllamav3/modules/attention_fn/triton_paged.py b/exllamav3/modules/attention_fn/triton_paged.py
index 083512d..9eca6dd 100644
--- a/exllamav3/modules/attention_fn/triton_paged.py
+++ b/exllamav3/modules/attention_fn/triton_paged.py
@@ -1263,7 +1263,8 @@ def _qdec_hip_decode(q, k_cache, v_cache, block_table, cache_seqlens, causal, so
window_left, window_right = _normalize_window(window_size)
sinks, has_sinks = _prep_sinks(sinks, n_q_heads, q)
cfg = _qh.make_cfg(q_len, n_q_heads, n_kv_heads, head_dim, qck, qcv, k_cache.shape[1], causal, softmax_scale,
- window_left, window_right, softcap, kv_append_len, has_sinks, ring.cfg.S if ring is not None else 0, tq is not None)
+ window_left, window_right, softcap, kv_append_len, has_sinks, ring.cfg.S if ring is not None else 0, tq is not None,
+ bsz = bsz)
if cfg is None:
if _QDEC_HIP_DEBUG: _qdec_hip_note(("no", f"cfg q_len {q_len} hd {head_dim} {n_q_heads}/{n_kv_heads} bits {qck},{qcv} window {window_left},{window_right} softcap {softcap} append {kv_append_len}"))
return None
diff --git a/exllamav3/util/knobs.py b/exllamav3/util/knobs.py
index 4ce3837..4333678 100644
--- a/exllamav3/util/knobs.py
+++ b/exllamav3/util/knobs.py
@@ -49,7 +49,7 @@ KNOBS = {
"EXL3_QDEC_HIP_SPL": "",
"EXL3_QDEC_HIP_WAVES": "0",
"EXL3_QDEC_HIP_VPF": "1",
- "EXL3_QDEC_HIP_SMM": "0",
+ "EXL3_QDEC_HIP_SMM": "auto",
"EXL3_QDEC_HIP_FLAGS": "",
}