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.

knobs: read EXL3_BC_KVWIN, EXL3_CUDA_GRAPH_RING, EXL3_DSA_LAT_*, EXL3_KDA_HF* through util.knobs

YanissAmz5cac49f04c49
diff --git a/exllamav3/model/cuda_graph.py b/exllamav3/model/cuda_graph.py
index f4955b8..473027b 100644
--- a/exllamav3/model/cuda_graph.py
+++ b/exllamav3/model/cuda_graph.py
@@ -56,6 +56,8 @@ from collections import Counter, OrderedDict
import torch
+from ..util.knobs import knob_on
+
_env_int = lambda name, default: int(os.environ.get(name, default) or default)
# Module global: a harness may flip it between arms (then call purge()).
@@ -290,7 +292,7 @@ class CudaGraphRunner:
# KVWIN ring-only models (plain attention + fp16 sink/window rings riding the recurrent state slots): the ring ids are
# static slot data exactly like a GDN model's, the ring writer/reader run inside the capture (bc_attn.py)
from ..cache import kvwin
- self.has_ring = bool(kvwin.ANY_ACTIVE) and os.environ.get("EXL3_CUDA_GRAPH_RING", "1") != "0" and not (self.has_gdn or self.has_conv or self.has_mamba or self.has_swa)
+ self.has_ring = bool(kvwin.ANY_ACTIVE) and knob_on("EXL3_CUDA_GRAPH_RING") and not (self.has_gdn or self.has_conv or self.has_mamba or self.has_swa)
if len(devs) != 1 or (self.has_gdn and self.has_conv):
return False # GDN graphs pass device slot ids, ShortConv reads them on the host: no mixed model
dev = devs.pop()
diff --git a/exllamav3/modules/attention_fn/bc_attn.py b/exllamav3/modules/attention_fn/bc_attn.py
index 9a15f99..9c29bd0 100644
--- a/exllamav3/modules/attention_fn/bc_attn.py
+++ b/exllamav3/modules/attention_fn/bc_attn.py
@@ -5,6 +5,7 @@ import torch
from ...ext import exllamav3_ext as ext
from ...constants import PAGE_SIZE
from ...util.tensor import g_tensor_cache
+from ...util.knobs import knob_on, on_change
"""
Graph-captured decode attention (BC_Attention): the whole attention block for a decode step --
@@ -64,7 +65,13 @@ MAX_BSZ_KW = 8 # BC_Attention.MAX_BSZ
_RING_BN = int(os.environ.get("EXL3_BC_RING_BN", "256"))
_RING_WARPS = int(os.environ.get("EXL3_BC_RING_WARPS", "8"))
_RING_STAGES = int(os.environ.get("EXL3_BC_RING_STAGES", "1"))
-_kvwin_bc = os.environ.get("EXL3_BC_KVWIN", "1") != "0" # KVWIN ring inside the BC_Attention graph
+_kvwin_bc = knob_on("EXL3_BC_KVWIN") # KVWIN ring inside the BC_Attention graph
+
+
+@on_change
+def _refresh_kvwin_bc():
+ global _kvwin_bc
+ _kvwin_bc = knob_on("EXL3_BC_KVWIN")
def _is_pow2(n: int) -> bool:
diff --git a/exllamav3/modules/attention_fn/dsa_triton.py b/exllamav3/modules/attention_fn/dsa_triton.py
index 5193d3b..9985767 100644
--- a/exllamav3/modules/attention_fn/dsa_triton.py
+++ b/exllamav3/modules/attention_fn/dsa_triton.py
@@ -30,6 +30,7 @@ The lightning-indexer scoring kernel is shared as-is between raw-token (V3.2) an
import os
import torch
from ...util.tensor import g_tensor_cache
+from ...util.knobs import knob, knob_int
# EXL3_DSA_DEBUG_BOUNDS=1: compile the JIT DSA kernels with device-side bounds asserts on
# every block-table page read and gathered pool index (names the kernel and traps at the
@@ -1610,13 +1611,13 @@ def dsa_attn(
bh, bn, nw, dc, *ext = (int(x) for x in _lat.split(":")) if ":" in _lat else (32, 16, 4, 64)
kv1, pf, ns = (list(ext) + [0, 0, 1][len(ext):])[:3]
# EXL3_DSA_LAT_OSPLIT (read per call, opt-in): split the D_c output accumulator across n programs
- osplit = int(os.environ.get("EXL3_DSA_LAT_OSPLIT", "1"))
+ osplit = knob_int("EXL3_DSA_LAT_OSPLIT", 1)
assert osplit == 1 or not kv1, "EXL3_DSA_LAT_OSPLIT > 1 needs KV1 = 0"
# EXL3_DSA_LAT_2P (read per call): "BN1:NW1:BN2:NW2[:STORE]" = two-pass latent kernel (pass 1 QK ->
# exact row max/sum, pass 2 PV without rescale; STORE=1 keeps pass-1 scores in fp32, row-sliced
# <= 512 MB, and pass 2 skips QK). Default 64:4:16:4:1 since mla-prefill step 4 (-36 % kernel,
# PPL 10x4096 +0.054 %, KL 3.5e-3); "0" = the one-pass kernel above.
- _2p = os.environ.get("EXL3_DSA_LAT_2P", "64:4:16:4:1")
+ _2p = knob("EXL3_DSA_LAT_2P", "64:4:16:4:1")
with torch.cuda.device(q.device):
if _2p != "0":
bn1, nw1, bn2, nw2, *st = (int(x) for x in _2p.split(":"))
diff --git a/exllamav3/vendor/fla/hip/kda_hf_hip.py b/exllamav3/vendor/fla/hip/kda_hf_hip.py
index 79bc009..d81eef5 100644
--- a/exllamav3/vendor/fla/hip/kda_hf_hip.py
+++ b/exllamav3/vendor/fla/hip/kda_hf_hip.py
@@ -6,6 +6,7 @@ import ctypes, hashlib, os, subprocess
import torch
import triton
from exllamav3.util import hip_compiler
+from exllamav3.util.knobs import knob
from exllamav3.util.hip_lib import load_hip_runtime
_SRC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "kda_hf.hip")
@@ -46,7 +47,7 @@ def _load(defs=""):
def kda_hf_ok(q, k, v, g, beta, initial_state, chunk_size):
"""q, k [1, T, H, 128] bf16 (l2-normalized), v [1, T, HV, 128] bf16, g [1, T, HV, 128] fp32 = 64-row-local log2 cumsum,
beta [1, T, HV] bf16, all contiguous."""
- if os.environ.get("EXL3_KDA_HF", "0") != "1" or _state.get("fail"):
+ if knob("EXL3_KDA_HF", "0") != "1" or _state.get("fail"):
return False
B, T, H, K = q.shape
HV, V = v.shape[2], v.shape[3]
@@ -63,7 +64,7 @@ def chunk_kda_hf(q, k, v, g, beta, scale, initial_state, output_final_state, ckp
if defs is None:
# diagonal 16x16 blocks: from fla's token_parallel kernel (exact fp32 pairwise decay) by default; EXL3_KDA_HF_DIAG=1 (read
# per call) computes them in the kernel with bf16 WMMA (faster, but heavier per-token error tails on real GLM inputs)
- defs = "" if os.environ.get("EXL3_KDA_HF_DIAG", "0") == "1" else "KHF_TP=1"
+ defs = "" if knob("EXL3_KDA_HF_DIAG", "0") == "1" else "KHF_TP=1"
try:
fn = _load(defs)
except Exception: