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
ROCm prefill attention: waves_per_eu=2 launch hint for the fp16 kernel (hd <= 256), bit-identical
YanissAmzf5e240c9b990
diff --git a/exllamav3/modules/attention_fn/triton_paged.py b/exllamav3/modules/attention_fn/triton_paged.pyindex a13e162..6520a02 100644--- a/exllamav3/modules/attention_fn/triton_paged.py+++ b/exllamav3/modules/attention_fn/triton_paged.py@@ -722,6 +722,9 @@ _pf_fa2_rows = int(os.environ.get("EXL3_PF_FA2_ROWS", "1024"))# runs 10 TFLOPS at 120K, 256-row slices 21). Default on for ROCm only (CUDA not measured)_pf_row_slice = int(os.environ.get("EXL3_PF_ROW_SLICE", "256" if torch.version.hip else "0"))+# ROCm waves_per_eu launch hint of the fp16 prefill kernel (hd <= 256); 0 = compiler default+_pf_waves_per_eu = int(os.environ.get("EXL3_PF_WAVES_PER_EU", "2"))+def _prefill_fa2_contig(q, kd, vd, past, n_kvh, head_dim, scale, out):from torch.nn.attention import sdpa_kernel, SDPBackendfrom torch.nn.attention.bias import causal_lower_right@@ -2165,6 +2168,13 @@ def paged_attn_triton_prefill(_maxnreg = int(os.environ.get("EXL3_QC_PF_MAXNREG", "255" if qc is not None and qck + qcv >= 16 else "0"))# the ROCm Triton backend has no maxnreg launch option (it raises on the unknown keyword)_launch_opts = {"maxnreg": _maxnreg} if _maxnreg and not torch.version.hip else {}+ if torch.version.hip and qc is None and hd_pad <= 256:+ # gfx1151: the 128-row tile sits at the 256-VGPR cap and spills; waves_per_eu=2 changes the allocation, not the math+ # (bit-identical): hd256 24q/4kv 4096-row chunk +7 % (21 -> 22.8 TFLOPS at 32K past), hd128 32q/4kv +45 % (19.7 -> 28.5)+ _launch_opts["waves_per_eu"] = _pf_waves_per_eu+ # EXL3_ATTN_PREFILL_OPTS="matrix_instr_nonkdim=16,...": extra ROCm Triton launch options (A/B), applied last+ for _kv in filter(None, os.environ.get("EXL3_ATTN_PREFILL_OPTS", "").split(",")):+ _launch_opts[_kv.split("=")[0]] = int(_kv.split("=")[1])grid = (q_blocks, bsz * n_q_heads, num_splits)slice_blocks = 0if num_splits == 1 and _pf_row_slice > 0:diff --git a/tests/test_prefill_waves_per_eu.py b/tests/test_prefill_waves_per_eu.pynew file mode 100644index 0000000..27558bc--- /dev/null+++ b/tests/test_prefill_waves_per_eu.py@@ -0,0 +1,46 @@+"""+The waves_per_eu launch hint of the ROCm prefill kernel (EXL3_PF_WAVES_PER_EU, default 2) only changes the register allocation:+the output must be bit-identical to the compiler default (0) for causal / windowed / ragged / GQA geometries.+"""+import sys, os+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+import pytest+import torch++pytestmark = pytest.mark.skipif(not torch.cuda.is_available() or torch.version.hip is None, reason = "needs a ROCm GPU (Triton)")++from exllamav3.modules.attention_fn import triton_paged as tp++PAGE = 256+device = "cuda:0"++[email protected]("hd, n_heads, n_kv, q_len, past, window", [+ (256, 24, 4, 4096, 3000, None),+ (256, 24, 4, 1000, 0, None),+ (256, 24, 4, 2500, 777, None),+ (128, 32, 4, 2048, 5000, None),+ (128, 32, 8, 1536, 5000, None),+ (256, 16, 2, 2048, 4096, 1024),+])+def test_waves_per_eu_bit_identical(hd, n_heads, n_kv, q_len, past, window):+ torch.manual_seed(1)+ pages = (past + q_len + PAGE - 1) // PAGE+ kc = (torch.randn((pages, PAGE, n_kv, hd), device = device) * 0.5).half()+ vc = torch.randn((pages, PAGE, n_kv, hd), device = device).half()+ bt = torch.arange(pages, dtype = torch.int32, device = device)[None]+ q = torch.randn((1, q_len, n_heads, hd), device = device).half()+ k = torch.randn((1, q_len, n_kv, hd), device = device).half()+ v = torch.randn((1, q_len, n_kv, hd), device = device).half()+ outs = []+ for w in (0, 2):+ old = tp._pf_waves_per_eu+ tp._pf_waves_per_eu = w+ try:+ sl = torch.tensor([past], dtype = torch.int32, device = device)+ outs.append(tp.paged_attn_triton_prefill(+ q, k, v, kc.clone(), vc.clone(), bt, sl, causal = True, softmax_scale = hd ** -0.5,+ window_size = window, max_kv_len = past))+ finally:+ tp._pf_waves_per_eu = old+ assert torch.equal(outs[0], outs[1])