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 TQ: drop the LUT experiment variants

YanissAmzf5e7007e72ab
diff --git a/exllamav3/modules/attention_fn/cu/qdec.cu b/exllamav3/modules/attention_fn/cu/qdec.cu
index cd113cf..8e58c58 100644
--- a/exllamav3/modules/attention_fn/cu/qdec.cu
+++ b/exllamav3/modules/attention_fn/cu/qdec.cu
@@ -59,21 +59,10 @@ template<int B> __device__ __forceinline__ u32 negbias2() { return (u32)(0x8000
__device__ __forceinline__ u32 bytesel(int b) { return (u32)b | ((u32)(4 + b) << 8); }
// TurboQuant: packed raw pair (1024 + raw in each half) -> half2 (codebook[raw] * scale); the codebook sits in smem as fp16 bits
-#ifndef TQ_LUT
-#define TQ_LUT 0 // 0: u16 table in smem | 1: timing experiment, no table (wrong values) | 2: table replicated per lane (u32 slots, bank = lane)
-#endif
__device__ __forceinline__ u32 lut2(u32 x, u32 s2, const u16* cb)
{
-#if TQ_LUT == 1
- return hmul2(hsub2(x, 0x64006400u), s2);
-#elif TQ_LUT == 2
- const u32* cw = (const u32*)cb + (threadIdx.x & 31); // entry e of this lane's copy at word e * 32 + lane
- u32 lo = cw[(x & 0x3FFu) << 5], hi = cw[((x >> 16) & 0x3FFu) << 5];
- return hmul2(lo | (hi << 16), s2);
-#else
u32 lo = cb[x & 0x3FFu], hi = cb[(x >> 16) & 0x3FFu];
return hmul2(lo | (hi << 16), s2);
-#endif
}
struct DqK { u32 sel8, sh4, sh2, sel2[2], sh1, mu8, mu4, mu2; };
@@ -137,14 +126,8 @@ qdec_split(
int split_len, int num_pages_per_seq, int num_splits, const float* sinks_unused,
const u16* __restrict__ cbk, const u16* __restrict__ cbv)
{
-#if TQ && TQ_LUT == 2
- __shared__ __align__(16) u32 cbk_r[(1 << KB) * 32];
- __shared__ __align__(16) u32 cbv_r[(1 << VB) * 32];
- const u16* cbk_s = (const u16*)cbk_r; const u16* cbv_s = (const u16*)cbv_r;
-#else
__shared__ u16 cbk_s[TQ ? (1 << KB) : 1];
__shared__ u16 cbv_s[TQ ? (1 << VB) : 1];
-#endif
extern __shared__ __align__(16) unsigned char smem[];
u16* Qs = (u16*)smem;
unsigned char* ring = smem + ((NT * 8 * QSTR * 2 + 15) / 16) * 16;
@@ -161,13 +144,8 @@ qdec_split(
// ---- q rows -> rotated (h32) fp16 in smem
if (TQ) { // q arrives already rotated: plain copy (K dim order permuted like below)
-#if TQ_LUT == 2
- for (int i = tid; i < (1 << KB) * 32; i += NTHREADS) cbk_r[i] = cbk[i >> 5];
- for (int i = tid; i < (1 << VB) * 32; i += NTHREADS) cbv_r[i] = cbv[i >> 5];
-#else
for (int i = tid; i < (1 << KB); i += NTHREADS) cbk_s[i] = cbk[i];
for (int i = tid; i < (1 << VB); i += NTHREADS) cbv_s[i] = cbv[i];
-#endif
for (int idx = tid; idx < NT * 8 * HD; idx += NTHREADS) {
int r = idx / HD, d = idx % HD;
u16 x = 0;
diff --git a/exllamav3/modules/attention_fn/qdec_cuda.py b/exllamav3/modules/attention_fn/qdec_cuda.py
index 0d4f00a..2a25b73 100644
--- a/exllamav3/modules/attention_fn/qdec_cuda.py
+++ b/exllamav3/modules/attention_fn/qdec_cuda.py
@@ -75,7 +75,7 @@ def _compile(cfg):
defs = dict(HD=cfg["hd"], KB=cfg["kb"], VB=cfg["vb"], NKV=cfg["nkv"], NQH=cfg["nqh"], QLEN=cfg["qlen"],
PAGE=cfg["page"], NW=cfg["nw"], ST=cfg["st"], CAUSAL=int(cfg["causal"]), BLOCK_ROWS=cfg["block_rows"],
HD_PAD=triton.next_power_of_2(cfg["hd"]), SCALE=repr(float(cfg["scale"])) + "f", KEY_LO=cfg.get("key_lo", 0),
- TQ=int(cfg.get("tq", False)), TQ_LUT=int(os.environ.get("EXL3_QDEC_TQ_LUT", "0")))
+ TQ=int(cfg.get("tq", False)))
defs["L2HINT"] = int(os.environ.get("EXL3_QDEC_L2HINT", "1")) # L2 evict_first on K/V, evict_last on the scales
defs["FASTDQ"] = 1 if cfg.get("tq") else int(os.environ.get("EXL3_QDEC_FASTDQ", "1")) # permuted-order PRMT/LOP3 bit-plane unpack (qdec.cu)
if os.environ.get("EXL3_QDEC_ABL"):
@@ -160,13 +160,6 @@ def rows_nw(hd):
return int(os.environ.get("EXL3_QDEC_RNW", "0")) or (4 if (hd // 32) % 4 == 0 else 2)
-def _tq_static(cfg):
- """static smem of the TurboQuant codebooks: 2^bits u16 each, or 2^bits x 32 u32 each with the per-lane replicated table (EXL3_QDEC_TQ_LUT=2)"""
- if os.environ.get("EXL3_QDEC_TQ_LUT", "0") == "2":
- return ((1 << cfg["kb"]) + (1 << cfg["vb"])) * 128 + 1024
- return 1024
-
-
def pick_nw_st(cfg):
"""(warps per CTA, ring depth), measured on a 3090 at 128K context (K/V bits 4/4, 6/6, 8/8): 8 x 2 for hd128 with
narrow codes, 4 x 2 otherwise; shrinks until the shared memory fits the opt-in limit"""
@@ -181,7 +174,7 @@ def pick_nw_st(cfg):
narrow = cfg["hd"] == 128 and cfg["kb"] + cfg["vb"] <= 8
for nw, st in (((8, 2), (4, 2), (4, 1), (2, 2), (2, 1)) if narrow else ((4, 2), (4, 1), (2, 2), (2, 1))):
c.update(nw=nw, st=st)
- if geometry(c)["shared"] <= 99 * 1024 - (_tq_static(cfg) if cfg.get("tq") else 0): # + the static codebooks
+ if geometry(c)["shared"] <= 99 * 1024 - (1024 if cfg.get("tq") else 0): # + the static codebooks
return nw, st
raise QdecUnsupported("no ring configuration fits")