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.

ROCm qdec.hip: issue a slab's V runs before its S stage (EXL3_QDEC_HIP_VPF)

YanissAmz6e8bdc925857
diff --git a/exllamav3/modules/attention_fn/qdec.hip b/exllamav3/modules/attention_fn/qdec.hip
index 50c3a70..75b2d31 100644
--- a/exllamav3/modules/attention_fn/qdec.hip
+++ b/exllamav3/modules/attention_fn/qdec.hip
@@ -55,6 +55,9 @@ typedef u32 v8u __attribute__((ext_vector_type(8)));
#ifndef KEY_LO
#define KEY_LO 0 // KVWIN: tokens below KEY_LO are not attended (the fp16 ring serves the sinks)
#endif
+#ifndef VPF
+#define VPF 1 // this slab's V runs are issued before its S stage, so their DRAM latency overlaps
+#endif // the S dequant/WMMA and the softmax (bit-identical, scheduling only; 0 = pre-lever order)
__device__ __forceinline__ u32 hsub2(u32 a, u32 b) { return __builtin_bit_cast(u32, __builtin_bit_cast(v2h, a) - __builtin_bit_cast(v2h, b)); }
__device__ __forceinline__ u32 hmul2(u32 a, u32 b) { return __builtin_bit_cast(u32, __builtin_bit_cast(v2h, a) * __builtin_bit_cast(v2h, b)); }
@@ -325,8 +328,24 @@ qdec_split(
v8f S[NT];
#pragma unroll
for (int j = 0; j < NT; j++) S[j] = (v8f){0, 0, 0, 0, 0, 0, 0, 0};
+#if VPF && !TQF
+ u32 vr[16][NRW > 0 ? NRW : 1]; // this slab's V runs, loaded up front (see VPF)
+ u32 vsc[16];
+#endif
if (active) {
+#if VPF && !TQF
+ {
+ const int dcol = dw * HDW + DTW * n;
+ const int gi_v = dcol >> 5, p0 = dcol & 31;
+ #pragma unroll
+ for (int e = 0; e < 16; e++) {
+ size_t row = (size_t) row0 + min(e, lim);
+ load_run(vr[e], v_cache + row * (GPT * VB) + kvh * VCHW + gi_v * VB, p0);
+ vsc[e] = TQ ? ((u32) v_scales[row * NKV + kvh] * 0x10001u) : scale2<VB>(v_scales[row * GPT + kvh * G + gi_v]);
+ }
+ }
+#endif
// ---- S (partial over this wave's k-steps) = Kdeq x q^T
#pragma unroll
for (int gl = 0; gl < GWV; gl++) {
@@ -476,6 +495,7 @@ qdec_split(
}
}
#else
+#if !VPF
const int cur_row0 = row0, cur_lim = lim;
const int dcol = dw * HDW + DTW * n;
const int gi_v = dcol >> 5, p0 = dcol & 31;
@@ -487,6 +507,7 @@ qdec_split(
load_run(vr[e], v_cache + row * (GPT * VB) + kvh * VCHW + gi_v * VB, p0);
vsc[e] = TQ ? ((u32) v_scales[row * NKV + kvh] * 0x10001u) : scale2<VB>(v_scales[row * GPT + kvh * G + gi_v]);
}
+#endif
// next slab's K (kw is dead now)
if (it + 1 < iters && (sw + (it + 1) * NSW) < nslabs) { slab_rows(it + 1); load_k(); }
#pragma unroll
diff --git a/exllamav3/modules/attention_fn/qdec_hip.py b/exllamav3/modules/attention_fn/qdec_hip.py
index e86e0b7..c1dfae3 100644
--- a/exllamav3/modules/attention_fn/qdec_hip.py
+++ b/exllamav3/modules/attention_fn/qdec_hip.py
@@ -81,13 +81,15 @@ def make_cfg(q_len, n_q_heads, n_kv_heads, head_dim, k_bits, v_bits, page_size,
if shared > 64 * 1024:
return None
return dict(hd=head_dim, kb=k_bits, vb=v_bits, nkv=n_kv_heads, nqh=n_q_heads, qlen=q_len, page=page_size, nw=nw, dw=dw,
- causal=bool(causal), scale=float(sm_scale), sinks=bool(has_sinks), key_lo=int(key_lo), tq=bool(tq))
+ causal=bool(causal), scale=float(sm_scale), sinks=bool(has_sinks), key_lo=int(key_lo), tq=bool(tq),
+ vpf=bool(knob_int("EXL3_QDEC_HIP_VPF", 1)))
def _compile(cfg, arch):
from exllamav3.util import hip_compiler
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"], DW=cfg["dw"], CAUSAL=int(cfg["causal"]), HAS_SINKS=int(cfg["sinks"]), KEY_LO=cfg["key_lo"], TQ=int(cfg.get("tq", False)), SCALE=repr(float(cfg["scale"])) + "f")
+ NW=cfg["nw"], DW=cfg["dw"], CAUSAL=int(cfg["causal"]), HAS_SINKS=int(cfg["sinks"]), KEY_LO=cfg["key_lo"], TQ=int(cfg.get("tq", False)),
+ VPF=int(cfg.get("vpf", False)), SCALE=repr(float(cfg["scale"])) + "f")
extra = [f"-D{k}={v}" for k, v in defs.items()] + knob("EXL3_QDEC_HIP_FLAGS", "").split()
flags = ["--genco", f"--offload-arch={arch}", "-O3", "-ffp-contract=off", "--no-gpu-bundle-output"] + extra
gcc = os.environ.get("EXL3_GCC_INSTALL_DIR", "/usr/lib/gcc/x86_64-linux-gnu/13")
diff --git a/exllamav3/util/knobs.py b/exllamav3/util/knobs.py
index 47cccee..55bd7fd 100644
--- a/exllamav3/util/knobs.py
+++ b/exllamav3/util/knobs.py
@@ -41,6 +41,7 @@ KNOBS = {
"EXL3_QDEC_HIP_MAXO": "96",
"EXL3_QDEC_HIP_SPL": "",
"EXL3_QDEC_HIP_WAVES": "0",
+ "EXL3_QDEC_HIP_VPF": "1",
"EXL3_QDEC_HIP_FLAGS": "",
}