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
qserve: dump every thread stack when a start-up phase stalls (#133)
Yaniss Amazouz03654935b84e
diff --git a/exllamav3/util/jit_log.py b/exllamav3/util/jit_log.pyindex 91b410e..8efecd4 100644--- a/exllamav3/util/jit_log.py+++ b/exllamav3/util/jit_log.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport os, sys, time_t0: dict = {}+_on = Falsedef install(log=None) -> bool:@@ -14,16 +15,18 @@ def install(log=None) -> bool:from triton import knobsexcept Exception: # noqa: BLE001 older triton: no hooksreturn False+ global _on+ _on = Trueout = log or (lambda s: print(s, file=sys.stderr, flush=True))started = time.perf_counter()def pre(*, key, repr, fn, compile, is_manual_warmup, already_compiled):if not already_compiled:- _t0[key] = time.perf_counter()+ _t0[key] = (time.perf_counter(), str(repr).split("[", 1)[0])return Falsedef post(*, key, repr, fn, compile, is_manual_warmup, already_compiled):- t = _t0.pop(key, None)+ t = _t0.pop(key, (None,))[0]if t is None or already_compiled:returnnow = time.perf_counter()@@ -38,3 +41,11 @@ def install(log=None) -> bool:knobs.runtime.jit_cache_hook = preknobs.runtime.jit_post_compile_hook = postreturn True+++def pending():+ """[(kernel name, seconds)] of the compiles started and not finished yet; None when the log is off (no hooks)."""+ if not _on:+ return None+ now = time.perf_counter()+ return [(name, now - t) for t, name in list(_t0.values())]diff --git a/tools/qwen/serve.py b/tools/qwen/serve.pyindex b931449..5f787d8 100644--- a/tools/qwen/serve.py+++ b/tools/qwen/serve.py@@ -444,10 +444,13 @@ def load_defaults(model_dir: str, args: argparse.Namespace | None = None) -> dicclass Heartbeat:- """Prints one progress line every `every` seconds while a long start-up phase runs."""+ """Prints one progress line every `every` seconds while a long start-up phase runs. A phase still running after+ EXL3_STALL_DUMP_S seconds (default 600, 0 = off) also prints the Python stack of every thread, again at 2x, 4x ... that+ time, so a stall shows where it waits (GPU sync, Triton compile, disk read) and whether it moves."""- def __init__(self, label: str, every: float = 15.0):+ def __init__(self, label: str, every: float = 15.0, dump_s: float | None = None):self.label, self.every, self.stop = label, every, threading.Event()+ self.dump_s = float(os.environ.get("EXL3_STALL_DUMP_S", "600")) if dump_s is None else dump_sdef __enter__(self):self.t0 = time.time()@@ -456,8 +459,30 @@ class Heartbeat:return selfdef _run(self):+ next_dump = self.dump_swhile not self.stop.wait(self.every):- print(f"qserve: {self.label} ... {time.time() - self.t0:.0f} s", flush=True)+ dt = time.time() - self.t0+ print(f"qserve: {self.label} ... {dt:.0f} s", flush=True)+ if 0 < next_dump <= dt:+ next_dump *= 2+ self.dump(dt)++ def dump(self, dt: float):+ import faulthandler+ try:+ from exllamav3.util import jit_log+ jit = jit_log.pending()+ except ImportError:+ jit = None+ busy = "not logged (EXL3_LOG_JIT=1 logs them)" if jit is None else ", ".join(f"{n} {a:.0f} s" for n, a in jit) or "none"+ print(f"qserve: {self.label} still running after {dt:.0f} s, stack of every thread below (EXL3_STALL_DUMP_S=0 = off); "+ f"Triton compiles in flight: {busy}", flush=True)+ try:+ faulthandler.dump_traceback(file=sys.stdout, all_threads=True)+ except (ValueError, OSError, io.UnsupportedOperation): # stdout without a file descriptor (captured)+ import traceback+ for tid, frame in sys._current_frames().items():+ print(f"Thread {tid:#x}:\n" + "".join(traceback.format_stack(frame)), flush=True)def __exit__(self, *exc):self.stop.set()diff --git a/tools/qwen/test_serve.py b/tools/qwen/test_serve.pyindex 21178a2..843d3dd 100644--- a/tools/qwen/test_serve.py+++ b/tools/qwen/test_serve.py@@ -1494,5 +1494,27 @@ class DraftDepthTests(unittest.TestCase):self.assertEqual(c.depth, 0)+class HeartbeatStallDumpTests(unittest.TestCase):+ def _run(self, dump_s, wait):+ import time+ out = io.StringIO() # no file descriptor: the dump takes its traceback fallback+ with unittest.mock.patch.object(sys, "stdout", out):+ with serve.Heartbeat("phase", every=0.05, dump_s=dump_s):+ time.sleep(wait)+ time.sleep(0.1) # the heartbeat thread sees the stop+ return out.getvalue()++ def test_a_long_phase_prints_every_thread_stack_once_per_doubling(self):+ out = self._run(0.1, 1.0)+ self.assertIn(out.count("still running after"), (3, 4)) # 0.1, 0.2, 0.4, 0.8 s: not one per 0.05 s tick+ self.assertIn("test_serve.py", out) # the stack of the waiting main thread+ self.assertIn("Triton compiles in flight", out)++ def test_zero_turns_the_dump_off(self):+ out = self._run(0, 0.2)+ self.assertNotIn("still running after", out)+ self.assertIn("phase done in", out)++if __name__ == "__main__":unittest.main()