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.

Add TTFT test for chunked-prefill interleave with a short request behind a long prefill

YanissAmzc6444e9aa8c7
diff --git a/tests/test_gguf_ttft_interleave.py b/tests/test_gguf_ttft_interleave.py
new file mode 100644
index 0000000..7d2cd19
--- /dev/null
+++ b/tests/test_gguf_ttft_interleave.py
@@ -0,0 +1,52 @@
+"""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).
+
+ FMOE_GGUF=<file.gguf> [FMOE_LONG=24000] EXL3_SCHED_CHUNK_IL=1 python tests/test_gguf_ttft_interleave.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
+
+L = int(os.environ.get("FMOE_LONG", "24000"))
+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=(L + 4096) // 256 * 256 + 256)
+model.load()
+tok = Tokenizer.from_config(config)
+gen = Generator(model=model, cache=cache, tokenizer=tok)
+short_ids = tok.encode("What is two plus two?")
+
+
+def run(seed):
+ # a fresh prompt per run: an identical one would hit the prefix cache and prefill nothing
+ long_ids = tok.encode(f"Story {seed}. " + "The history of the Roman empire is long. " * (L // 8))[:, :L]
+ t0 = time.time()
+ ja = Job(input_ids=long_ids, max_new_tokens=8, sampler=GreedySampler(), stop_conditions=[], identifier="long")
+ jb = Job(input_ids=short_ids, max_new_tokens=16, sampler=GreedySampler(), stop_conditions=[], identifier="short")
+ first = {}
+ done = {}
+ sent = False
+ gen.enqueue(ja)
+ gen.iterate() # first chunk of the long prefill is in flight, then the short request arrives
+ while gen.num_remaining_jobs():
+ if not sent and time.time() - t0 > 0.0:
+ gen.enqueue(jb); sent = True; tb = time.time()
+ results = gen.iterate()
+ for r in results:
+ i = r["identifier"]
+ if r["stage"] == "streaming" and "token_ids" in r and i not in first:
+ first[i] = time.time()
+ if r.get("eos"):
+ done[i] = time.time()
+ torch.cuda.synchronize()
+ return first["short"] - tb, done["long"] - t0
+
+
+run(1)
+a, b = 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")