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.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
Bring up gfx1201 (RDNA4) (#139)
resynthbf9c65443949
diff --git a/exllamav3/exllamav3_ext/hip/hip_mma.cuh b/exllamav3/exllamav3_ext/hip/hip_mma.cuhindex aeca502..e7359f3 100644--- a/exllamav3/exllamav3_ext/hip/hip_mma.cuh+++ b/exllamav3/exllamav3_ext/hip/hip_mma.cuh@@ -47,7 +47,7 @@ using FragC_h = HipVec<half2, 2>; // legacy fp16-accumulate shape, kept for sh// Arch family macros. gfx12 (RDNA4) and gfx11.5 (RDNA3.5) both have a wave32// v_wmma_f32_16x16x16_f16, but with DIFFERENT builtins and DIFFERENT fragment// layouts -- they are not interchangeable. See the layout comments below.-#if defined(EXL3_HIP_WMMA_GFX12)+#if defined(__gfx1200__) || defined(__gfx1201__)#define EXL3_HIP_WMMA_GFX12 1#endif#if defined(__gfx1150__) || defined(__gfx1151__) || defined(__gfx1152__)diff --git a/exllamav3/exllamav3_ext/quant/exl3_gemv_kernel.cuh b/exllamav3/exllamav3_ext/quant/exl3_gemv_kernel.cuhindex a03247b..586677c 100644--- a/exllamav3/exllamav3_ext/quant/exl3_gemv_kernel.cuh+++ b/exllamav3/exllamav3_ext/quant/exl3_gemv_kernel.cuh@@ -36,6 +36,14 @@#else#include "../ptx.cuh"#endif+// Build-time regression guard: the gfx12 WMMA path is inert unless EXL3_HIP_WMMA_GFX12 is+// defined from the arch guards in hip_mma.cuh (a one-line regression there silently emitted+// zeros/garbage on gfx1200/gfx1201), so fail the device pass loudly instead.+#if defined(__HIP_DEVICE_COMPILE__) && (defined(__gfx1200__) || defined(__gfx1201__)) \+ && !defined(EXL3_HIP_WMMA_GFX12)+#error "gfx12: EXL3_HIP_WMMA_GFX12 must be defined for gfx1200/gfx1201"+#endif+#include "exl3_dq.cuh"#include "exl3_kernel_map.cuh"diff --git a/exllamav3/modules/attention_fn/qdec_hip.py b/exllamav3/modules/attention_fn/qdec_hip.pyindex d75b51e..9bd8120 100644--- a/exllamav3/modules/attention_fn/qdec_hip.py+++ b/exllamav3/modules/attention_fn/qdec_hip.py@@ -17,13 +17,34 @@ from ...util.knobs import knob, knob_int, knob_on, on_change_SRC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "qdec.hip")_CACHE = os.path.expanduser(os.environ.get("EXL3_QDEC_CACHE", "~/.cache/exllamav3"))-ENABLED = bool(torch.version.hip) and knob_on("EXL3_QDEC_HIP")+++def _gfx115_family0() -> bool:+ """qdec.hip uses gfx11.5-only (RDNA3.5) wave32 WMMA; enable it only when device 0 is that+ family. On a mixed gfx1201+gfx1151 box (RX 9070 exposed as device 0) quantized-KV decode+ keeps the Triton fallback (triton_paged.py) instead of trying to compile gfx11.5 WMMA for+ gfx1201. An extension without the family probe keeps the historical behavior."""+ if not torch.version.hip:+ return False+ try:+ from ...ext import exllamav3_ext as ext+ except Exception: # noqa: BLE001+ return False+ if not hasattr(ext, "exl3_gemv_wmma_family"):+ return True+ try:+ return ext.exl3_gemv_wmma_family(0) == 2+ except Exception: # noqa: BLE001+ return False+++ENABLED = bool(torch.version.hip) and _gfx115_family0() and knob_on("EXL3_QDEC_HIP")@on_changedef _refresh_knobs():global ENABLED- ENABLED = bool(torch.version.hip) and knob_on("EXL3_QDEC_HIP")+ ENABLED = bool(torch.version.hip) and _gfx115_family0() and knob_on("EXL3_QDEC_HIP")_kernels = {}_bufs = {}diff --git a/exllamav3/modules/hyperconnections.py b/exllamav3/modules/hyperconnections.pyindex 143aaec..4291568 100644--- a/exllamav3/modules/hyperconnections.py+++ b/exllamav3/modules/hyperconnections.py@@ -500,6 +500,28 @@ def _gr_hip():return _gr_hip_mod[0]+def _wmma_family0() -> int:+ """WMMA family of device 0: 0 none, 1 gfx12 (RDNA4), 2 gfx11.5 (RDNA3.5).++ gr_mix.hip is a gfx11.5-only hand kernel (different builtin and fragment layout from+ gfx12) and its JIT compiles for device 0, so it must not be selected when device 0 is a+ gfx1201 part -- the PyTorch/reference gr path stays. Mirrors exl3_gemv_wmma_family, with an+ arch-name fallback for builds that predate the probe."""+ try:+ return ext.exl3_gemv_wmma_family(0)+ except Exception: # noqa: BLE001+ pass+ try:+ arch = torch.cuda.get_device_properties(0).gcnArchName.split(":")[0]+ if arch in ("gfx1200", "gfx1201"):+ return 1+ if arch in ("gfx1150", "gfx1151", "gfx1152"):+ return 2+ except Exception: # noqa: BLE001+ pass+ return 0++class GatedResidual(Module):"""Qwen4Exp-style gated residual: the low-rank, elementwise cousin of mHC. The residual is the@@ -730,6 +752,7 @@ class GatedResidual(Module):if self.use_combine else Nonefuse = _GR_PF_FUSE and dev.type == "cuda" and torch.version.hip is not Nonegr_hip_ok = (R > 32 and os.environ.get("EXL3_GR_HIP", "0") == "1" and fuse and self.use_combine and H == 4+ and _wmma_family0() == 2and tuple(self.proj_h.shape) == (324, 10240) and tuple(self.up_h.shape) == (10240, 320)and self.proj_h.dtype == torch.half and self.up_h.dtype == torch.halfand self.proj_h.is_contiguous() and self.up_h.is_contiguous())diff --git a/exllamav3/modules/quant/exl3.py b/exllamav3/modules/quant/exl3.pyindex eb48a93..061a892 100644--- a/exllamav3/modules/quant/exl3.py+++ b/exllamav3/modules/quant/exl3.py@@ -230,6 +230,7 @@ def _had_cache_put(inner, n_offset, n, w, clock):_f32_via_f16 = os.environ.get("EXL3_HIP_F32OUT_VIA_F16", "1") != "0" and bool(torch.version.hip)_f32_via_f16_min_rows = int(os.environ.get("EXL3_HIP_F32OUT_VIA_F16_MIN_ROWS", "33"))_hip_gemv_support_cache: dict[int, bool] = {}+_hip_gemv_family_cache: dict[int, int] = {}# Batch-1 decode kernels (exl3_dec.cu, gfx11.5): one launch per GEMV with both Hadamard stages# fused. EXL3_DEC=0 disables them (falls back to exl3_gemv / reconstruct).@@ -294,9 +295,13 @@ def wide_scratch(device: torch.device):def dec_supported(inner) -> bool:- """True when a LinearEXL3 can run the exl3_dec kernels (mul1 codebook, supported K, shapes)."""+ """True when a LinearEXL3 can run the exl3_dec kernels (mul1 codebook, supported K, shapes).++ The exl3_dec kernels are gfx11.5 (RDNA3.5) WMMA only, so the gate also pins the device to+ family 2 -- on gfx12 (RDNA4) the direct WMMA GEMV path must be used instead."""return (EXL3_DEC and bool(torch.version.hip) and hasattr(ext, "exl3_dec_gemv") and+ _hip_wmma_family(inner.trellis.device) == 2 andinner.mul1 and not inner.mcg and (int(round(inner.K * 2)) in _DEC_KB2_DENSE or(inner.K == 8 and os.environ.get("EXL3_DENSE_K8") == "1" and@@ -318,6 +323,7 @@ def dec_moe_supported(inner) -> bool:"""return (EXL3_DEC and bool(torch.version.hip) and hasattr(ext, "exl3_dec_moe") and+ _hip_wmma_family(inner.trellis.device) == 2 and(inner.mul1 or inner.mcg) and int(round(inner.K * 2)) in _DEC_KB2 andinner.K * 2 == int(round(inner.K * 2)) andinner.in_features % 512 == 0 and inner.out_features % 128 == 0 and@@ -336,6 +342,16 @@ def _hip_gemv_supported(device: torch.device) -> bool:return _hip_gemv_support_cache[index]+def _hip_wmma_family(device: torch.device) -> int:+ """Cache ext.exl3_gemv_wmma_family(index): 0 none, 1 gfx12 (RDNA4), 2 gfx11.5 (RDNA3.5)."""+ if not torch.version.hip or not hasattr(ext, "exl3_gemv_wmma_family"):+ return 0+ index = device.index if device.index is not None else torch.cuda.current_device()+ if index not in _hip_gemv_family_cache:+ _hip_gemv_family_cache[index] = ext.exl3_gemv_wmma_family(index)+ return _hip_gemv_family_cache[index]++class LinearEXL3:quant_type: str = "exl3"diff --git a/tests/test_dense_k8_cpu.py b/tests/test_dense_k8_cpu.pyindex fc140d6..73cdf51 100644--- a/tests/test_dense_k8_cpu.py+++ b/tests/test_dense_k8_cpu.py@@ -60,14 +60,18 @@ int main() {return !(run<10>() && run<12>() && run<14>() && run<16>());}subprocess.run([str(exe)],check=True,env={**os.environ,'ASAN_OPTIONS':'detect_leaks=0'})-def helpers():+def helpers(family=2):tree = ast.parse((ROOT / 'exllamav3/modules/quant/exl3.py').read_text())nodes = [n for n in tree.body if- isinstance(n, ast.FunctionDef) and n.name in ('dec_supported','dec_moe_supported') or- isinstance(n, ast.Assign) and any(isinstance(t,ast.Name) and t.id in- ('_DEC_KB2','_DEC_KB2_DENSE','_DENSE_K8_SHAPES') for t in n.targets)]- ns = {'os':os,'torch':NS(version=NS(hip=True)), 'EXL3_DEC':True,- 'ext':NS(exl3_dec_gemv=True,exl3_dec_moe=True)}+ (isinstance(n, ast.FunctionDef) and n.name in ('dec_supported','dec_moe_supported','_hip_wmma_family')) or+ (isinstance(n, (ast.Assign, ast.AnnAssign)) and any(isinstance(t,ast.Name) and t.id in+ ('_DEC_KB2','_DEC_KB2_DENSE','_DENSE_K8_SHAPES','_hip_gemv_family_cache') for t in+ (n.targets if isinstance(n, ast.Assign) else [n.target])))]+ ns = {'os':os,+ 'torch':NS(version=NS(hip=True), device=object, cuda=NS(current_device=lambda:0)),+ 'EXL3_DEC':True,+ 'ext':NS(exl3_dec_gemv=True, exl3_dec_moe=True,+ exl3_gemv_wmma_family=lambda index: family)}exec(compile(ast.Module(body=nodes,type_ignores=[]),'eligibility','exec'),ns)return ns@@ -75,7 +79,7 @@ def helpers():def inner(k=8, shape=(2560,10240)):i,o=shapereturn NS(K=k,mul1=True,mcg=False,in_features=i,out_features=o,- trellis=NS(shape=(i//16,o//16,128)),suh=1,svh=1)+ trellis=NS(shape=(i//16,o//16,128),device=NS(index=0)),suh=1,svh=1)class DenseK8Checks(unittest.TestCase):@@ -107,5 +111,12 @@ class DenseK8Checks(unittest.TestCase):setattr(x,attribute,value)self.assertFalse(helpers()['dec_supported'](x))+ def test_wmma_family_gates_dec_kernels(self):+ with patch.dict(os.environ, {'EXL3_DENSE_K8':'1'}):+ for family,enabled in [(2,True),(1,False),(0,False)]:+ ns = helpers(family)+ self.assertEqual(ns['dec_supported'](inner()), enabled, family)+ self.assertEqual(ns['dec_moe_supported'](inner(k=2)), enabled, family)+if __name__ == '__main__':unittest.main()diff --git a/tools/strix_halo/patch_gfx115.py b/tools/strix_halo/patch_gfx115.pyindex 490dc92..4146344 100644--- a/tools/strix_halo/patch_gfx115.py+++ b/tools/strix_halo/patch_gfx115.py@@ -75,11 +75,18 @@ using HipFp32x8 = __attribute__((__vector_size__(8 * sizeof(float)))) float;"family macros + HipFp16x16 typedef")# Swap the remaining raw gfx1200/gfx1201 guards in hip_mma.cuh to the macro so-# the file reads consistently (there are several).+# the file reads consistently (there are several). The guard that DEFINES the macro+# (inserted above) must stay a raw arch test: rewriting it would make the macro+# self-referential and leave it undefined, silently killing the whole gfx12 WMMA path+# (this is exactly the regression that left the RX 9070 emitting zeros/garbage).s = mma.read_text()raw = "#if defined(__gfx1200__) || defined(__gfx1201__)"+define_guard = raw + "\n #define EXL3_HIP_WMMA_GFX12 1"+placeholder = "// __EXL3_GFX12_DEFINE_GUARD__"if raw in s:+ s = s.replace(define_guard, placeholder)s = s.replace(raw, "#if defined(EXL3_HIP_WMMA_GFX12)")+ s = s.replace(placeholder, define_guard)mma.write_text(s)print(f" OK: normalized {raw!r} -> EXL3_HIP_WMMA_GFX12 in hip_mma.cuh")changed.append(str(mma))