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
Merge feature/hy4-strix-mufix-fast-r192 into 1.9.3 tree
YanissAmz95774780f645
diff --cc tools/hy4/mu_engine.pyindex b82d981,fcb3c81..fdf0d34--- a/tools/hy4/mu_engine.py+++ b/tools/hy4/mu_engine.py@@@ -14,9 -15,50 +15,50 @@@ from collections import dequfrom engine import Hy4Engine, PRIME_ROWS, warmup_clamp+ # HY4_MU_HOSTFAST=1 (default OFF): the batched host path of a decode round (see MuEngine._hcur_set, plain_round, spec_round, step_mu.step_slots).+ # HY4_MU_HOSTPROF=1: perf_counter splits per round, one `MUFAST` line per 100 rounds in the server log (also the FIRES-CHECK path counters).+ FIRES = {"plain": 0, "spec": 0, "hcur_idx": 0, "bind_skip": 0, "draft_cat": 0}+ HT = {"rounds": 0, "rows": 0, "draft": 0.0, "wait": 0.0, "post": 0.0, "emit": 0.0, "round": 0.0}+++ def _fast() -> bool:+ return os.environ.get("HY4_MU_HOSTFAST", "0") not in ("", "0")+++ def _prof() -> bool:+ return os.environ.get("HY4_MU_HOSTPROF", "0") not in ("", "0")+++ def fires_line(eng, last: dict | None = None) -> str:+ """one log line: path counters (cumulative) + mean ms per decode round since the previous line (`last` = the previous snapshot, updated in place)"""+ sm = getattr(eng, "SM", None)+ fs = dict(FIRES)+ ht = dict(HT)+ if sm is not None:+ fs.update(sm.FIRES)+ ht.update({k: sm.HT[k] for k in ("stage", "launch", "inputs", "gpu", "bubble")})+ last = {} if last is None else last+ nr = max(1, ht["rounds"] - last.get("rounds", 0))+ ms = {k: 1000.0 * (ht.get(k, 0.0) - last.get(k, 0.0)) / nr for k in ("round", "inputs", "stage", "launch", "draft", "wait", "post", "emit", "gpu", "bubble")}+ ms["host"] = ms["round"] - ms["gpu"] # round time the GPU did not spend replaying (0 gpu = HOSTPROF events off)+ rows = (ht["rows"] - last.get("rows", 0)) / nr+ last.clear()+ last.update(ht)+ return ("MUFAST rounds=%d fast=%d " % (ht["rounds"], int(_fast())) + " ".join(f"{k}={v}" for k, v in fs.items()) ++ " | ms/round " + " ".join(f"{k}={v:.2f}" for k, v in ms.items()) + f" rows/round={rows:.2f}")+++ def _stage(name):+ """HY4_MU_SYNC_DEBUG=1: log the stage and sync the device when it ends (loader/mu_debug.py); a null context otherwise"""+ if os.environ.get("HY4_MU_SYNC_DEBUG", "0") in ("", "0"):+ return contextlib.nullcontext()+ from exllamav3.loader import mu_debug+ return mu_debug.stage(name)++class MuEngine(Hy4Engine):def __init__(self, *a, slots: int = 4, **kw):- for f in ("HY4_SWA_RING", "HY4_LC_SPARSE"): # long-context levers act on the single-session K / indexer buffers, not on the slot slabs+ for f in ("HY4_SWA_RING", "HY4_LC_SPARSE", "HY4_KV_FP8_MTP", "HY4_IX_POOL16", "HY4_ROPE_POS"): # long-context levers act on the single-session K / indexer buffers, not on the slot slabsif os.environ.get(f, "0") not in ("", "0"):raise RuntimeError(f + " is not supported with --slots > 1")super().__init__(*a, **kw)@@@ -331,5 -518,54 +518,56 @@@ def warmup(sch: MuScheduler, n: int, nefor r in reqs:r.done.wait(900)print(f"mu warm-up: {n} prompt tokens, 1..{eng.slots} sessions", flush=True)+ if eng.LF is not None:+ print(eng.LF.line(), flush=True)+++ def precapture(sch: MuScheduler, nbs=None, ts=None, progress=print):+ """HY4_MU_PRECAP=512,1024 (context buckets): capture every (bucket, rows) trunk graph for rows in 1..TM and every (slot, bucket) draft graph NOW, before any timing, and print+ the replay curve `MUCURVE Nb T ms` (one timed replay each; rows of one dummy session on the last slot, which a real request re-zeroes on admission). Call before the server is ready:+ the scheduler must be idle. Rows above 8 run the fallback kernels (mla_bgemv / router_gemv keep their MAXT = 8 guards, mu_slots MAX_T = 16): the curve shows their cost."""+ eng, torch = sch.eng, sch.eng.torch+ GR, MG = eng.GR, eng.MG+ TM = eng.SG.TM+ if nbs is None:+ nbs = [int(x) for x in os.environ.get("HY4_MU_PRECAP", "512").replace("+", ",").split(",") if x.strip()]+ ts = list(ts) if ts is not None else list(range(1, TM + 1))+ pc = time.perf_counter+ t00 = pc()+ s = GR.new_session(eng.slots - 1)+ for Nb in nbs:+ for T in ts:+ base = Nb - T # top = Nb: the rows land in bucket Nb+ for rep in range(3):+ GR.rewind(s, 0)+ s.tokens = [0] * base+ s.n = base+ t = pc()+ GR.step_slots([(s, [(i * 7919 + 13) % 50000 for i in range(T)])]) # varied ids: the routed experts of the rows differ, the union grows with T like real text+ torch.cuda.synchronize()+ ms = (pc() - t) * 1000+ if rep == 0:+ cap_ms = ms+ progress(f"MUCURVE Nb={Nb} T={T} ms={ms:.1f} capture_or_first_ms={cap_ms:.0f}")+ GR.rewind(s, 0)+ nd = 0+ for slot in range(eng.slots): # the draft chain graph is keyed (slot, bucket): every slot may serve the first request of a cell+ s2 = GR.new_session(slot)+ GR.bind(s2)+ MG.slot = slot+ for Nb in nbs:+ if (slot, Nb) not in MG.graphs:+ MG._graph(Nb)+ nd += 1+ free = None+ try:+ free = torch.cuda.mem_get_info()[0] / 2 ** 30+ except Exception: # noqa: BLE001+ pass+ sm = getattr(eng, "SM", None)+ if sm is not None: # the FIRES-CHECK counts the served requests only, never the precapture steps+ for k in sm.FIRES: sm.FIRES[k] = 0+ for k in sm.HT: sm.HT[k] = 0.0+ for k in FIRES: FIRES[k] = 0+ for k in HT: HT[k] = 0 if k in ("rounds", "rows") else 0.0+ progress(f"mu precapture: buckets {nbs} rows {ts[0]}..{ts[-1]}: {len(nbs) * len(ts)} trunk graphs, {nd} draft graphs, {pc() - t00:.1f} s, free GiB {free}")