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
Hy4 multi-session: the draft graphs of different slots share one memory pool, so MTPGraphMU.run returns a private copy of the drafts (replaying an earlier-captured graph after a later one overwrote the later graph output before the host read it: garbage draft ids, out-of-range embedding gather, HSA 0x1016), CPU test with pool-aliased fake graphs
YanissAmz93fbb80ced82
diff --git a/exllamav3/loader/step_mu.py b/exllamav3/loader/step_mu.pyindex a9b2624..fcf6a8f 100644--- a/exllamav3/loader/step_mu.py+++ b/exllamav3/loader/step_mu.py@@ -249,6 +249,13 @@ class MTPGraphMU(_MH.MTPGraph):"""the draft chain graph per (slot, bucket): the captured graph holds the addresses of the slot's K buffer / indexer slab views (set `slot` and bind the session first)"""slot = 0+ def run(self, tok, h, j):+ """drafts of the bound session as a PRIVATE device tensor. The (slot, N) graphs share one memory pool and a graph's output can live in a block that an+ earlier-captured graph used for intermediates: replaying graph A after graph B (two sessions whose slots were first drafted in the other order) overwrote+ the drafts of B before the host read them (garbage token ids -> out-of-range embedding gather -> HSA 0x1016 in the verify replay). The clone is stream-ordered+ right after its own replay, so no later replay can touch it."""+ return super().run(tok, h, j).clone()+def _graph(self, N):key = (self.slot, N)g = self.graphs.get(key)diff --git a/tests/test_hy4_mu_draft_alias.py b/tests/test_hy4_mu_draft_alias.pynew file mode 100644index 0000000..ed85d8e--- /dev/null+++ b/tests/test_hy4_mu_draft_alias.py@@ -0,0 +1,81 @@+"""CPU check of MTPGraphMU.run with fake captured graphs that emulate the shared memory pool: the (slot, N) draft graphs capture into ONE pool, so a graph's output can sit in a+block an earlier-captured graph uses for intermediates. Replaying the earlier graph AFTER the later one (two sessions whose slots were first drafted in the other order, the+speculative round of a 3rd / later request pair) overwrote the later graph's drafts before the host read them (garbage ids -> HSA 0x1016 in the verify replay).+run() must hand back a private copy: every session's drafts read after both replays equal what its own replay wrote."""+import os+import sys+import types+from types import SimpleNamespace++import torch++ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+for _n, _s in (("exllamav3", ""), ("exllamav3.loader", "loader")):+ _m = sys.modules.get(_n) or types.ModuleType(_n)+ _m.__path__ = [os.path.join(ROOT, "exllamav3", _s)]+ sys.modules[_n] = _m++from exllamav3.loader import mtp_head as MH # noqa: E402+from exllamav3.loader import step_mu # noqa: E402++K = 3+GARBAGE = 10 ** 9+++class AliasedGraph:+ """replay writes the drafts of the bound slot (token + j .. ) into `out`; `clobbers` = the outputs of later-captured graphs that live in this graph's intermediate blocks"""++ def __init__(self, out, clobbers=()):+ self.out, self.clobbers, self.slot_tok = out, list(clobbers), None++ def replay(self):+ for c in self.clobbers:+ c.fill_(GARBAGE) # the intermediates of this graph overwrite whatever later captures put in the shared blocks+ self.out.copy_(self.inp[0] + torch.arange(1, K + 1)) # drafts = f(token): distinguishes the sessions+++def make():+ pool = torch.zeros(2 * K, dtype=torch.long)+ out1, out2 = pool[:K], pool[K:] # graph 1 (captured first) and graph 2 (captured second)+ d = object.__new__(step_mu.MTPGraphMU)+ d.mt = SimpleNamespace(cap=4096)+ d.k = K+ d.hin = torch.zeros(2, dtype=torch.long)+ d.inp = torch.zeros(2, dtype=torch.long)+ d.h0 = torch.zeros(1, 4)+ d.ev, d.ev_set = SimpleNamespace(synchronize=lambda: None, record=lambda: None), False+ g1, g2 = AliasedGraph(out1, clobbers=[out2]), AliasedGraph(out2)+ for g in (g1, g2):+ g.inp = d.inp+ d.graphs = {(1, 512): (g1, out1), (2, 512): (g2, out2)}+ d._graph = lambda N: d.graphs[(d.slot, N)]+ return d+++def drafts_after(run, reverse):+ d = make()+ order = [(2, 100), (1, 200)] if reverse else [(1, 200), (2, 100)]+ outs = {}+ for slot, tok in order:+ d.slot = slot+ outs[slot] = run(d, tok, torch.zeros(1, 4), 5)+ return {s: o.tolist() for s, o in outs.items()}+++def test_naive_pool_aliasing_is_real_in_the_emulation():+ naive = lambda d, tok, h, j: MH.MTPGraph.run(d, tok, h, j)+ assert drafts_after(naive, reverse=False) == {1: [201, 202, 203], 2: [101, 102, 103]} # capture order: safe+ got = drafts_after(naive, reverse=True) # graph 2 replayed, then graph 1: graph 2's drafts are garbage+ assert got[1] == [201, 202, 203] and got[2] == [GARBAGE] * K+++def test_run_returns_private_drafts_in_either_replay_order():+ fixed = lambda d, tok, h, j: step_mu.MTPGraphMU.run(d, tok, h, j)+ for reverse in (False, True):+ assert drafts_after(fixed, reverse) == {1: [201, 202, 203], 2: [101, 102, 103]}, reverse+++if __name__ == "__main__":+ test_naive_pool_aliasing_is_real_in_the_emulation()+ test_run_returns_private_drafts_in_either_replay_order()+ print("ok")