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.

Chunk interleave decode priority: a short prefill beside a decoding job takes the short chunks too

YanissAmz7e0a6da7a217
diff --git a/exllamav3/generator/chunk_il.py b/exllamav3/generator/chunk_il.py
index 7b9846e..f19a6fe 100644
--- a/exllamav3/generator/chunk_il.py
+++ b/exllamav3/generator/chunk_il.py
@@ -12,7 +12,7 @@ alternates with the queued short work of other jobs:
Decode priority (EXL3_CIL_DECODE_PRIO=1, for GPUs that decode several users in one batch): while another job is decode-ready the
deferral budget does not apply and a leader chunk is not exclusive. The leader takes EXL3_CIL_DPRIO_CHUNK rows (default 768, about
0.75 s on a 3090) per step and shares the step with the decode round of every ready job; between two leader chunks the ready jobs
-decode, all of them in one batch, for up to EXL3_CIL_SLICE_S. A running stream waits one chunk, not the whole big prefill; the
+decode, all of them in one batch, for up to EXL3_CIL_SLICE_S (a short prefill beside a decoding job takes the same short chunks). A running stream waits one chunk, not the whole big prefill; the
leader keeps about two thirds of the GPU time. Without a decode-ready job the leader runs at full chunk size as before.
Hard bound: the leader's deferral (wall time of steps in which it did not run) is capped per leader by
@@ -135,7 +135,8 @@ class ChunkPlanner:
if ld is None:
bigs = sorted((v for v in live if v.remaining > self.short_tok), key=lambda v: v.order)
if not bigs:
- return Plan(set(), None, None)
+ # decode priority also for the short prefills (a 2-3K-row tool result): they take the short chunk while someone decodes
+ return Plan(set(), None, None, self.dprio_chunk if self.dprio and live and any(v.done for v in views) else 0)
lv = bigs[0]
ld = self._lead = _Leader(lv.key, lv.kv, now)
ld.rows = lv.remaining
diff --git a/tools/qwen/test_chunk_il.py b/tools/qwen/test_chunk_il.py
index 5e186d4..f3cb534 100644
--- a/tools/qwen/test_chunk_il.py
+++ b/tools/qwen/test_chunk_il.py
@@ -191,6 +191,28 @@ class DecodePriorityTests(unittest.TestCase):
self.assertLess(t1_, 1.7 * solo) # the big prefill keeps about 60 % of the GPU
self.assertGreater(rate1, 10) # rounds per second of a stream during the big prefill (full speed 29: about 40 %)
+ def test_short_prefill_beside_a_stream_takes_short_chunks(self):
+ def gap(prio):
+ if prio:
+ os.environ["EXL3_CIL_DECODE_PRIO"] = "1"
+ try:
+ s = Sim(True)
+ s.add("u1", 900, out=2000)
+ arrived = []
+
+ def refill(sim):
+ if not arrived and sim.clk.t >= 3.0:
+ arrived.append(sim.add("u2", 3500, out=30)) # a tool result of 3.5K rows: a short prefill (below the 4096 big threshold)
+ if arrived and arrived[0].time_first_token is not None:
+ sim.g.active_jobs.clear()
+ s.run(60, refill=refill)
+ ends = [t1 for (t0, t1, pre, dec) in s.log if "u1" in dec and 2.5 <= t0 <= arrived[0].t_prefill_done]
+ return max(b - a for a, b in zip(ends, ends[1:]))
+ finally:
+ os.environ.pop("EXL3_CIL_DECODE_PRIO", None)
+ self.assertGreater(gap(False), 2.0) # one 3.5K-row chunk (4096 cap) stops the stream
+ self.assertLess(gap(True), 1.1) # 768-row chunks with a decode round between them (the last chunk merges the tail: <= 1792 rows)
+
def test_chunk_size_restored_when_nobody_decodes(self):
os.environ["EXL3_CIL_DECODE_PRIO"] = "1"
try: