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.

Chunked-prefill interleave on by default (EXL3_SCHED_CHUNK_IL=0 turns it off); add prefill roof bench

YanissAmz69c6350c2019
diff --git a/exllamav3/generator/chunk_il.py b/exllamav3/generator/chunk_il.py
index 9059c08..85510cc 100644
--- a/exllamav3/generator/chunk_il.py
+++ b/exllamav3/generator/chunk_il.py
@@ -1,4 +1,4 @@
-"""EXL3_SCHED_CHUNK_IL=1 (default off): chunked-prefill interleave planner. Pure python (no torch), importable without a GPU.
+"""Chunked-prefill interleave, default ON since 1.8.8 (EXL3_SCHED_CHUNK_IL=0 turns it off): chunked-prefill interleave planner. Pure python (no torch), importable without a GPU.
The engine already prefills in chunks (EXL3_PREFILL_CHUNK, 4096 rows; Job.prefill runs ONE chunk per Generator.iterate()
step and keeps kv_position / pages / recurrent slot between steps). This planner only decides, per step, WHICH jobs may run
@@ -35,7 +35,7 @@ from typing import Any, NamedTuple
def chunk_il_enabled() -> bool:
- return os.environ.get("EXL3_SCHED_CHUNK_IL", "0") == "1"
+ return os.environ.get("EXL3_SCHED_CHUNK_IL", "1") != "0"
class View(NamedTuple):
diff --git a/tests/bench_prefill_roof.py b/tests/bench_prefill_roof.py
new file mode 100644
index 0000000..56ce786
--- /dev/null
+++ b/tests/bench_prefill_roof.py
@@ -0,0 +1,68 @@
+"""Prefill throughput vs the GEMM roof. Prints, per prompt length: tok/s, the GEMM TFLOPs that rate implies (2 x active params
+per token; attention FLOPs not counted, so the gap at 32K includes them) and its share of the device's measured fp16 matmul peak.
+
+ MODEL_DIR=<exl3 dir> | FMOE_GGUF=<file.gguf> [PREFILL_LENS=8192,32768] python tests/bench_prefill_roof.py
+"""
+import os, sys, time
+import torch
+
+ENGINE = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
+sys.path.insert(0, ENGINE)
+from exllamav3 import Model, Config, Cache, Generator, Job, GreedySampler, Tokenizer
+from exllamav3.loader.gguf_config import write_config_dir
+from exllamav3.modules import BlockSparseMLP
+
+lens = [int(v) for v in os.environ.get("PREFILL_LENS", "8192,32768").split(",")]
+if os.environ.get("MODEL_DIR"):
+ d = os.environ["MODEL_DIR"]
+else:
+ d = write_config_dir(os.environ["FMOE_GGUF"], os.path.join(os.environ.get("FMOE_CFG", "/tmp"), "qwen35moe_cfg"))
+config = Config.from_directory(d)
+model = Model.from_config(config)
+cache = Cache(model, max_num_tokens=(max(lens) + 1024) // 256 * 256 + 256)
+model.load()
+tok = Tokenizer.from_config(config)
+gen = Generator(model=model, cache=cache, tokenizer=tok)
+
+
+def active_params(mod, scale=1.0):
+ n = 0.0
+ if isinstance(mod, BlockSparseMLP):
+ k = mod.num_experts_per_tok / mod.num_experts
+ keep = {id(getattr(mod, a, None)) for a in ("shared_experts", "shared_gate", "routing_gate", "latent_in", "latent_out")}
+ for c in mod.modules:
+ n += active_params(c, scale if id(c) in keep else scale * k)
+ return n
+ if hasattr(mod, "in_features") and hasattr(mod, "out_features") and not mod.modules:
+ return scale * mod.in_features * mod.out_features
+ for c in mod.modules:
+ n += active_params(c, scale)
+ return n
+
+
+dev = torch.device("cuda")
+a = torch.randn(8192, 8192, device=dev, dtype=torch.half)
+b = torch.randn(8192, 8192, device=dev, dtype=torch.half)
+for _ in range(3): a @ b
+torch.cuda.synchronize(); t = time.time()
+for _ in range(20): a @ b
+torch.cuda.synchronize()
+peak = 20 * 2 * 8192 ** 3 / (time.time() - t) / 1e12
+del a, b
+act = sum(active_params(m) for m in model.modules)
+print(f"device fp16 matmul peak {peak:.1f} TFLOPs; active params/token {act / 1e9:.2f} B -> GEMM roof {peak * 1e12 / (2 * act):.0f} tok/s")
+
+g = torch.Generator().manual_seed(1)
+vocab = min(config.vocab_size, 100000)
+for L in [1024] + lens:
+ for rep in range(2 if L == 1024 else 1):
+ ids = torch.randint(1000, vocab, (1, L), generator=g) # random ids: no prefix-cache hit
+ job = Job(input_ids=ids, max_new_tokens=1, sampler=GreedySampler(), stop_conditions=[])
+ gen.enqueue(job)
+ torch.cuda.synchronize(); t = time.time()
+ while gen.num_remaining_jobs():
+ gen.iterate()
+ torch.cuda.synchronize(); dt = time.time() - t
+ if L != 1024:
+ r = L / dt
+ print(f"prefill L={L}: {dt:.2f}s = {r:.0f} tok/s, {2 * act * r / 1e12:.1f} TFLOPs-equiv = {100 * 2 * act * r / 1e12 / peak:.0f} % of matmul peak")
diff --git a/tests/test_gguf_ttft_interleave.py b/tests/test_gguf_ttft_interleave.py
index 1bf453f..069486b 100644
--- a/tests/test_gguf_ttft_interleave.py
+++ b/tests/test_gguf_ttft_interleave.py
@@ -1,5 +1,5 @@
"""Multi-user TTFT with a big prefill in flight: a short request arrives while a long prompt prefills. Reports the short job's
-time to first token and the long job's total time. Run once per EXL3_SCHED_CHUNK_IL value (0/1, optionally EXL3_CIL_DECODE_PRIO=1).
+time to first token and the long job's total time. Run once per EXL3_SCHED_CHUNK_IL value (0 = off, default on, optionally EXL3_CIL_DECODE_PRIO=1).
FMOE_GGUF=<file.gguf> [FMOE_LONG=24000] EXL3_SCHED_CHUNK_IL=1 python tests/test_gguf_ttft_interleave.py
"""
@@ -56,4 +56,4 @@ def run(seed):
run(1)
a, b, h = run(2)
-print(f"CHUNK_IL={os.environ.get('EXL3_SCHED_CHUNK_IL', '0')} DPRIO={os.environ.get('EXL3_CIL_DECODE_PRIO', '0')} long={L}: short TTFT {a:.2f}s, long total {b:.2f}s, tokens {h}")
+print(f"CHUNK_IL={os.environ.get('EXL3_SCHED_CHUNK_IL', '1')} DPRIO={os.environ.get('EXL3_CIL_DECODE_PRIO', '0')} long={L}: short TTFT {a:.2f}s, long total {b:.2f}s, tokens {h}")