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 serve: clamp the load warm-up prompt to the context (a small -c no longer fails the warm-up)
YanissAmze8cb95b2a3cc
diff --git a/tests/test_hy4_warmup_clamp.py b/tests/test_hy4_warmup_clamp.pynew file mode 100644index 0000000..964f47d--- /dev/null+++ b/tests/test_hy4_warmup_clamp.py@@ -0,0 +1,69 @@+"""zero-GPU check: the load warm-up prompt is clamped to the context (a requested HY4_WARMUP_TOKENS above ctx no longer raises ValueError("context"))"""+import os+import sys+import types++HERE = os.path.dirname(os.path.abspath(__file__))+TREE = os.path.dirname(HERE)+sys.path.insert(0, os.path.join(TREE, "tools", "hy4"))++import engine as E+++def _fake(ctx, k=3):+ """an engine without model or GPU: generate() applies the real context bound and records the prompt length"""+ e = object.__new__(E.Hy4Engine)+ e.ctx, e.k, e.seen = ctx, k, []++ def generate(ids, max_new, on_tokens, **kw):+ if len(ids) + max_new + e.k + 2 > e.ctx:+ raise ValueError("context")+ e.seen.append(len(ids))+ return {}++ e.generate = generate+ e.reset = lambda: None+ e.warmup_tails = lambda: None+ return e+++def _run(monkeypatch, ctx, n, k=3):+ for v in ("HY4_PRECAPTURE", "HY4_LC_PRIME", "HY4_WARMUP_TAILS"):+ monkeypatch.delenv(v, raising=False)+ monkeypatch.setenv("HY4_WARMUP_TAILS", "0")+ if hasattr(E.Hy4Engine, "_warmup"): # builds that stage the Engram rows (HY4_WARMUP_NO_ENGRAM) import the GPU loader: stub it+ eg = types.SimpleNamespace(READ={"bytes": 0, "dummy_bytes": 0}, DUMMY=[False])+ for name in ("exllamav3", "exllamav3.loader"):+ monkeypatch.setitem(sys.modules, name, types.ModuleType(name))+ monkeypatch.setitem(sys.modules, "exllamav3.loader.engram_gpu", eg)+ sys.modules["exllamav3.loader"].engram_gpu = eg+ monkeypatch.setattr(E, "_proc_io", lambda: (0, 0), raising=False)+ e = _fake(ctx, k)+ e.warmup(n)+ return e.seen+++def test_clamp_value():+ assert E.warmup_clamp(8493, 8192, 3) == 8192 - (8 + 3 + 2 + E.WARMUP_PAD)+ assert E.warmup_clamp(8493, 70000, 3) == 8493+ assert E.warmup_clamp(8163, 8192, 3) == 8163 # exactly at the bound: unchanged+ assert E.warmup_clamp(8493, 200, 3) == 0 # ctx too small: skip+++def test_small_ctx_warmup_runs(monkeypatch):+ seen = _run(monkeypatch, 8192, 8493)+ assert seen == [E.warmup_clamp(8493, 8192, 3)] and seen[0] + 8 + 3 + 2 <= 8192+++def test_large_ctx_unchanged(monkeypatch):+ assert _run(monkeypatch, 70000, 8493) == [8493]+++def test_tiny_ctx_skips(monkeypatch, capsys):+ assert _run(monkeypatch, 200, 8493) == []+ assert "warm-up skipped: ctx too small" in capsys.readouterr().out+++if __name__ == "__main__":+ import pytest+ sys.exit(pytest.main([__file__, "-q"]))diff --git a/tools/hy4/engine.py b/tools/hy4/engine.pyindex adfb4ca..99c352e 100644--- a/tools/hy4/engine.py+++ b/tools/hy4/engine.py@@ -21,6 +21,23 @@ CHUNK_DEFAULT = 8192PRIME_ROWS = int(os.environ.get("HY4_PRIME_ROWS", "2048")) # rows per batched MTP draft-cache fill call+WARMUP_MIN = 256 # below this many prompt tokens a warm-up compiles nothing useful: skip it+WARMUP_PAD = 16 # row alignment of the last prefill chunk (the static buffers also keep 64 spare rows, see serve.apply_env)+++def warmup_clamp(n: int, ctx: int, k: int, new: int = 8) -> int:+ """Prompt length of the load warm-up: generate() accepts n + new + k + 2 <= ctx, so a requested n above ctx - (new + k + 2 + WARMUP_PAD) is clamped+ to that bound (the server would never become ready otherwise). Returns 0 (skip) when the bound is below WARMUP_MIN. Unchanged when n fits."""+ room = ctx - (new + k + 2 + WARMUP_PAD)+ if n <= room:+ return n+ if room < WARMUP_MIN:+ print(f"warm-up skipped: ctx too small (requested {n}, ctx {ctx})", flush=True)+ return 0+ print(f"warm-up clamped {n} -> {room} (ctx {ctx})", flush=True)+ return room++def _stub_package(tree: str):"""import loader modules by path without importing the whole exllamav3 package (as the bench harnesses do)"""for n, s in (("exllamav3", ""), ("exllamav3.loader", "loader")):@@ -134,6 +151,9 @@ class Hy4Engine:def warmup(self, n: int):"""one synthetic request of n prompt tokens + 8 decode tokens: compiles the Triton prefill kernels (they would land in the first user chunk, about 0.3 s) and captures the decode graphs"""+ n = warmup_clamp(n, self.ctx, self.k)+ if n <= 0:+ returnids = [(i * 7919 + 13) % 50000 for i in range(n)]t0 = time.perf_counter()self.generate(ids, 8, lambda toks: False)diff --git a/tools/hy4/mu_engine.py b/tools/hy4/mu_engine.pyindex ae9a14d..a9072dc 100644--- a/tools/hy4/mu_engine.py+++ b/tools/hy4/mu_engine.py@@ -11,7 +11,7 @@ import threadingimport timefrom collections import deque-from engine import Hy4Engine, PRIME_ROWS+from engine import Hy4Engine, PRIME_ROWS, warmup_clampclass MuEngine(Hy4Engine):@@ -321,6 +321,9 @@ class MuScheduler(threading.Thread):def warmup(sch: MuScheduler, n: int, new: int = 24):"""compile / capture what a served mix needs at the first bucket: B = 1 .. slots concurrent requests of n prompt tokens (graphs per (bucket, rows), MTP chains per slot)"""+ n = warmup_clamp(n, sch.eng.ctx, sch.eng.k, new)+ if n <= 0:+ returneng = sch.engids = [(i * 7919 + 13) % 50000 for i in range(n)]for B in range(1, eng.slots + 1):