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.

Prefill: a page-aligned resume off the chunk grid measures its tail gap from the resume point (EXL3_TAIL_OFFGRID), on by default for GLM

YanissAmzcfe0c15bd2ca
diff --git a/exllamav3/generator/job.py b/exllamav3/generator/job.py
index 8bc2eab..0462b0c 100644
--- a/exllamav3/generator/job.py
+++ b/exllamav3/generator/job.py
@@ -1397,7 +1397,11 @@ class Job:
# last chunks have the same shapes cold and resumed (a 6144 resume of a 7000-token prompt ran one 855-row
# chunk instead of cold's 768 + 87 and the recurrent state differed). Only a mid-page resume (tail
# checkpoint, never comparable to a cold prefill) keeps the distance to its checkpoint.
- gap_base = self.cached_pages * PAGE_SIZE if self._unaligned_start else 0
+ # EXL3_TAIL_OFFGRID=1 (default off): a page-aligned resume off the chunk grid (a branch or last-page checkpoint)
+ # never matches a cold prefill's chunks either, so it also measures the gap from the resume point
+ resume_pos = self.cached_pages * PAGE_SIZE
+ off_grid = os.environ.get("EXL3_TAIL_OFFGRID", "0") == "1" and resume_pos % self.generator.max_chunk_size != 0
+ gap_base = resume_pos if self._unaligned_start or off_grid else 0
# EXL3_PF_NO_TAIL=1 (default 0, big-tail mode only): no separate pass for the prompt's last page
# (a 4K prompt ran 3840 + 255, the 255-row tail cost ~1 s); the chunk runs whole and the KDA
# kernel side-writes the last-page state as a second mid-chunk checkpoint (stash_midchunk)
diff --git a/tools/glm/serve.py b/tools/glm/serve.py
index 9cfd634..7a4e89c 100644
--- a/tools/glm/serve.py
+++ b/tools/glm/serve.py
@@ -98,6 +98,9 @@ SPEED_ENV = {
# side-writes the state where those pages end, so the next one resumes there: first token after a shared 9K / 12.1K prefix
# 2.41 -> 1.94 s, 3.84 -> 2.06 s; the writing prompt is bitwise unchanged, KLD vs a cold prefill at the resumed-turn level.
"EXL3_BRANCH_CKPT": "1",
+ # such a resume (page-aligned, off the 2048 chunk grid) with a short remainder keeps the tail in its one chunk (prompt-end tail
+ # checkpoint) instead of a separate last-page forward: 2.00 -> 1.42 s, 2.44 -> 1.51 s; KLD vs a cold prefill unchanged in class.
+ "EXL3_TAIL_OFFGRID": "1",
"EXL3_HOST_LEAN": "1",
"EXL3_HOST_CUTS": "1",
"EXL3_PF_GLUE": "1",