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
Merge perf/hy4-strix-193-mla2 into 1.9.3 tree
YanissAmzc5e446eb6002
diff --cc CHANGELOG.mdindex 7a52fd7,cd6af72..6182253--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -2,11 -2,8 +2,16 @@@## Unreleased (1.9.3)+- Decode levers, shipped on in `SHIPPED_ENV` (`HY4_<FLAG>=0` restores 1.9.2; code default `0`), each with a fires counter printed after the load warm-up (`FIRES <name> {...}`, `loader/lever_fires.py`) and a CPU test (`tests/test_hy4_seta_levers_cpu.py`):+ `HY4_DENSE_V2` (column-tiled few-row Q8_0 dense GEMV, `gm_dense_q8`, bit-identical to the stock kernel; rebuild `exl3_gm_ext` with `tools/hy4/install_strix.sh`),+ `HY4_MOE_V2` (routed experts through the HIP code object `moe_dec.co`, built by `install_strix.sh` step 2b, `MOE_DEC_CO` overrides the path),+ `HY4_DRAFT_MOE_TILES`, `HY4_DRAFT_MLA_BG`, `HY4_DRAFT_IX_GV` (draft MTP layer: int8 expert tile retune, Q8 absorb matrices, indexer mat-vec).+- New tools: `tools/hy4/step/opbench.py` (per-op decode microbench, no server boot) and the paired A/B drivers `ab_dend.py`, `ab_exp.py`, `mtp_items.py`, `mtp_micro.py`, `mtp_arms.sh`; model and data paths come from `GGUF` / `WIKI` (no default path).++- KV footprint: `HY4_KV_FP8_MTP=1` keeps the draft layer's K cache in fp8 too (needs `HY4_KV_FP8=1`), `HY4_KV_COMPACT=1` sets fp8 trunk + draft cache + the 1024-row window ring in one switch (about 11 KB per token instead of 113 KB); all off by default. `tools/hy4/kv_bytes.py` prints the per-component table, `tools/hy4/kv_bytes_probe.py` measures it. CPU tests: `tests/test_kv_bytes.py`.++- KV footprint 2: `HY4_IX_POOL16=1` (fp16 indexer pool, -832 bytes per token) and `HY4_ROPE_POS=1` (rope cos / sin rows evaluated from the positions of a call, no tables to the full context, -1280 bytes per token), both part of `HY4_KV_COMPACT=1` now: 9220 bytes per token (9.0 KB, 9.1 KB at 1M) instead of 11332. Off by default. CPU tests (including the Triton interpreter): `tests/test_kv10.py`; GPU gate: `tools/hy4/step/kv10_driver.py`.++- Long context: opt-in fp8 e4m3 latent K cache for the full-attention layers (`HY4_KV_FP8=1`, off by default; 644 bytes per token and layer instead of 2304) and the head-blocked split-K sparse attend that reads it (`HY4_LC_HB`, `HY4_LC_HB_SPLIT`; only runs on the fp8 cache). `-c 65536` keeps the fp32 cache. Guide: `doc/hy4.md`, "Long context option". CPU tests: `tests/test_kv_fp8.py`, `tests/test_hy4_shipped_flags.py`.+ - Hy4 decode graphs: context buckets can grow with the context (1/32 of the octave above 16K rows) instead of a fixed 512 rows, so a 256K prompt lists 225 buckets instead of 2049. `HY4_GRAPH_BUCKET_REL` (default 0 = fixed 512-row buckets, as in 1.9.2; 1 = growing buckets). CPU test: `tests/test_graph_bucket.py`.+ - Hy4 MLA2 (`HY4_MLA_ROWS2`, default 0 = off, the 1.9.2 attention path is untouched): row-batched split-K decode attention. One pass over the K rows serves all verify rows, q is streamed in chunks, the output has 4 quarters. Tunables `HY4_MLA_ROWS2_BH` 16, `_RG` 1, `_BN` 32, `_BK` 64, `_NW` 4, `_PROG` 64, `_SPLIT` 0 (auto), `_RS` 8, `_MINB` 2. `HY4_MLA_ROWS2_PRECOMPILE=1` (default 0) compiles and loads every (T, S) specialisation at the end of load, outside any graph capture. `HY4_MLA_ROWS2_TRACE=1` prints the first sighting of each launch key and flags a JIT inside a capture. Fires counter: `HY4_MLA_ROWS2_FIRES=<file>` holds one line `FIRES mla2 <n> trunk <a> draft <b> fallback {reason: n} fallback_trunk {...} fallback_draft {...}`; an A/B arm with the flag on must show n > 0 and no fallback. Measured on the Strix Halo box (Hy4-flash): precision equal to the deployed head-blocked fp16-dot kernel (1152 calls, mean abs error 2.66e-05 for both); served hang matrix 12/12 boots clean, including an empty Triton cache. The quality gate (paired dNLL + GSM8K) is still pending, so the flag stays off. CPU tests (no GPU): `tools/hy4/step/mla2_precompile_cpu_test.py`, `mla2_engine_hook_test.py`, `mla2_fires_cpu_test.py`; micro `tools/hy4/step/mla2_micro.py` (`MLA_CPU=1` for a CPU smoke run).## 1.9.2diff --cc exllamav3/loader/mtp_head.pyindex d41879c,3e866df..24ac013--- a/exllamav3/loader/mtp_head.py+++ b/exllamav3/loader/mtp_head.py@@@ -15,9 -15,10 +15,11 @@@ import timimport torch+from . import kv_fp8 as _KV8from . import moe_i8 as MIfrom . import step_graph as SG+ from . import graph_bucket as _gb+ from . import ref_fused as _rffrom . import step_nosync as _nsfrom .engram_rows import load_dense, rmsfrom .hy4_forward import _mv, head_gemm, QLinear, GG_DENSE, dense_fndiff --cc exllamav3/loader/ref_fused.pyindex d91b0cc,1f5c592..0a14247--- a/exllamav3/loader/ref_fused.py+++ b/exllamav3/loader/ref_fused.py@@@ -16,12 -17,21 +17,26 @@@ ENABLED = os.environ.get("HY4_REF_FUSEDHB = os.environ.get("HY4_MLA_HB", "0") == "1" # head-batched fp16 tl.dot decode attention (opt-in)HB_BN = int(os.environ.get("HY4_MLA_HB_BN", "16"))HB_NW = int(os.environ.get("HY4_MLA_HB_NW", "4"))+HB_ROWS = int(os.environ.get("HY4_MLA_HB_ROWS", "0")) # >= 2: verify rows (2..HB_ROWS) of a head group share ONE pass over the K rows (M = 16 heads x rows in the tl.dot; default 0 = off)+HB_ROWS_NW = int(os.environ.get("HY4_MLA_HB_ROWS_NW", "8"))+HB_ROWS_BN = int(os.environ.get("HY4_MLA_HB_ROWS_BN", "16"))+HB_ROWS_BH = int(os.environ.get("HY4_MLA_HB_ROWS_BH", "8")) # heads per program of the rows kernel (M = BH x RG; M = 64 spilled registers: 1.4 KB scratch per thread, dec7)+HB_ROWS_RG = int(os.environ.get("HY4_MLA_HB_ROWS_RG", "4")) # rows per program (power of two <= 4): more rows are split over the gridHB_SPLIT = int(os.environ.get("HY4_MLA_HB_SPLIT", "0")) # key splits per (row, head group): 0 = auto (fill the GPU: ~96 programs), 1 = off, n = fixed+ ROWS2 = os.environ.get("HY4_MLA_ROWS2", "0") == "1" # row-batched split-K decode attention (mla2): ONE pass over the K rows for all verify rows, q streamed (never resident in registers); default OFF+ R2_BH = int(os.environ.get("HY4_MLA_ROWS2_BH", "16")) # heads per program (M tile = BH x RG rows of the WMMA tile)+ R2_RG = int(os.environ.get("HY4_MLA_ROWS2_RG", "1")) # verify rows per program (power of two); more rows go over the grid (micro 20/11: RG 1 ~ RG 2 per row, the win is the spill-free q stream, not the row sharing)+ R2_BN = int(os.environ.get("HY4_MLA_ROWS2_BN", "32")) # keys per block+ R2_BK = int(os.environ.get("HY4_MLA_ROWS2_BK", "64")) # latent chunk of the QK reduction (q / K streamed in chunks)+ R2_NW = int(os.environ.get("HY4_MLA_ROWS2_NW", "4"))+ R2_PROG = int(os.environ.get("HY4_MLA_ROWS2_PROG", "64")) # target number of split programs (auto split count)+ R2_SPLIT = int(os.environ.get("HY4_MLA_ROWS2_SPLIT", "0")) # key splits: 0 = auto, n = fixed+ R2_RS = int(os.environ.get("HY4_MLA_ROWS2_RS", "8")) # column slices of the combine+ R2_MINB = int(os.environ.get("HY4_MLA_ROWS2_MINB", "2")) # minimum key blocks per split+ R2_FIRES = {"calls": 0, "fallback": {}} # fires-check of HY4_MLA_ROWS2: python-side counter of mla2 dispatches (graph capture / eager) and the reasons of decode-size calls that fell back+ R2_FIRES_FILE = os.environ.get("HY4_MLA_ROWS2_FIRES", "") # when set: the counter is written there (first calls, then every 256th, and at exit): the job reads it back as `FIRES mla2 <calls>`+ R2_TRACE = os.environ.get("HY4_MLA_ROWS2_TRACE", "0") == "1" # first sighting of every mla2 launch key on stderr: key, whether a graph capture is running, whether Triton compiled a NEW specialisation for it (JIT inside a capture = the hang hypothesis of 18_mla2_quality)+ R2_PRECOMPILE = os.environ.get("HY4_MLA_ROWS2_PRECOMPILE", "0") == "1" # 1: mla2_precompile() (called by the engine at the end of load) compiles + loads every (T, S) specialisation OUTSIDE any graph capture; default 0 = as beforeMAX_T = 16 # rows per call handled by the attention kernel (decode / short verify); more = prefill -> torch GEMMsCLAMP_MIN = 6.103515625e-5 # the old router's `sum.clamp(min=...)`diff --cc exllamav3/loader/step_graph.pyindex b672453,83160cd..9326e7a--- a/exllamav3/loader/step_graph.py+++ b/exllamav3/loader/step_graph.py@@@ -23,11 -23,10 +23,12 @@@ import torcfrom . import step_nosync as _nsfrom .engram_rows import QB, E4M3, E8M0from . import attn_eager as _ae+from . import router_gemv as _RG+from . import lever_fires as _LVFfrom .engram_stage import EngramStager- BUCKET = int(os.environ.get("HY4_GRAPH_BUCKET", "512"))+ from . import graph_bucket as _gb+ BUCKET = _gb.BASETM = int(os.environ.get("HY4_GRAPH_TM", "8")) # max rows of one graph step (verify rows)MASK64 = (1 << 64) - 1PERT = None # [cap, D] fp32 noise table (measurement arms only)diff --cc exllamav3/loader/step_mu.pyindex aed0bf2,cb4b604..0fa2731--- a/exllamav3/loader/step_mu.py+++ b/exllamav3/loader/step_mu.py@@@ -256,68 -184,17 +256,68 @@@ class MultiDecoder(SG.GraphDecoder)ps += list(range(s.n, s.n + len(toks)))bs += [s.slot * self.cap] * len(toks)top = max(top, s.n + len(toks))- Nb = min(self.cap, ((top - 1) // SG.BUCKET + 1) * SG.BUCKET)+ Nb = SG._gb.bucket(top, self.cap)gs.Nb = Nb- self.hin[0, :T] = torch.tensor(tk)- self.hin[1, :T] = torch.tensor(ps)- self.hin[2, :T] = torch.tensor(bs)- gs.inp.copy_(self.hin, non_blocking=True)- self._stage_rows(rows)- cg, _out = self._graph(Nb, T)+ what = f"step_slots T={T} Nb={Nb} rows={[(s.slot, s.n, len(t)) for s, t in rows]}" if (not fast or DBG.enabled()) else "step_slots"+ bnds = self.bounds() if fast else None+ ov = fast and (Nb, T, len(bnds)) in self.graphs # graph already captured: stage group by group while the earlier segments run+ hs = None+ with DBG.stage(what + " inputs + Engram rows"):+ if fast:+ self.hnp[0, :T] = tk+ self.hnp[1, :T] = ps+ self.hnp[2, :T] = bs+ FIRES["inp_np"] += 1+ else:+ self.hin[0, :T] = torch.tensor(tk)+ self.hin[1, :T] = torch.tensor(ps)+ self.hin[2, :T] = torch.tensor(bs)+ gs.inp.copy_(self.hin, non_blocking=True)+ if prof:+ t1 = pc()+ HT["inputs"] += t1 - t0+ t0 = t1+ if fast:+ hs = self._hash_rows(rows)+ FIRES["stage_vec"] += 1+ if not ov: # first use of this (bucket, rows): stage everything, the capture's warm-up bodies read the rows+ self._stage_group_mu(hs, 0, self.rpin.shape[0])+ else:+ self._stage_rows(rows)+ if prof:+ t1 = pc()+ HT["stage"] += t1 - t0+ t0 = t1+ if DBG.probe_enabled():+ self._probe(Nb, T, rows)+ with DBG.stage(what + " graph (capture if new)"):+ cgs, _out = self._graph(Nb, T) # the solo capture: a LIST of graph segments (Engram split), replayed in order like step_rowsself.x_out = _out[2]fw._h = _out[3]- cg.replay()+ grp = self.groups(bnds) if ov else None+ for si, cg in enumerate(cgs): # staged up front (_stage_rows / first use); with `ov` each group is read just before its own segment+ if ov and grp[si] is not None:+ t2 = pc() if prof else 0.0+ self._stage_group_mu(hs, *grp[si])+ if prof:+ dt = pc() - t2+ HT["stage"] += dt+ t0 += dt # launch = the replay calls only+ if prof:+ if getattr(self, "_tev_pool", None) is None:+ self._tev_pool = [(torch.cuda.Event(enable_timing=True), torch.cuda.Event(enable_timing=True)) for _ in range(8)]+ self._tev_pool[si][0].record()+ with DBG.stage(f"{what} replay segment {si}/{len(cgs)}"):+ cg.replay()+ if prof:+ self._tev_pool[si][1].record()+ if ov:+ FIRES["stage_ov"] += 1+ if T > 8:+ FIRES["rows_gt8"] += 1+ FIRES["steps"] += 1+ if prof:+ self._tev_n = len(cgs)self.ev.record()self.ev_set = Truefor s, toks in rows: