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.

Prefix disk: replacing a tail checkpoint already in memory compares by identity, not through list.remove()

YanissAmz8885f809f08a
diff --git a/exllamav3/generator/slot_store.py b/exllamav3/generator/slot_store.py
index 647925d..6525064 100644
--- a/exllamav3/generator/slot_store.py
+++ b/exllamav3/generator/slot_store.py
@@ -242,9 +242,10 @@ class SlotStore:
pt = g.pagetable
ids = tail["ids"]
L = ids.shape[-1]
- for e in list(g.tail_ckpts): # same content already in memory: the restored copy replaces it
- if e["prev_hash"] == ph and e["ids"].shape == ids.shape and torch.equal(e["ids"].cpu(), ids):
- g.tail_ckpts.remove(e)
+ # same content already in memory: the restored copy replaces it. By identity: list.remove() compares the entries as
+ # dicts, and two entries with the same prev_hash but ids of other lengths raise "The size of tensor a must match"
+ g.tail_ckpts[:] = [e for e in g.tail_ckpts
+ if not (e["prev_hash"] == ph and e["ids"].shape == ids.shape and torch.equal(e["ids"].cpu(), ids))]
if order is None:
order = pt.build_eviction_order(protected)
while order[0].ref_count:
diff --git a/tests/test_tail_restore_dedupe_.py b/tests/test_tail_restore_dedupe_.py
new file mode 100644
index 0000000..839a548
--- /dev/null
+++ b/tests/test_tail_restore_dedupe_.py
@@ -0,0 +1,28 @@
+"""
+SlotStore._restore_tail drops a tail entry that is already in memory. With list.remove() two entries of the same prev_hash and ids of
+other lengths made the comparison of the dicts raise (RuntimeError: The size of tensor a (122) must match the size of tensor b (215)),
+which ended the whole prefix disk restore of that request. The method is loaded by ast; its first statements run on fakes.
+"""
+import ast, os, sys, textwrap, types
+import torch
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+src = open(os.path.join(ROOT, "exllamav3", "generator", "slot_store.py")).read()
+fn = None
+for n in ast.walk(ast.parse(src)):
+ if isinstance(n, ast.FunctionDef) and n.name == "_restore_tail":
+ fn = n
+body = ast.get_source_segment(src, fn)
+# keep the dedupe statement only: cut at the eviction order
+head = body[:body.index(" if order is None:")]
+ns = {"torch": torch}
+exec(textwrap.dedent(head + " return g.tail_ckpts\n"), ns)
+f = ns["_restore_tail"]
+
+def entry(ph, n):
+ return {"prev_hash": ph, "ids": torch.arange(n).view(1, -1), "page": None}
+
+g = types.SimpleNamespace(tail_ckpts=[entry(b"p", 122), entry(b"q", 7), entry(b"p", 215)], pagetable=None)
+self = types.SimpleNamespace(generator=g)
+out = f(self, {"ids": torch.arange(215).view(1, -1)}, b"p", None, None, None, None)
+assert [(e["prev_hash"], e["ids"].shape[-1]) for e in out] == [(b"p", 122), (b"q", 7)], out # only the identical entry is replaced
+print("tail dedupe ok")
diff --git a/tools/qwen/serve.py b/tools/qwen/serve.py
index 0221794..0e6da1a 100644
--- a/tools/qwen/serve.py
+++ b/tools/qwen/serve.py
@@ -928,7 +928,10 @@ class QwenEngine:
try:
r = self.prefix_disk.restore(ids)
except Exception as exc: # noqa: BLE001 the disk never fails a request
- print(f"qserve: prefix disk restore failed: {type(exc).__name__}: {exc}", file=sys.stderr, flush=True)
+ import traceback
+ where = traceback.extract_tb(exc.__traceback__)[-1]
+ print(f"qserve: prefix disk restore failed: {type(exc).__name__}: {exc} ({where.filename.split('/')[-1]}:{where.lineno} {where.line})",
+ file=sys.stderr, flush=True)
return
if r:
print(f"qserve: prefix disk restore resume_at={r['resume_at']} (ram {r['ram_at']}) pages={r['pages']} {r['ms']:.0f} ms",