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 multi-session: HY4_MU_SLOT_PIN=k allocates slot k first (one run tests one slot index), HY4_MU_SYNC_ONLY=a,b syncs only the named stage families without the eager probe (bisects a fault the full sync debug masks), CPU tests

YanissAmz23f6788459f2
diff --git a/exllamav3/loader/mu_debug.py b/exllamav3/loader/mu_debug.py
index b51a321..e18be02 100644
--- a/exllamav3/loader/mu_debug.py
+++ b/exllamav3/loader/mu_debug.py
@@ -17,6 +17,17 @@ def enabled() -> bool:
return os.environ.get("HY4_MU_SYNC_DEBUG", "0") not in ("", "0")
+def only() -> list:
+ """HY4_MU_SYNC_ONLY=a,b: with the debug on, only the stages whose name contains one of these substrings sync and log, and the eager per-layer probe is skipped unless `probe` is listed.
+ A fault that the full debug masks (its syncs remove the host / device overlap) is bisected by syncing one stage family per run: `replay segment`, `draft chain`, `draft catch-up`, `prefill`, `hcur clone`."""
+ return [x.strip() for x in os.environ.get("HY4_MU_SYNC_ONLY", "").split(",") if x.strip()]
+
+
+def probe_enabled() -> bool:
+ o = only()
+ return enabled() and (not o or "probe" in o)
+
+
def sync():
if torch.cuda.is_available():
torch.cuda.synchronize()
@@ -34,7 +45,12 @@ def _stage(name):
def stage(name):
- return _stage(name) if enabled() else contextlib.nullcontext()
+ if not enabled():
+ return contextlib.nullcontext()
+ o = only()
+ if o and not any(x in name for x in o):
+ return contextlib.nullcontext()
+ return _stage(name)
_MISSING = object()
diff --git a/exllamav3/loader/step_mu.py b/exllamav3/loader/step_mu.py
index 25c708d..a9b2624 100644
--- a/exllamav3/loader/step_mu.py
+++ b/exllamav3/loader/step_mu.py
@@ -219,7 +219,7 @@ class MultiDecoder(SG.GraphDecoder):
self.hin[2, :T] = torch.tensor(bs)
gs.inp.copy_(self.hin, non_blocking=True)
self._stage_rows(rows)
- if DBG.enabled():
+ 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_rows
diff --git a/tests/test_hy4_mu_sched.py b/tests/test_hy4_mu_sched.py
index 513ec99..e1f6133 100644
--- a/tests/test_hy4_mu_sched.py
+++ b/tests/test_hy4_mu_sched.py
@@ -75,6 +75,32 @@ def test_queue_past_slots_reuse_and_max_new():
assert max(len(x[1]) for x in eng.log if x[0] == "dec") == 2 # never more rows than slots
+def test_slot_pin_allocates_slot_k_first(monkeypatch):
+ monkeypatch.setenv("HY4_MU_SLOT_PIN", "6")
+ eng = FakeEng(slots=8)
+ reqs = [ME.Request(list(range(6)), 3) for _ in range(3)]
+ run(reqs[:1], eng)
+ run(reqs[1:2], eng) # sequential single sessions: always slot 6
+ assert [x[1] for x in eng.log if x[0] == "open"] == [6, 6]
+ eng2 = FakeEng(slots=8)
+ sch = ME.MuScheduler(eng2, chunk=4) # two at once: the pinned slot first, then the FIFO order of the others
+ assert [sch._take_slot(), sch._take_slot(), sch._take_slot()] == [6, 0, 1]
+ assert 6 not in sch.free and sch.free == [2, 3, 4, 5, 7]
+
+
+def test_slot_pin_off_keeps_fifo_and_rejects_a_slot_past_slots(monkeypatch):
+ monkeypatch.delenv("HY4_MU_SLOT_PIN", raising=False)
+ sch = ME.MuScheduler(FakeEng(slots=4), chunk=4)
+ assert [sch._take_slot() for _ in range(4)] == [0, 1, 2, 3]
+ monkeypatch.setenv("HY4_MU_SLOT_PIN", "4")
+ try:
+ ME.MuScheduler(FakeEng(slots=4), chunk=4)
+ except ValueError as ex:
+ assert "HY4_MU_SLOT_PIN=4" in str(ex)
+ else:
+ raise AssertionError("a pin past --slots must be refused")
+
+
def test_prefill_chunk_is_interleaved_with_decode_rounds():
eng = FakeEng(slots=2)
a = ME.Request(list(range(4)), 40)
diff --git a/tests/test_hy4_mu_sync_debug.py b/tests/test_hy4_mu_sync_debug.py
index a6d4e1d..a8ec08e 100644
--- a/tests/test_hy4_mu_sync_debug.py
+++ b/tests/test_hy4_mu_sync_debug.py
@@ -110,3 +110,19 @@ def test_step_slots_probe_runs_once_per_slot_set_and_restores(capsys, monkeypatc
assert "mu-sync begin layer L1" in lines and "mu-sync begin L0 mla.attend L0" in lines and "mu-sync begin ffn L1" in lines
assert [l for l in lines if "replay segment" in l] and len([1 for e in log if e[0] == "layer"]) == 4
assert not any(k in d.fw.__dict__ for k in ("layer", "_ffn")) and "attend" not in d.fw.mlas[0].__dict__ and "indexer" not in d.gs.__dict__
+
+
+def test_sync_only_filters_stages_and_skips_the_probe(capsys, monkeypatch):
+ monkeypatch.setenv("HY4_MU_SYNC_DEBUG", "1")
+ monkeypatch.delenv("HY4_MU_SYNC_ONLY", raising=False)
+ assert D.probe_enabled()
+ monkeypatch.setenv("HY4_MU_SYNC_ONLY", "replay segment, draft chain")
+ assert not D.probe_enabled()
+ for name in ("step_slots T=1 replay segment 0/3", "spec_round draft chain slot 2 j 9", "prefill trunk step slot 1", "plain_round hcur clone slot 0 row 0"):
+ with D.stage(name):
+ pass
+ assert capsys.readouterr().out.splitlines() == ["mu-sync begin step_slots T=1 replay segment 0/3", "mu-sync begin spec_round draft chain slot 2 j 9"]
+ monkeypatch.setenv("HY4_MU_SYNC_ONLY", "probe")
+ assert D.probe_enabled()
+ monkeypatch.delenv("HY4_MU_SYNC_DEBUG")
+ assert not D.probe_enabled()
diff --git a/tools/hy4/mu_engine.py b/tools/hy4/mu_engine.py
index 4b09128..4f0fc87 100644
--- a/tools/hy4/mu_engine.py
+++ b/tools/hy4/mu_engine.py
@@ -238,12 +238,21 @@ class MuScheduler(threading.Thread):
self.cv = threading.Condition()
self.pending: deque = deque()
self.free = list(range(eng.slots))
+ self.pin = int(os.environ.get("HY4_MU_SLOT_PIN", "-1")) # HY4_MU_SLOT_PIN=k: slot k is allocated first whenever it is free (tests one slot index: a single session always lands on it)
+ if self.pin >= eng.slots:
+ raise ValueError(f"HY4_MU_SLOT_PIN={self.pin} is past --slots {eng.slots}")
self.pf: deque = deque()
self.dec: list = []
self.stop_flag = False
self.stats = {"rounds": 0, "round_rows": 0, "pf_chunks": 0, "pf_s": 0.0, "dec_s": 0.0}
self.trace: list = [] # (t0, t1, kind, n) per scheduler action
+ def _take_slot(self):
+ if self.pin in self.free:
+ self.free.remove(self.pin)
+ return self.pin
+ return self.free.pop(0)
+
def submit(self, req: Request):
with self.cv:
self.pending.append(req)
@@ -285,7 +294,7 @@ class MuScheduler(threading.Thread):
return
while self.pending and self.free:
req = self.pending.popleft()
- req.sess = eng.open(self.free.pop(0))
+ req.sess = eng.open(self._take_slot())
req.stats["admit"] = pc()
if req.cancel.is_set() or len(req.ids) + req.max_new + eng.k + 2 > eng.ctx:
req.error = None if req.cancel.is_set() else "context"