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
Prefix disk restore: an in-memory prompt-end checkpoint whose partial page was reused does not count as a resume point
YanissAmz0511b28aed6f
diff --git a/exllamav3/generator/prefix_disk.py b/exllamav3/generator/prefix_disk.pyindex e992380..791168e 100644--- a/exllamav3/generator/prefix_disk.py+++ b/exllamav3/generator/prefix_disk.py@@ -53,6 +53,16 @@ def _hx(h) -> str:PIN_PAGES = 32 # every checkpoint of the first 8K tokens is kept: the system prompt + tools of any session resumes near its end+def tail_page_usable(e: dict, ph, L: int) -> bool:+ """Whether the partial page of an in-memory prompt-end checkpoint still holds its K/V: it is an unreferenced page, another job+ may have taken it. The job refuses such an entry (Job._tail_restore); counting it as resumable here kept the deeper copy on+ the disk from being restored (a follow-up turn re-prefilled 2-4K tokens while the disk held its prompt end)."""+ src = e.get("page")+ if src is None:+ return True+ return src.prev_hash == ph and src.kv_position >= L and torch.equal(src.sequence[:, :L], e["ids"].view(1, -1).to(src.sequence.device))++def _pow2(d: int) -> bool:return d >= 8 and d & (d - 1) == 0 # 8 pages = 2048 tokens@@ -254,7 +264,7 @@ class PagedPrefixDisk:if k < 0 or k > ram_res:continue # tail without its resident page chain is unreachable: prefill matches pages from page 0L = e["ids"].shape[-1]- if torch.equal(e["ids"].cpu().view(1, -1), ids[:, k * PAGE_SIZE:k * PAGE_SIZE + L]):+ if torch.equal(e["ids"].cpu().view(1, -1), ids[:, k * PAGE_SIZE:k * PAGE_SIZE + L]) and tail_page_usable(e, ph, L):ram_pos = max(ram_pos, k * PAGE_SIZE + L)# what the disk has: pages are needed from 0, so the usable chain stops at the first page it lacksavail = 0diff --git a/tests/test_tail_page_usable_.py b/tests/test_tail_page_usable_.pynew file mode 100644index 0000000..76c416f--- /dev/null+++ b/tests/test_tail_page_usable_.py@@ -0,0 +1,21 @@+"""+prefix_disk.tail_page_usable: an in-memory prompt-end checkpoint whose partial page was reused by another job is not resumable,+so the restore must take the deeper copy from the disk. Pure torch on CPU.+"""+import os, sys, types+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+import torch+from exllamav3.generator.prefix_disk import tail_page_usable++ids = torch.arange(100).view(1, -1)+def page(prev, n, seq):+ s = torch.zeros(1, 256, dtype=torch.long); s[:, :len(seq)] = torch.tensor(seq)+ return types.SimpleNamespace(prev_hash=prev, kv_position=n, sequence=s)++e = {"prev_hash": b"p", "ids": ids, "page": page(b"p", 100, list(range(100)))}+assert tail_page_usable(e, b"p", 100)+assert not tail_page_usable(dict(e, page=page(b"q", 100, list(range(100)))), b"p", 100) # taken by a chain of another prompt+assert not tail_page_usable(dict(e, page=page(b"p", 0, [])), b"p", 100) # evicted and cleared+assert not tail_page_usable(dict(e, page=page(b"p", 100, list(range(99)) + [7])), b"p", 100) # reused for other tokens+assert tail_page_usable({"prev_hash": b"p", "ids": ids, "page": None}, b"p", 100) # no page recorded: unchanged behaviour+print("tail page usable ok")