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.

Hy4 serve: --slots > 1 boots on the shipped defaults (HY4_LC_SPARSE off with slots), CPU tests of the slot boot and slab index ranges

YanissAmz5763b9782ac4
diff --git a/tests/test_hy4_mu_boot.py b/tests/test_hy4_mu_boot.py
new file mode 100644
index 0000000..3597e12
--- /dev/null
+++ b/tests/test_hy4_mu_boot.py
@@ -0,0 +1,86 @@
+"""Zero-GPU checks of the served --slots path.
+1. serve.apply_env(slots > 1) leaves the shipped long-context levers MuEngine refuses OFF (the 1.9.0 release clone died at construction: HY4_LC_SPARSE=1 from SHIPPED_ENV vs the
+ MuEngine guard; the server stayed up with /health 500 and the benchmark driver waited for it). An explicit value still wins; slots == 1 keeps the shipped flags.
+2. The flat-slab index math of step_slots / indexer_forward_slots (row base + position, pooled group rows, group start + offset) stays inside [0, S * cap) for every session count
+ B <= S, every bucket Nb <= cap and every position, including the first chunk of a fresh slot and the warm-up shape (64-token prompts)."""
+import os
+import sys
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+TREE = os.path.dirname(HERE)
+sys.path.insert(0, os.path.join(TREE, "tools", "hy4"))
+
+import serve # noqa: E402
+
+GUARDED = ("HY4_SWA_RING", "HY4_LC_SPARSE")
+
+
+def _clean(env):
+ for k in list(os.environ):
+ if k.startswith("HY4_") and k not in ("HY4_ALLOW_SLOW",):
+ del os.environ[k]
+ os.environ.update(env)
+
+
+def test_slots_apply_env_turns_guarded_flags_off():
+ _clean({})
+ serve.apply_env(4096, "", slots=8)
+ for f in GUARDED:
+ assert os.environ.get(f, "0") in ("", "0"), f
+ assert os.environ["HY4_LC_PRIME"] == "1" and os.environ["HY4_PF_SPARSE"] == "1" # the other shipped levers stay
+
+
+def test_single_session_keeps_shipped_flags():
+ _clean({})
+ serve.apply_env(4096, "", slots=1)
+ assert os.environ["HY4_LC_SPARSE"] == "1"
+ _clean({})
+ serve.apply_env(4096)
+ assert os.environ["HY4_LC_SPARSE"] == "1"
+
+
+def test_explicit_value_wins():
+ _clean({"HY4_LC_SPARSE": "1"})
+ serve.apply_env(4096, "", slots=8)
+ assert os.environ["HY4_LC_SPARSE"] == "1"
+
+
+def _slab_indices(S, cap, k, rows, Nb):
+ """rows = [(slot, n_before, n_new)] -> every flat index step_slots / indexer_forward_slots builds"""
+ out = []
+ for slot, n0, nt in rows:
+ base = slot * cap
+ for p in range(n0, n0 + nt):
+ flat = base + p
+ out.append(("kv / vgb write", flat, S * cap))
+ out.append(("pool write", flat // k, S * cap // k))
+ g0 = (flat // k) * k
+ for a in range(k):
+ out.append(("vgb group read", g0 + a, S * cap))
+ Pb = Nb // k
+ for a in range(Pb):
+ out.append(("pool score read", base // k + a, S * cap // k))
+ for a in range(Nb): # MLA core reads keys base + 0 .. N - 1
+ out.append(("mla key read", base + a, S * cap))
+ return out
+
+
+def test_slab_gather_indices_in_range():
+ S, k = 8, 4
+ for ctx in (2048, 4096):
+ cap = ((ctx + 64 + 511) // 512) * 512
+ assert cap % k == 0
+ for B in range(1, S + 1):
+ for n0, nt in ((0, 64), (0, 1), (64, 1), (64, 4), (cap - 8, 4)):
+ top = n0 + nt
+ Nb = min(cap, ((top - 1) // 64 + 1) * 64)
+ rows = [(s, n0, nt) for s in range(B)]
+ for what, idx, hi in _slab_indices(S, cap, k, rows, Nb):
+ assert 0 <= idx < hi, (what, ctx, B, n0, nt, idx, hi)
+
+
+def test_padding_rows_are_never_indexed():
+ """the graph is keyed (Nb, T) with T = real rows: the static input past T is stale and never read (MultiDecoder.step_slots copies hin[:, :T] and the ops slice [:T])"""
+ import inspect
+ src = open(os.path.join(TREE, "exllamav3", "loader", "step_mu.py")).read()
+ assert "inp[2, :self.T]" in src and "assert 1 <= T <= TM" in src
diff --git a/tools/hy4/serve.py b/tools/hy4/serve.py
index 3bc3359..5c6d17c 100644
--- a/tools/hy4/serve.py
+++ b/tools/hy4/serve.py
@@ -85,9 +85,12 @@ def check_kernels() -> None:
print(f"hy4 serve: WARNING {m}: slow path (HY4_ALLOW_SLOW=1)", file=sys.stderr, flush=True)
-def apply_env(ctx: int, model: str = "") -> None:
+SLOTS_OFF = ("HY4_LC_SPARSE",) # shipped long-context levers that act on the single-session K / indexer buffers: mu_engine.MuEngine refuses them with --slots > 1
+
+
+def apply_env(ctx: int, model: str = "", slots: int = 1) -> None:
for k, v in SHIPPED_ENV.items():
- os.environ.setdefault(k, v)
+ os.environ.setdefault(k, "0" if slots > 1 and k in SLOTS_OFF else v) # an explicit value still wins (and MuEngine refuses it)
os.environ.setdefault("HY4_NOSYNC_CAP", str(((ctx + 64 + 511) // 512) * 512)) # K buffers / token history: fixed for the life of the process
# the measured line also runs with frozen TunableOp results for the prefill GEMMs and a start-up request that compiles the prefill kernels and captures the decode graphs
tune = os.path.join(TREE, "tools", "hy4", "tunableop_gfx1151.csv")
@@ -410,7 +413,7 @@ def main(argv=None):
ap.add_argument("--slots", type=int, default=1, help="concurrent sessions decoded in ONE batched step (1 = the single-request engine behind the lock)")
ap.add_argument("--sched-chunk", type=int, default=1024, help="prefill rows per scheduler turn with --slots > 1 (a decode round of the other sessions runs between chunks)")
args = ap.parse_args(argv)
- apply_env(args.max_ctx, args.model)
+ apply_env(args.max_ctx, args.model, args.slots)
check_kernels()
st = State(args)
app = build_app(st)