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.

startup_health: load hip_compiler by path so the Qwen server start is not blocked by an early exllamav3 import

YanissAmze71b1df3d491
diff --git a/tools/startup_health.py b/tools/startup_health.py
index aa2387d..7062361 100644
--- a/tools/startup_health.py
+++ b/tools/startup_health.py
@@ -21,9 +21,11 @@ tracker is active (tests, library use).
"""
from __future__ import annotations
+import importlib.util
import json
import os
import socket
+import sys
import threading
import time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -310,11 +312,26 @@ def start(name: str, stages: list[str], host: str, port: int, variant: str | Non
return ACTIVE
+def _hip_compiler():
+ """exllamav3/util/hip_compiler.py loaded by path, under its package name, WITHOUT importing the exllamav3 package: the Qwen
+ server applies its serving environment after this runs, and importing exllamav3 first would latch the engine defaults
+ (check_latched_env refuses to start). Later `from exllamav3.util import hip_compiler` finds the same module object."""
+ name = "exllamav3.util.hip_compiler"
+ mod = sys.modules.get(name)
+ if mod is None:
+ path = Path(__file__).resolve().parent.parent / "exllamav3" / "util" / "hip_compiler.py"
+ spec = importlib.util.spec_from_file_location(name, path)
+ mod = importlib.util.module_from_spec(spec)
+ sys.modules[name] = mod
+ spec.loader.exec_module(mod)
+ return mod
+
+
def compiler_health() -> dict:
"""Fields for /health: the HIP kernel compiler line, plus the warning line when it is not the rocm-sdk compiler.
- Lazy import: nothing here needs torch at import time."""
+ Loaded by path: no torch and no exllamav3 package import."""
try:
- from exllamav3.util import hip_compiler
+ hip_compiler = _hip_compiler()
out = {"hip_compiler": hip_compiler.describe().removeprefix("HIP kernel compiler: ")}
if hip_compiler.warning():
out["hip_compiler_warning"] = hip_compiler.warning()
@@ -326,7 +343,7 @@ def compiler_health() -> dict:
def report_compiler() -> None:
"""Start-up log: which compiler builds the JIT kernels, plus one warning line when it is not the rocm-sdk one."""
try:
- from exllamav3.util import hip_compiler
+ hip_compiler = _hip_compiler()
hip_compiler.report(lambda line: print(line, flush=True))
except Exception as e: # noqa: BLE001
print(f"[kyojin] HIP kernel compiler: unknown ({type(e).__name__}: {e})", flush=True)
diff --git a/tools/test_startup_health.py b/tools/test_startup_health.py
index c77aebb..8f84130 100644
--- a/tools/test_startup_health.py
+++ b/tools/test_startup_health.py
@@ -644,6 +644,17 @@ class WiringTest(unittest.TestCase):
def test_glm_keeps_tuned_and_untuned_history_apart(self):
self.assertIn('variant="tuned" if tune and dense_tune_path().exists() else "untuned"', (TOOLS / "glm" / "serve.py").read_text())
+ def test_compiler_report_does_not_import_the_engine_package(self):
+ # The Qwen server sets its serving environment after startup_health.report_compiler(): importing exllamav3 there
+ # latches the engine defaults and check_latched_env() refuses to start (found on the first GPU start of the merge).
+ import subprocess
+ code = ("import sys; sys.path.insert(0, %r); import startup_health as s; s.report_compiler(); h = s.compiler_health(); "
+ "assert 'hip_compiler' in h, h; assert 'exllamav3' not in sys.modules and 'torch' not in sys.modules, sorted(m for m in sys.modules if m.startswith(('exllamav3', 'torch'))); "
+ "assert s._hip_compiler() is sys.modules['exllamav3.util.hip_compiler']") % str(TOOLS)
+ r = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True)
+ self.assertEqual(r.returncode, 0, r.stderr[-800:])
+ self.assertIn("HIP kernel compiler", r.stdout)
+
def test_default_ready_line_unchanged(self):
self.assertIn("qserve: READY on http://", (TOOLS / "qwen" / "serve.py").read_text())