Add DiffusionGemma (Gemma-4 MoE block-diffusion) support: MoE imatrix variants, AWQ MoE groups, llama.cpp bump, diffusion eval backend#4
Draft
pearsonkyle wants to merge 1 commit into
Conversation
Bump vendor/llama.cpp 9e58d4d6 -> c84e85af (head of llama.cpp PR #24423:
diffusion-gemma arch, converter, llama-diffusion-cli canvas mode, persistent
llama-diffusion-gemma-server); regenerate calibrate/_iq2_grids.py against the
new pin (grids unchanged, ksigns parity holds).
MoE-aware imatrix variants:
- hf_gguf_map: fused 3D expert rules (ffn_gate_up_exps/ffn_down_exps), router
(ffn_gate_inp), self-conditioning MLP; DiffusionGemma trunk prefixes
(model.decoder.*, model.encoder.language_model.*) normalized to model.*;
new is_moe_expert sibling of is_ssm.
- imatrix: per-expert counts normalization in _load_base_imatrix (zero-count
experts -> neutral ones, mirroring llama-quantize), per-expert reranking in
the analytic variants (L1 norm must not bleed across experts), per-expert
E[a^2] passthrough in outlier variants, and a MoE expert-coverage check
wired into both pipeline calibrate stages.
AWQ MoE extension:
- discover_groups emits L{i}_moe: the fused gate_up stack under
pre_feedforward_layernorm_2, anchored on the experts module (sees every
token pre-routing). The router reads the raw residual through its own norm,
so routing logits are exactly invariant under the fold (unit-tested).
- moe_expert_sample (default 8) caps the alpha-search cost on 128-expert
stacks; apply() handles 3D members via last-axis broadcasting.
- _hf.load_calibration_model falls back to the concrete arch class when
AutoModelForCausalLM refuses (DiffusionGemmaForBlockDiffusion);
_hf.causal_logits runs sanity checks through the causal encoder + tied
lm_head; forward_no_logits resolves the encoder trunk.
extract: ForBlockDiffusion checkpoints pass through untouched (the llama.cpp
converter owns vision-drop and decoder remapping).
Task eval without llama-server (which cannot diffusion-decode):
eval/diffusion_server.py drives the persistent logits server with a numpy
port of the entropy-bound block-diffusion sampler behind an OpenAI-compatible
shim (Gemma-4 tool-call markup parsed into tool_calls); eval/reps grows a
server_factory hook and the reps scripts a --backend diffusion flag.
scripts/bench_diffusion_speed.py times llama-diffusion-cli (llama-bench
decode tok/s is meaningless for diffusion generation).
Recipes: q2_k_diffusiongemma_imatrix (low-resource, no HF load) and
iq2_m_diffusiongemma_awq (AWQ + hybrid_custom stacked). CLAUDE.md documents
the architecture facts, imatrix caveats (UNIFIED-graph canvas region,
per-expert counts), and the GPTQ-on-experts deferral.
https://claude.ai/code/session_011BaPPBxkVCggmj1McnSC32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds end-to-end support for DiffusionGemma 26B-A4B (
google/diffusiongemma-26B-A4B-it) — a 128-expert (8 active) Gemma-4 MoE block-diffusion LLM — covering the <3bpw quantization methods, bench, and full task-level eval. This is the repo's first MoE and first diffusion architecture.Answers to the motivating questions
llama-imatrixruns a standard forward, and DiffusionGemma's causal encoder mode is exactly that, over the same weights the diffusion decoder uses (encoder/decoder are tied; only the attention mask differs). Two caveats are handled: (1) the UNIFIED graph treats the lastcanvas_length(256) positions of each chunk as a bidirectional canvas — recipes raiseimatrix_ctxto 2048 to keep that fraction small, and quant-vs-quant KLD remains valid; (2) MoE imatrix entries carry per-expert counts and 3D weights, which the variant builders previously dropped silently (which would makellama-quantizerefuse IQ2_*). They now normalize and rerank per expert, with an expert-coverage check wired into the pipeline.L{i}_moescale groups fold intopre_feedforward_layernorm_2, whose only consumer is the fused 3Dexperts.gate_up_proj. The router reads the raw residual through its own internal norm, so routing logits are exactly invariant under the fold (unit-tested in f32).moe_expert_sample(default 8) caps the α-search cost; Gemma's(1+γ)RMSNorm convention rides the existingrmsnorm_plus_onepath.Submodule bump
vendor/llama.cpp:9e58d4d6→c84e85af, the head of llama.cpp PR #24423 — current master has no DiffusionGemma support; the PR adds thediffusion-gemmaarch, converter,llama-diffusion-clicanvas mode, and a persistent logits server. Setup instructions in CLAUDE.md show how to fetch the PR ref; re-pin to master once it merges.calibrate/_iq2_grids.pyregenerated against the new pin (grids byte-identical; ksigns parity assertion passed).llama-perplexitystill has no--parse-special(re-verified); the imatrix GGUF schema and converter CLI are unchanged.Task eval without llama-server
llama-servercannot diffusion-decode, soeval/diffusion_server.pyprovidesrunning_diffusion_server(...): an OpenAI-compatible shim that renders chat prompts (with tools) via the HF tokenizer, generates through a numpy port of llama.cpp's entropy-bound block-diffusion sampler driven by the persistentllama-diffusion-gemma-server(one model load per eval), and parses Gemma-4<|tool_call>call:NAME{…}<tool_call|>markup into OpenAItool_calls. The tool-call/MMLU-Pro evals andeval.repsare untouched apart from aserver_factoryhook; reps scripts gain--backend diffusion --hf-dir <snapshot>.scripts/bench_diffusion_speed.pytimesllama-diffusion-cli(llama-bench decode tok/s is meaningless for diffusion generation).New recipes
q2_k_diffusiongemma_imatrix— low-resource path (no HF load; llama-imatrix streams the GGUF).iq2_m_diffusiongemma_awq— AWQ +hybrid_customimatrix stacked, IQ2_S codebook proxy auto-selected.Testing
ruffandmypyat or better than parity withmain(mypy 36 → 28 pre-existing errors; the one ruff finding predates this PR).ffn_*_exps, manualllama-diffusion-clisanity generation at F16 vs IQ2_M).https://claude.ai/code/session_011BaPPBxkVCggmj1McnSC32
Generated by Claude Code