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
Hy4 docs: new decode and prefill flags, native Engram IO build, sparse prefill from 2048 keys
YanissAmz169186e915d4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f2e9269..6d168ca 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,7 +5,7 @@Hy4-flash (GGUF Q3_K) on one Strix Halo machine. Numbers: see the benchmark table.- New `tools/hy4/serve.py`: OpenAI-compatible server for Hy4-flash with prefill fast path, HIP-graph decode, MTP drafts and prompt-lookup rows. Guide: `doc/hy4.md`.-- Sparse-attention prefill: per-query gather MLA kernel in HIP/WMMA (`hipsp/`, H = 32 and H = 64), Triton fallback; blocked indexer score with linear-time exact top-k; sparse path from 16K keys.+- Sparse-attention prefill: per-query gather MLA kernel in HIP/WMMA (`hipsp/`, H = 32 and H = 64), Triton fallback; blocked indexer score with linear-time exact top-k; sparse path from 2048 keys.- Long-context decode: exact top-k sparse attend (`HY4_LC_SPARSE`), draft-cache fill with the same selection.- Prefill: fused dequant GEMMs, WMMA expert kernels shared with the GGUF MoE path, CK latent-attention core, dense GEMMs split in pieces of 8192 rows above 8192 rows.- Decode: static-buffer graph step, MTP head from a Q5_K copy of the output head, n-gram rows on top of the drafts, Engram rows prefetched by row.@@ -13,3 +13,7 @@ Hy4-flash (GGUF Q3_K) on one Strix Halo machine. Numbers: see the benchmark tabl- Generic GGUF loader (`EXL3_GGUF_GENERIC=1`, off by default) and its CPU tests.- Context: 128K tokens. Single user (`--slots` is experimental). Greedy decoding only.- A missing built kernel library (repository extension, MoE extension, attention libraries) stops the server with the install step; `HY4_ALLOW_SLOW=1` keeps the old slow-path start.+- Decode levers on by default: head-batched MLA attention (`HY4_MLA_HB`), k_b / v_b and output-head products on `tl.dot` (`HY4_BG_DOT`, `HY4_HEAD_DOT`), fp16 router weights (`HY4_RG_F16`), fused K-row / q-rope kernels for verify rows (`HY4_KV_FUSED_MAXT`). Step tests in `tools/hy4/step/`.+- The MTP draft-cache fill after prefill writes only K / V and the indexer key state (`HY4_PRIME_KVONLY`, on by default).+- Prefill levers on by default: fused SwiGLU + cast and cast-add glue, finer M-split of the dense GEMMs (`HY4_PF_G_SWIGLU`, `HY4_PF_G_ADD`, `HY4_PF_MM_FINE`); Engram host side with a numpy hash, a single prefetch worker and native row reads (`HY4_ENGRAM_NPHASH`, `HY4_ENGRAM_PF_WORKERS`, `HY4_ENGRAM_NATIVE_IO`); sparse prefill attention from 2048 keys.+- Native Engram IO is built with `gcc` at first use (`~/.cache/kyojin/engram_io`). Without `gcc`, or when the build fails, the server uses the Python reader.diff --git a/doc/hy4.md b/doc/hy4.mdindex 9ae5643..de1fd7f 100644--- a/doc/hy4.md+++ b/doc/hy4.md@@ -52,10 +52,21 @@ The server speaks the OpenAI API (`/v1/chat/completions`, `/v1/completions`, bot| variable | shipped | effect ||---|---|---|| `HY4_LC_SPARSE` | 1 | exact top-k sparse attention in decode for long context |-| `HY4_PF_SPARSE`, `HY4_PF_SPARSE_MINN` | 1, 16384 | sparse prefill attention from 16K keys |+| `HY4_PF_SPARSE`, `HY4_PF_SPARSE_MINN` | 1, 2048 | sparse prefill attention from 2048 keys || `HY4_PF_MM_SPLIT` | 8192 | dense prefill GEMMs of more than 8192 rows run in pieces of 8192 (`0` = off) || `HY4_NGRAM_EXT`, `HY4_NGRAM_MIN` | 4, 8 | prompt-lookup rows added to the MTP drafts when the last 8 tokens occurred before || `HY4_MTP_HEAD` | q5k | head of the MTP drafts |+| `HY4_MLA_HB` | 1 | decode attention: one kernel reads each K tile once for 16 heads (fp16 `tl.dot`); `HY4_MLA_HB_SPLIT` adds a key-split path for few-row steps |+| `HY4_BG_DOT`, `HY4_HEAD_DOT` | 1 | k_b / v_b and output-head products of the verify rows on `tl.dot` (used from 5 rows for k_b / v_b, from 3 rows for the head) |+| `HY4_RG_F16` | 1 | fp16 resident router weights for the router mat-vec, fp32 accumulate |+| `HY4_KV_FUSED_MAXT` | 16 | the fused K-row / q-rope kernels take verify rows up to this count (was 1 row) |+| `HY4_PRIME_KVONLY` | 1 | the draft-cache fill at the end of prefill writes only K / V and the indexer key state (no queries, selection, attention or MoE) |+| `HY4_PF_G_SWIGLU`, `HY4_PF_G_ADD`, `HY4_PF_MM_FINE` | 1 | prefill glue: fused SwiGLU + cast, fused cast-add of the MoE layer tail, finer M-split of the dense GEMMs |+| `HY4_ENGRAM_NPHASH`, `HY4_ENGRAM_PF_WORKERS` | 1, 1 | Engram hash in numpy; one prefetch worker |+| `HY4_ENGRAM_NATIVE_IO` | 1 | Engram row reads in C threads (`pread`, no GIL) |+| `HY4_ENGRAM_FUSED` | 0 | two-launch fused Engram block in decode (opt-in) |++Native Engram IO: `exllamav3/loader/engram_io.c` is compiled with `gcc` at first use into `~/.cache/kyojin/engram_io` (`XDG_CACHE_HOME` moves it). When `gcc` is missing or the build fails, the server prints one line and uses the Python reader, which does the same reads more slowly (`HY4_ENGRAM_NATIVE_IO=0` selects it directly).`--num-draft` is the number of MTP drafts per round (3 by default). Memory: the K buffers are sized by `-c` (about 0.1 MB per position).diff --git a/tools/hy4/serve.py b/tools/hy4/serve.pyindex 32dfb6f..b5f86b1 100644--- a/tools/hy4/serve.py+++ b/tools/hy4/serve.py@@ -53,7 +53,7 @@ SHIPPED_ENV = {"HY4_PREFILL_MOE": "1", "HY4_PREFILL_DENSE": "1", "HY4_PREFILL_ATTN": "1", "HY4_PREFILL_IX": "1", "HY4_ENGRAM_PREFETCH": "1","HY4_PF_F16": "1", "HY4_MOE_NFIRST": "1", "KEEPCACHE": "1", # prefill set"HY4_LC_SPARSE": "1", "HY4_LC_PRIME": "1", # long context: exact top-k sparse decode attend (NLL inside the dense-vs-null band at 8K / 16K), draft-cache fill selects with the prefill scorer- "HY4_PF_SPARSE": "1", "HY4_PF_SPARSE_MINN": "2048", # sparse prefill attention (HIP kernel via SP_SO, Triton fallback) from 16K keys: 33K prefill 60.6 -> 42 s, 128K flat ~790 tok/s; NLL 32K 4.5226 vs dense 4.5231 (nulls 4.511-4.515); below 16K dense CK (KL at 4096 with sparse 0.1089 vs nulls 0.0988-0.1054)+ "HY4_PF_SPARSE": "1", "HY4_PF_SPARSE_MINN": "2048", # sparse prefill attention (HIP kernel via SP_SO, Triton fallback) from 2048 keys (first measured from 16K keys): 33K prefill 60.6 -> 42 s, 128K flat ~790 tok/s; NLL 32K 4.5226 vs dense 4.5231 (nulls 4.511-4.515); below 16K dense CK (KL at 4096 with sparse 0.1089 vs nulls 0.0988-0.1054)"HY4_ENGRAM_NPHASH": "1", "HY4_ENGRAM_NATIVE_IO": "1", "HY4_ENGRAM_PF_WORKERS": "1", "HY4_PF_G_SWIGLU": "1", "HY4_PF_G_ADD": "1", "HY4_PF_MM_FINE": "1", # prefill levers (box A/B 20/11 pf2_A / pf2_B: prefill +11 / +7.6 / +6.5 % at 8K / 32K / 64K, passkey 3/3, KL 0.108 vs noise nulls 0.103-0.108)"HY4_MLA_HB": "1", "HY4_BG_DOT": "1", "HY4_HEAD_DOT": "1", "HY4_RG_F16": "1", # decode levers (box A/B 20/11, 256 tok x2: verify round -7 % at 4K, -4 % at 32K, plain flat; qual6 KL 0.94 x noise null)"HY4_PF_WOT": "0", "HY4_MOE_HIP": "2", "HY4_PF_CK": "1", "HY4_PF_FUSE": "1", # prefill set 2: shared gm_ext WMMA experts (HY4_GM_EXT), CK MLA core (EXL3_CKMLA_SO), one-pass hc / norm / indexer kernels