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.

ROCm block graph: capture only single-row decode by default (EXL3_BLOCK_GRAPH_MAX_Q), multi-row n-gram/verify steps stay eager (#143)

Yaniss Amazouz175339317242
diff --git a/exllamav3/modules/block_graph.py b/exllamav3/modules/block_graph.py
index ec0aeee..bc75f88 100644
--- a/exllamav3/modules/block_graph.py
+++ b/exllamav3/modules/block_graph.py
@@ -46,6 +46,10 @@ _env_int = lambda name, default: int(os.environ.get(name, default) or default)
BLOCK_GRAPH_ENABLED = os.environ.get("EXL3_BLOCK_GRAPH", "1" if torch.version.hip else "0") == "1"
BLOCK_GRAPH_WARMUPS = max(1, _env_int("EXL3_BLOCK_GRAPH_WARMUPS", 3))
BLOCK_GRAPH_MAX_SLOTS = max(1, _env_int("EXL3_BLOCK_GRAPH_MAX_SLOTS", 4))
+# Rows per sequence a non-MLA block graph captures. Default 1 (plain decode). Multi-row steps (n-gram or MTP
+# verify, 2..8 rows) have one specialization per row count: more keys than BLOCK_GRAPH_MAX_SLOTS, so the
+# slots evict each other and the blocks re-warm and re-capture all the time (Flash-Next 128K decode -13 %).
+BLOCK_GRAPH_MAX_Q = max(1, _env_int("EXL3_BLOCK_GRAPH_MAX_Q", 1))
# Rows above the dense GEMV cap reconstruct+hgemm; still captureable, but the first bounded
# implementation keeps the served decode envelope. Revisit after (B,Q) family measurements.
@@ -189,6 +193,9 @@ class BlockGraphRunner:
return None
if isinstance(attn, MLAttention) and BLOCK_GRAPH_MLA:
return self._mla_key(x, params)
+ if x.shape[1] > BLOCK_GRAPH_MAX_Q and not isinstance(attn, MLAttention):
+ self.stats["declines"]["rows_q"] += 1
+ return None
if BLOCK_GRAPH_ATTN and type(attn) is Attention:
return self._attn_key(x, params)
if not isinstance(attn, GatedDeltaNet) or attn.bc is not None:
diff --git a/tests/test_hip_block_graph.py b/tests/test_hip_block_graph.py
index 119c238..9e09bf5 100644
--- a/tests/test_hip_block_graph.py
+++ b/tests/test_hip_block_graph.py
@@ -186,6 +186,17 @@ class TestDeclines:
assert runner.stats["declines"]["recurrent_slots"] == 1
[email protected](not (torch.version.hip and torch.cuda.is_available()), reason="requires a ROCm device")
+def test_multirow_step_declines_by_default():
+ # n-gram / MTP verify steps carry 2..8 rows: one specialization per row count would
+ # thrash the per-block slots, so only single-row decode is captured unless raised.
+ device = torch.device("cuda", 0)
+ runner = _runner(device)
+ assert block_graph.BLOCK_GRAPH_MAX_Q == 1
+ assert runner.slot_key(_decode_input(device, rows=4), _eligible_params()) is None
+ assert runner.stats["declines"]["rows_q"] == 1
+
+
@pytest.mark.skipif(not _gfx12_available(), reason="requires a gfx12 device")
def test_eligible_call_produces_slot_key():
device = torch.device("cuda", 0)