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
GGUF registry: predicate blocks for the Hy4 / glm5-next / deepseek41 pieces
YanissAmzda8e3b6be9ff
diff --git a/exllamav3/loader/gguf_blocks/engram.py b/exllamav3/loader/gguf_blocks/engram.pynew file mode 100644index 0000000..7bbcdf3--- /dev/null+++ b/exllamav3/loader/gguf_blocks/engram.py@@ -0,0 +1,45 @@+"""Blocks around modules/dsv41_fn/engram_dev.py (Engram n-gram rows) and the F8_E4M3 row table (ggml type 43).+Predicates + configs only (Hy4 step 2). Layout comes from the ple.* / engram.* keys, shared by hy_v4_flash and deepseek41."""+from __future__ import annotations+from ..gguf_registry import Block, register++GGML_F8_E4M3 = 43 # ggml_master.h:262; row-lookup-only: never a Linear, never dequantised resident++_HY4_GATE = ("engram_kv_b.weight", "engram_lookup_norm.weight", "engram_pre_gamma.weight", "engram_hc_scale.weight")+++def _engram_layer(ctx, i):+ pl = list(ctx.key("ple.layers") or [])+ n, h = ctx.key("ple.ngram_size"), ctx.key("ple.heads_per_ngram")+ cols = (n - 1) * h if n and h else None+ offs = ctx.key("ple.head_offsets") or []+ return {"module": pl.index(i), "n_modules": len(pl), "ngram_size": n, "heads_per_ngram": h, "columns": cols,+ "row_width": ctx.key("embedding_length_per_layer_input"), "n_head_offsets": len(offs),+ "offsets_cover_modules": bool(cols) and len(offs) == cols * len(pl),+ "variant": "hy4_gate" if all(ctx.has(i, s) for s in _HY4_GATE) else "ds41_gate",+ "kv_dims": ctx.dims(f"blk.{i}.engram_kv.weight"), "pad_token_id": ctx.key("engram.pad_token_id"),+ "token_map": len(ctx.key("engram.token_map") or []), "eps": ctx.feats.get("engram_eps")}+++register(Block(+ "engram", "pre", step="step 2",+ select=lambda ctx, i: i in (ctx.key("ple.layers") or []) and ctx.has(i, "engram_kv.weight"),+ config=_engram_layer, claims=frozenset({"engram_kv.weight", "engram_gate.weight", *_HY4_GATE}), build=None))+++def _f8_cfg(ctx, i):+ ty, dims, off = ctx.infos["per_layer_token_embd.weight"]+ part = off >> 48+ bases = getattr(ctx.g, "bases", None)+ offs = ctx.key("ple.head_offsets") or []+ sizes = ctx.key("ple.head_vocab_sizes") or []+ return {"type": ty, "row_width": dims[0], "rows": dims[1], "row_bytes": dims[0] if ty == GGML_F8_E4M3 else None,+ "part": part, "data_offset": (bases[part] if bases else 0) + (off & ((1 << 48) - 1)),+ "width_matches_ple": dims[0] == ctx.key("embedding_length_per_layer_input"),+ "rows_match_offsets": bool(offs) and offs[-1] + sizes[-1] == dims[1]}+++register(Block(+ "f8_rows", "embed_mod", step="step 2",+ select=lambda ctx, i: "per_layer_token_embd.weight" in ctx.infos and ctx.infos["per_layer_token_embd.weight"][0] == GGML_F8_E4M3,+ config=_f8_cfg, claims=frozenset({"per_layer_token_embd.weight"}), build=None))diff --git a/exllamav3/loader/gguf_blocks/hyperconnections.py b/exllamav3/loader/gguf_blocks/hyperconnections.pynew file mode 100644index 0000000..99123d5--- /dev/null+++ b/exllamav3/loader/gguf_blocks/hyperconnections.py@@ -0,0 +1,38 @@+"""Blocks around modules/hyperconnections.py: HyperConnection stream (comb = identity, or Sinkhorn mHC) and HyperHead.+Predicates + configs only (Hy4 step 5)."""+from __future__ import annotations+from ..gguf_registry import Block, register++_RESID_NORMS = ("attn_norm.weight", "ffn_norm.weight", "post_attention_norm.weight", "post_ffw_norm.weight")+++def hc_layer(ctx, i):+ H = ctx.key("hyper_connection.count")+ fn = ctx.dims(f"blk.{i}.hc_attn_fn.weight") # ggml dims (H * n_embd, rows)+ rows = fn[1] if fn and len(fn) > 1 else None+ sk = ctx.key("hyper_connection.sinkhorn_iterations")+ if sk is None and rows == 2 * H:+ mode = "identity" # pre + post only (hy_v4_flash; M:5431 comb is the identity)+ elif sk and rows == (2 + H) * H:+ mode = "sinkhorn" # pre + post + H x H comb, Sinkhorn-normalised (deepseek41, glm5-next)+ else:+ mode = "?"+ if mode == "identity" and not ctx.feats.get("hc_comb_identity"):+ mode = "?" # identity only where llama.cpp hard-codes it+ return {"count": H, "eps": ctx.key("hyper_connection.epsilon"), "magnitude": ctx.key("hyper_connection.magnitude"),+ "sinkhorn_iterations": sk, "fn_dims": fn, "fn_type": ctx.infos[f"blk.{i}.hc_attn_fn.weight"][0] if fn else None,+ "mode": mode, "norms": [s for s in _RESID_NORMS if ctx.has(i, s)]}+++register(Block(+ "hyper_connection", "stream", step="step 5", priority=1,+ select=lambda ctx, i: bool(ctx.key("hyper_connection.count")) and ctx.has(i, "hc_attn_fn.weight"),+ config=hc_layer,+ claims=frozenset({f"hc_{s}_{t}.weight" for s in ("attn", "ffn") for t in ("fn", "base", "scale")} | set(_RESID_NORMS)),+ build=None))++register(Block(+ "hyper_head", "head_mod", step="step 5",+ select=lambda ctx, i: "output_hc_fn.weight" in ctx.glob,+ config=lambda ctx, i: {"fn_dims": ctx.dims("output_hc_fn.weight"), "count": ctx.key("hyper_connection.count")},+ claims=frozenset({"output_hc_fn.weight", "output_hc_base.weight", "output_hc_scale.weight"}), build=None))diff --git a/exllamav3/loader/gguf_blocks/mla_attn.py b/exllamav3/loader/gguf_blocks/mla_attn.pynew file mode 100644index 0000000..ec9278b--- /dev/null+++ b/exllamav3/loader/gguf_blocks/mla_attn.py@@ -0,0 +1,70 @@+"""Blocks around modules/mla_attn.py: the MLA GGUF adapter and its modifiers. Predicates + configs only (Hy4 steps 3-4):+the builds come later. Selection is by keys / tensor names checked on the hy_v4_flash and glm5-next headers."""+from __future__ import annotations+from ..gguf_registry import Block, register++_MLA = frozenset({"attn_q_a.weight", "attn_q_a_norm.weight", "attn_q_b.weight", "attn_q.weight", "attn_kv_a_mqa.weight",+ "attn_kv_a_norm.weight", "attn_k_b.weight", "attn_v_b.weight", "attn_output.weight"})+++def is_mla(ctx, i):+ """GGUF MLA (llama.cpp deepseek2 layout): kv_lora_rank key + compressed kv + per-head absorbed k_b / v_b"""+ return ctx.key("attention.kv_lora_rank") is not None and all(+ ctx.has(i, s) for s in ("attn_kv_a_mqa.weight", "attn_k_b.weight", "attn_v_b.weight"))+++def _mla_layer(ctx, i):+ nh = ctx.per_layer("attention.head_count")+ kb = ctx.dims(f"blk.{i}.attn_k_b.weight")+ return {"n_head": nh[i], "q_lora_rank": ctx.key("attention.q_lora_rank"), "kv_lora_rank": ctx.key("attention.kv_lora_rank"),+ "qk_head_dim": ctx.key("attention.key_length_mla"), "v_head_dim": ctx.key("attention.value_length_mla"),+ "rope_dim": ctx.key("rope.dimension_count"), "k_b_dims": kb, "v_b_dims": ctx.dims(f"blk.{i}.attn_v_b.weight"),+ "kv_a_dims": ctx.dims(f"blk.{i}.attn_kv_a_mqa.weight"), "kq_scale_dim": ctx.key("attention.key_length_mla")}+++register(Block("mla", "attn", select=is_mla, config=_mla_layer, claims=_MLA, build=None, step="step 3", priority=1))+++def _swa(ctx, i):+ pat = ctx.key("attention.sliding_window_pattern")+ return bool(pat[i]) if isinstance(pat, list) and i < len(pat) else False+++register(Block(+ "mla_window_sinks", "attn_mod", step="step 3",+ select=lambda ctx, i: is_mla(ctx, i) and (ctx.has(i, "attn_sinks.weight") or (_swa(ctx, i) and ctx.key("attention.sliding_window"))),+ config=lambda ctx, i: {"swa": _swa(ctx, i), "window": ctx.key("attention.sliding_window") if _swa(ctx, i) else 0,+ "rope_theta": ctx.key("rope.freq_base_swa") if _swa(ctx, i) else ctx.key("rope.freq_base"),+ "sinks": ctx.has(i, "attn_sinks.weight")},+ claims=frozenset({"attn_sinks.weight"}), build=None))++register(Block(+ "mla_output_gate", "attn_mod", step="step 3",+ select=lambda ctx, i: is_mla(ctx, i) and ctx.has(i, "attn_gate.weight"),+ config=lambda ctx, i: {"gate": "sigmoid_full", "dims": ctx.dims(f"blk.{i}.attn_gate.weight")},+ claims=frozenset({"attn_gate.weight"}), build=None))+++def _indexer_layer(ctx, i):+ types = ctx.key("attention.indexer.types")+ if ctx.has(i, "indexer_compressor_value.weight"):+ variant = "kpool_value" # hy_v4_flash: pooled projection of the key, gate off the key, norm after the pool+ elif ctx.has(i, "indexer_compressor_gate.weight"):+ variant = "kpool_gate" # glm5-next+ else:+ variant = "dsa" # deepseek v3.2 / v4 indexer, no pooling+ return {"variant": variant, "k_norm": "layernorm" if ctx.has(i, "indexer.k_norm.bias") else "rms_weight",+ "n_head": ctx.key("attention.indexer.head_count"), "head_dim": ctx.key("attention.indexer.key_length"),+ "top_k": ctx.key("attention.indexer.top_k"), "kpool": ctx.key("attention.indexer.kpool"),+ "select_tail": ctx.key("attention.indexer.kpool_select_tail"),+ "typed": bool(types[i]) if isinstance(types, list) and i < len(types) else None,+ "rope_tail": bool(ctx.feats.get("indexer_rope_tail"))}+++register(Block(+ "dsa_indexer", "attn_mod", step="step 4",+ select=lambda ctx, i: ctx.has(i, "indexer.attn_k.weight") or ctx.has(i, "indexer.attn_q_b.weight"),+ config=_indexer_layer,+ claims=frozenset({"indexer.attn_k.weight", "indexer.attn_q_b.weight", "indexer.k_norm.weight", "indexer.k_norm.bias",+ "indexer.proj.weight", "indexer_compressor_ape.weight", "indexer_compressor_gate.weight",+ "indexer_compressor_norm.weight", "indexer_compressor_value.weight"}), build=None))diff --git a/exllamav3/loader/gguf_blocks/mlp.py b/exllamav3/loader/gguf_blocks/mlp.pyindex e009ad4..deb9a6a 100644--- a/exllamav3/loader/gguf_blocks/mlp.py+++ b/exllamav3/loader/gguf_blocks/mlp.py@@ -1,4 +1,5 @@-"""Blocks around modules/mlp.py and block_sparse_mlp.py: dense gated MLP, standard top-k MoE (+shared, +biases)."""+"""Blocks around modules/mlp.py and block_sparse_mlp.py: dense gated MLP, standard top-k MoE (+shared, +biases),+and the predicates of the latent MoE / sigmoid-bias router (not built yet)."""from __future__ import annotationsfrom ..gguf_registry import Block, register, req@@ -142,3 +143,31 @@ register(Block("moe_ffn", "ffn",select=lambda ctx, i: ctx.has(i, "ffn_gate_exps.weight") and not ctx.has(i, "ffn_routed_down.weight"),config=_moe_layer, claims=_MOE_CLAIMS, build=_moe_build, names=_moe_names))+++# ---- predicates only (Hy4 step 5): latent MoE (routed experts at expert_latent_length between ffn_routed_down/up),+# sigmoid router (gating_func 2) + exp_probs_b, weights_scale, per-layer swiglu_clamp_exp; engine module: block_sparse_mlp latent_in/out+def _latent_layer(ctx, i):+ gd = ctx.dims(f"blk.{i}.ffn_gate_exps.weight")+ sh = ctx.dims(f"blk.{i}.ffn_gate_shexp.weight")+ clamp = ctx.per_layer("swiglu_clamp_exp", 0.0)+ return {"latent": ctx.key("expert_latent_length"), "latent_down": ctx.dims(f"blk.{i}.ffn_routed_down.weight"),+ "expert_dims": gd, "num_experts": gd[2] if gd else None, "top_k": ctx.key("expert_used_count"),+ "gating_func": ctx.key("expert_gating_func"), "weights_scale": ctx.key("expert_weights_scale"),+ "weights_norm": ctx.key("expert_weights_norm"), "e_score_bias": ctx.has(i, "exp_probs_b.bias"),+ "clamp": clamp[i] if i < len(clamp) else None, "clamp_routed_only": bool(ctx.feats.get("clamp_routed_only")),+ "shared_dims": sh}+++register(Block(+ "latent_moe", "ffn", step="step 5",+ select=lambda ctx, i: ctx.has(i, "ffn_routed_down.weight") and ctx.has(i, "ffn_gate_exps.weight"),+ config=_latent_layer, claims=_MOE_CLAIMS | {"ffn_routed_down.weight", "ffn_routed_up.weight", "exp_probs_b.bias"}, build=None))++# sigmoid / sqrt-softplus router with a per-expert score bias on a plain MoE layer (glm5-next, deepseek41); predicate only+register(Block(+ "router_score_bias", "ffn_mod", step="step 5",+ select=lambda ctx, i: ctx.has(i, "exp_probs_b.bias") and not ctx.has(i, "ffn_routed_down.weight"),+ config=lambda ctx, i: {"gating_func": ctx.key("expert_gating_func"), "weights_scale": ctx.key("expert_weights_scale"),+ "vl_bias": ctx.has(i, "exp_probs_b_vl.bias")},+ claims=frozenset({"exp_probs_b.bias", "exp_probs_b_vl.bias"}), build=None))diff --git a/exllamav3/loader/gguf_blocks/mtp.py b/exllamav3/loader/gguf_blocks/mtp.pynew file mode 100644index 0000000..f5ae454--- /dev/null+++ b/exllamav3/loader/gguf_blocks/mtp.py@@ -0,0 +1,10 @@+"""MTP / nextn block (blk.<n>.nextn.*): predicate only, built after the trunk is correct (Hy4 step 8)."""+from __future__ import annotations+from ..gguf_registry import Block, register++register(Block(+ "mtp_nextn", "layer_mod", step="step 8",+ select=lambda ctx, i: ctx.has(i, "nextn.eh_proj.weight"),+ config=lambda ctx, i: {"nextn_predict_layers": ctx.key("nextn_predict_layers")},+ claims=frozenset({"nextn.eh_proj.weight", "nextn.enorm.weight", "nextn.hnorm.weight", "nextn.shared_head_norm.weight",+ "nextn.embed_tokens.weight", "nextn.shared_head_head.weight"}), build=None))diff --git a/exllamav3/loader/gguf_registry.py b/exllamav3/loader/gguf_registry.pyindex a5680e3..dc6a8e7 100644--- a/exllamav3/loader/gguf_registry.py+++ b/exllamav3/loader/gguf_registry.py@@ -26,7 +26,7 @@ BASE_SLOTS = ("pre", "stream", "attn", "ffn")MOD_SLOTS = ("attn_mod", "ffn_mod", "layer_mod")GLOBAL_SLOTS = ("embed", "embed_mod", "head", "head_mod")CONFIG_ONLY = "config-only" # build marker: the block feeds module configs, no module of its own-BLOCK_MODULES = ("transformer", "attn", "mlp")+BLOCK_MODULES = ("transformer", "attn", "mlp", "mla_attn", "hyperconnections", "engram", "mtp")# Per-arch features llama.cpp hard-codes with no GGUF key. Every entry names the llama.cpp source it mirrors# (M = the model patch published with the model, else the llama.cpp file).@@ -46,6 +46,13 @@ ARCH_FEATS = {# src/models/gemma4.cpp (see GEMMA4_UNCHECKED.md): LLM_FFN_GELU (tanh) dense act; build_inp_embd(.., sqrtf(n_embd));# unweighted rms_norm on V of every layer (K=V layers: V = raw k_proj output); hparams.f_attention_scale = 1.0"gemma4": {"act": "gelu", "embed_scale": True, "v_norm": True, "sm_scale": 1.0},+ "hy_v4_flash": {+ "rope_gptj": True, # M:4784 llama_model_rope_type: HY_V4_FLASH -> LLAMA_ROPE_TYPE_NORM (consecutive pairs), weights not permuted+ "engram_eps": 1.1920929e-07, # M:4852 HY_V4_FLASH_ENGRAM_EPS: Engram RMSNorms use FLT_EPSILON, not rms_norm_eps+ "clamp_routed_only": True, # M:4885 swiglu_clamp_exp applies to the routed experts only; shared and dense FFNs unclamped+ "indexer_rope_tail": True, # M:4936 the indexer head is a nope front + rope tail (rope on the last n_rot dims)+ "hc_comb_identity": True, # M:5431 HC post: comb is the identity, no cross-stream mix (no sinkhorn key in the GGUF)+ },}