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
KVWIN: the whole-forward CUDA graph keeps decoding with a bound ring; it declines only the step of a job whose ring is cold
YanissAmzd14b9a250a4d
diff --git a/exllamav3/cache/kvwin.py b/exllamav3/cache/kvwin.pyindex 4798689..48b35ce 100644--- a/exllamav3/cache/kvwin.py+++ b/exllamav3/cache/kvwin.py@@ -22,7 +22,7 @@ from typing import NamedTupleimport torchfrom ..constants import PAGE_SIZE-ANY_ACTIVE = False # a bound ring exists in this process: the whole-forward graph declines (it cannot fill cold rings)+ANY_ACTIVE = False # a bound ring exists in this process (the whole-forward graph then checks any_cold before each replay)MAX_DRAFT = 16 # rows one verify step writes at once (BC_Attention MAX_QLEN, the decode kernels' q_len cap)@@ -139,7 +139,7 @@ class KVWinLayerState:self.cache_layer = cache_layerglobal ANY_ACTIVEANY_ACTIVE = True- cache_layer.kvwin = self # BC_Attention (graph decode) and the whole-forward graph decline such layers+ cache_layer.kvwin = self # BC_Attention (per-layer graph decode) declines such layers: they run the Python path@propertydef active(self) -> bool:@@ -244,6 +244,20 @@ class KVWinLayerState:dst[slot].index_copy_(0, rows, out.view(-1, m.num_kv_heads, m.head_dim))+def any_cold(params: dict) -> bool:+ """True when a job of this call has a cold ring (restored from a checkpoint without ring blob): its rebuild from the pool is a+ host-side step, so the whole-forward graph declines that step (the eager call fills it) and replays from the next one."""+ rs, cache = params.get("recurrent_states"), params.get("cache")+ rl = getattr(cache, "recurrent_layers", None)+ if not rs or not rl:+ return False+ slots = [r.slot for r in rs]+ for st in rl.values():+ if getattr(st, "kvwin", False) and st.active and any(st.cold[s] for s in slots):+ return True+ return False++def make_ctx(cache_layer_state: KVWinLayerState | None, params: dict, device, bsz: int) -> KVWinCtx | None:"""Ring context of one attention call from params["recurrent_states"] (one state per batch row), or Nonewhen the ring is inert or the call has no job states (plain batched forward: quantized cache only)."""diff --git a/exllamav3/model/cuda_graph.py b/exllamav3/model/cuda_graph.pyindex fac08ae..7d90789 100644--- a/exllamav3/model/cuda_graph.py+++ b/exllamav3/model/cuda_graph.py@@ -312,8 +312,8 @@ class CudaGraphRunner:if params.get("indexed_embeddings"):return "state"from ..cache import kvwin- if kvwin.ANY_ACTIVE:- return "kvwin" # the ring writes / cold fills run in Python between layers+ if kvwin.ANY_ACTIVE and kvwin.any_cold(params):+ return "kvwin_cold" # the cold ring fill is a host step: eager this step, graph again from the next oners = params.get("recurrent_states")if self.has_gdn or self.has_conv or self.has_mamba or self.has_swa:slots = params.get("recurrent_slots")diff --git a/tests/test_kvwin.py b/tests/test_kvwin.pyindex 0b11c7c..2ae114a 100644--- a/tests/test_kvwin.py+++ b/tests/test_kvwin.py@@ -624,3 +624,23 @@ def test_off_is_bitwise_today():if __name__ == "__main__":sys.exit(pytest.main([__file__, "-x", "-q"] + sys.argv[1:]))+++def test_whole_forward_graph_declines_only_for_a_cold_ring(monkeypatch):+ """A bound ring no longer blocks the whole-forward graph: only a step whose job has a cold ring (host-side fill) runs eager."""+ from exllamav3.model.cuda_graph import CudaGraphRunner+ cache, model, cl, st = _fake_cache(monkeypatch)+ state = cache.get_new_state()+ runner = object.__new__(CudaGraphRunner)+ runner.has_gdn, runner.has_conv, runner.has_mamba, runner.has_swa = True, False, False, False+ ids = torch.zeros((1, 1), dtype = torch.long)+ params = {"block_table": torch.zeros((1, 4), dtype = torch.int32), "cache_seqlens": torch.full((1,), 300, dtype = torch.int32),+ "cache": cache, "recurrent_states": [state], "recurrent_slots": torch.tensor([state.slot], dtype = torch.int32)}+ monkeypatch.setattr(torch.cuda, "is_current_stream_capturing", lambda: False)+ assert kvwin.ANY_ACTIVE and not kvwin.any_cold(params)+ assert runner._decline(ids, params) is None+ st.cold[state.slot] = True+ assert kvwin.any_cold(params) and runner._decline(ids, params) == "kvwin_cold"+ st.cold[state.slot] = False+ assert runner._decline(ids, params) is None+ assert not kvwin.any_cold({}) and not kvwin.any_cold({"recurrent_states": [state]})