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: static indexer init on a bound slab view sets vg_ring = 0 (a prompt with an open indexer group crashed start_graph_state with AttributeError), CPU test

YanissAmz7952a82b609b
diff --git a/exllamav3/loader/step_graph.py b/exllamav3/loader/step_graph.py
index bc07495..146b0d8 100644
--- a/exllamav3/loader/step_graph.py
+++ b/exllamav3/loader/step_graph.py
@@ -65,6 +65,8 @@ def indexer_static_init(ix, cap):
if vgb is None:
ix.vg_ring = VG_RING if (VG_RING and VG_RING < cap) else 0 # HY4_SWA_RING: only the open group (+ the rows of one batch call) is ever read: slot = position % VG_RING
vgb = ix.vgb = torch.zeros(ix.vg_ring or cap, 2 * d, device=ix.dev)
+ elif not hasattr(ix, "vg_ring"):
+ ix.vg_ring = 0 # a buffer bound from outside (multi-session slab view [cap, 2d]) is full length: positions index it directly, never a ring
if ix.vg is not None: # open group of an eager prefill (< k rows)
m = ix.vg.shape[0]
vgb[(torch.arange(ix.n - m, ix.n, device=ix.dev) % ix.vg_ring) if ix.vg_ring else slice(ix.n - m, ix.n)] = ix.vg
diff --git a/tests/test_hy4_mu_static_init.py b/tests/test_hy4_mu_static_init.py
new file mode 100644
index 0000000..00b682c
--- /dev/null
+++ b/tests/test_hy4_mu_static_init.py
@@ -0,0 +1,58 @@
+"""CPU check of the static indexer init on a slab view (multi-session start_graph_state): the session binds its slab view as ix.vgb BEFORE the init, so the init must not
+assume it created the buffer. 20/11 served crash: a prompt that left an open indexer group (length % k != 0) died with AttributeError "vg_ring" at the second request."""
+import os
+import sys
+import types
+from types import SimpleNamespace
+
+import torch
+
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+for _n, _s in (("exllamav3", ""), ("exllamav3.loader", "loader")): # the loader package without exllamav3/__init__ (no C++ extension build on a CPU box)
+ _m = sys.modules.get(_n) or types.ModuleType(_n)
+ _m.__path__ = [os.path.join(ROOT, "exllamav3", _s)]
+ sys.modules[_n] = _m
+
+from exllamav3.loader import mu_slots as MS # noqa: E402
+from exllamav3.loader import step_graph as SG # noqa: E402
+
+
+def fake_ix(k=4, d=8):
+ return SimpleNamespace(k=k, d=d, dev=torch.device("cpu"), pool=None, vgb=None, vg=None, n=0, P=0, _table=lambda n: None)
+
+
+def test_static_init_on_a_slab_view_with_an_open_group():
+ k, d, cap, S = 4, 8, 64, 3
+ ix = fake_ix(k, d)
+ sl = MS.IxSlabs(ix, S, cap)
+ for slot in range(S):
+ for n in (60, 61, 63): # 60 % k == 0: no open group (the only case that worked); 61 / 63: open group of 1 / 3 rows
+ ix.pool, ix.vgb = sl.view(slot)
+ sl.vgb.zero_()
+ m = n % k
+ vg = torch.randn(m, 2 * d) if m else None
+ ix.n, ix.P, ix.vg = n, n // k, vg
+ if hasattr(ix, "vg_ring"):
+ del ix.vg_ring # the next session binds a fresh view on the same eager object
+ SG.indexer_static_init(ix, cap)
+ assert ix.vg_ring == 0 and ix.vgb.shape[0] == cap
+ if vg is not None:
+ assert torch.equal(ix.vgb[n - m:n], vg)
+ assert torch.count_nonzero(sl.vgb) == torch.count_nonzero(vg) # nothing outside this session's rows
+ assert torch.count_nonzero(sl.vgb[slot * cap:(slot + 1) * cap]) == torch.count_nonzero(vg)
+
+
+def test_static_init_solo_still_creates_the_buffer():
+ ix = fake_ix()
+ ix.pool = torch.zeros(4, 8)
+ ix.n, ix.P, ix.vg = 2, 0, torch.randn(2, 16)
+ SG.indexer_static_init(ix, 64)
+ assert ix.vg_ring == (SG.VG_RING if (SG.VG_RING and SG.VG_RING < 64) else 0)
+ assert ix.pool.shape[0] == 16 and ix.vgb.shape[0] == (ix.vg_ring or 64)
+ assert torch.equal(ix.vgb[torch.arange(0, 2) % ix.vg_ring] if ix.vg_ring else ix.vgb[0:2], ix.vg)
+
+
+if __name__ == "__main__":
+ test_static_init_on_a_slab_view_with_an_open_group()
+ test_static_init_solo_still_creates_the_buffer()
+ print("ok")