Adaptive compute for sparse MoE models on consumer hardware — demonstrated on Google's official QAT Q4_0 Gemma 4 26B-A4B (26B total / 4B active).
Instead of running every token at fixed K=8 experts, this release combines runtime per-request dynamic MoE expert routing (moe_top_k ∈ {2, 4, 8}) via ARGUS, a 39 MB K-Aware Thinking LoRA (gemma4_kat_v1.gguf), and an 11 KB self-supervised Value-of-Computation (VoC) router (voc_gate_q40.npz) — fitting multimodal 26B inference inside 4 GB VRAM + 32 GB RAM.
Companion Release — Modular 39 MB Specialist Cartridges: Looking for hot-swappable agent tool-calling (ToolUse v2, formerly Hermes v2) and desktop UI grounding (PC Vision v1) adapters that run alongside
gemma4_kat_v1.ggufinside a single4 GB VRAMserver (2,595 MiBpeak VRAM,0.65–0.96 msHTTP/lora-adaptersswitch)? SeeZwannFrederick/Gemma-4-26B-A4B-QAT-Specialist-Cartridges-v1.
| Metric | Result | Notes |
|---|---|---|
| Hard Task Accuracy | 43.8% → 87.5% (2.0×) |
7/16 → 14/16 (KAT K=4 vs Base K=8) |
| Decode Throughput | 1.51× (18.5 → 27.9 tok/s) |
KAT K=4 vs Base K=8 (tg_128: 18.32 → 28.71 tok/s) |
| Additional VRAM | +60 MiB (2,748 → 2,808 MiB) |
With --mmproj --no-mmproj-offload |
| GGUF Adapter Size | 39 MB (470 BF16 tensors) |
r=16, Attention + Shared MLP + MoE Router |
| Self-Supervised VoC Gate | 0.9417 AUROC |
Easy+Aleatoric vs Hard (11 KB, zero labels) |
| Hardware Requirement | 4 GB VRAM + 32 GB RAM |
30/30 MoE expert layers RAM-pinned |
Scope note: Small controlled evaluation suite (
16hard reasoning/code problems +4easy +2aleatoric +3.2Kneedle on RTX 3050 Ti 4 GB). Compares KATK=4vs BaseK=8under identical server settings; not a general-purpose benchmark (e.g. MMLU/GPQA).
License & Component Provenance: This adapter is a derivative of Google DeepMind's official Gemma 4 QAT checkpoints (
google/gemma-4-26B-A4B-it-qat-q4_0-unquantizedandgoogle/gemma-4-26B-A4B-it-qat-q4_0-gguf), which are licensed under Apache 2.0 (https://ai.google.dev/gemma/docs/gemma_4_license). Included training/evaluation scripts are licensed under Apache 2.0; GSM8K training data is MIT, ARGUS is Apache 2.0, andllama.cppis MIT. Base model weights are not redistributed here; download them directly from Google on Hugging Face.
| File / Folder | Size | Description |
|---|---|---|
gemma4_kat_v1.gguf |
39 MB |
BF16 GGUF LoRA (470 tensors, r=16, 20.0M params: Attention q/k/v/o + Shared MLP gate/up/down + MoE Router ffn_gate_inp) for ARGUS / llama.cpp |
adapter_config.json + adapter_model.safetensors |
77 MB |
Standard root-level Hugging Face PEFT LoRA (task_type: "CAUSAL_LM") for PyTorch / peft |
voc_gate_q40.npz + voc_calibration_q40.json |
11 KB |
Self-supervised Q4_0-native linear VoC router (2,817 params, zero difficulty labels, zero PyTorch required) |
voc_gate.npz + voc_calibration.json |
1.4 MB |
Reference bf16-trained 2-layer VoC MLP (363,777 params) |
argus_voc_router.py |
10 KB |
Standalone pure-NumPy + stdlib CLI router for live ARGUS llama-server (--interactive, --prompt, --image, --think-k 4|8) |
code/crte/ |
240 KB |
Full training (gemma4_qat_kat.py), dataset generation (gemma4_qat_data.py), Q4_0 VoC calibration (calibrate_voc_q40.py), adaptive verification (adaptive_reasoner.py, eval_adaptive_verify.py), and A/B eval (eval_gemma4_argus_ab.py) scripts |
benchmarks/ |
48 KB |
Raw JSON measurements (summary.json, local_ab_base_control.json, local_ab_kat_v1.json, local_voc_kat_v1_q40_native.json, local_ab_adaptive_verify.json, data_manifest.json) |
assets/pareto_frontier.png |
160 KB |
Speed–accuracy Pareto frontier plot generated directly from benchmarks/*.json |
SHA256SUMS.txt |
1 KB |
Checksums for release artifacts |
The recipe itself is model-agnostic for any sparse MoE architecture with dynamic top_k routing:
K ∈ {8, 4, 2}): Sparse MoE models are normally trained at a fixed active expert count (K=8). Lowering K at inference directly cuts RAM-bandwidth reads on consumer hardware (18.5 → 28.0 → 38.8 tok/s with --mmproj, or 20.9 → 33.8 → 47.1 tok/s text-only), but untrained low-K routing collapses hard reasoning (0/16 at K=2). KAT trains a compact LoRA strictly on always-active weights (Attention + Shared MLP + MoE Router):<|channel>thought traces across K ∈ {8, 4, 2} plus a K=8 teacher KL anchor when K < 8.KL(p_{K=8} || p_K) distillation at K ∈ {2, 4} with thinking disabled, preserving low-K fluency without memorization.VoC Gate (voc_gate_q40.npz, 11 KB): Trained without difficulty labels directly on live Q4_0 K=2 prompt-end hidden states (RMSNorm(h2) via /embeddings, moe_top_k=2) to predict whether upgrading from (K=2, no-think) to (K=8, <think>) meaningfully changes a non-aleatoric prompt's answer — avoiding the entropy trap on random/aleatoric prompts.Hardware: NVIDIA RTX 3050 Ti Laptop (4 GB VRAM, PCIe Gen3 x4 = 3.14 GB/s), Intel i5-11300H, 32 GiB DDR4 (42.2 GB/s).
Base GGUF: Official google/gemma-4-26B-A4B-it-qat-q4_0-gguf/gemma-4-26B_q4_0-it.gguf (13.44 GiB, 30/30 MoE layers RAM-pinned).
Exact runtime build: ARGUS v1.0.1-moe-topk (commit 498eca1, pinned upstream llama.cpp 5bacb7c868a2bc98682de15f447fc1ce17c9c49c).
Server flags (identical across Base and KAT): -c 32768 -ngl 99 -ncmoe 30 -fa on -nkvo -ctk q4_0 -ctv q4_0 -np 1 -t 4 -tb 6 -b 512 -ub 512 --load-mode mmap --no-warmup --embeddings --pooling last --mmproj mmproj-gemma-4-26B-BF16.gguf --no-mmproj-offload (ARGUS_AUTO=1 ARGUS_P3_COALESCE=1).
K ∈ {8, 4, 2}| Metric | Base K=8 |
KAT K=8 |
Base K=4 |
KAT K=4 |
Base K=2 |
KAT K=2 |
|---|---|---|---|---|---|---|
VRAM (+mmproj) |
2,748 MiB |
2,808 MiB |
2,760 MiB |
2,820 MiB |
2,760 MiB |
2,820 MiB |
Decode (math_nt_tg) |
18.5 tok/s |
18.6 tok/s |
28.0 tok/s |
27.9 tok/s |
38.8 tok/s |
38.2 tok/s |
Decode (tg_128) |
18.32 tok/s |
16.13 tok/s |
27.79 tok/s |
28.71 tok/s |
37.72 tok/s |
38.42 tok/s |
| 3.2K Needle / Easy TR+EN | OK / 4/4 |
OK / 4/4 |
OK / 4/4 |
OK / 4/4 |
OK / 4/4 |
OK / 4/4 |
| Hard Math (no-think, 8) | 6/8 (75.0%) |
7/8 (87.5%) |
5/8 (62.5%) |
7/8 (87.5%) |
0/8 (0.0%) |
4/8 (50.0%) |
Hard Math (<think>, 4, 512t) |
0/4 (0.0%) |
3/4 (75.0%) |
0/4 (0.0%) |
3/4 (75.0%) |
0/4 (0.0%) |
1/4 (25.0%) |
| Code+Logic (no-think, 4) | 1/4 |
1/4 |
2/4 |
1/4 |
0/4 |
1/4 |
Code+Logic (<think>, 4, 512t) |
1/4 (25.0%) |
4/4 (100.0%) |
1/4 (25.0%) |
4/4 (100.0%) |
0/4 (0.0%) |
3/4 (75.0%) |
| Hard Total (16 problems) | 7/16 (43.8%) |
14/16 (87.5%) |
6/16 (37.5%) |
14/16 (87.5%) |
0/16 (0.0%) |
8/16 (50.0%) |
(Without --mmproj / --embeddings, text-only QAT Q4_0 base decodes at 20.88 / 33.84 / 47.08 tok/s at 2,490 MiB VRAM.)
VoC Adaptive Routing (voc_gate_q40.npz, 11 KB)44 prompts, zero overlap with test): AUROC(Easy vs Hard) = 0.9437, AUROC(Easy+Aleatoric vs Hard) = 0.9417 (Easy mean = -22.30, Aleatoric mean = -18.76, Hard mean = -2.08, TPR = 1.000, FPR = 0.083).RTX 3050 Ti 4 GB, single running server):| Slice | Accuracy | Mean K |
K Split (2/4/8) |
<think> Rate |
Mean Probe | Mean Decode |
|---|---|---|---|---|---|---|
| Easy TR/EN (4) | 4/4 (100%) |
3.50 |
3 / 0 / 1 |
25% |
373 ms |
27.3 tok/s |
| Aleatoric (2) | n/a |
2.00 |
2 / 0 / 0 |
0% |
216 ms |
31.7 tok/s |
| Hard Math (12) | 10/12 (83.3%) |
7.67 |
0 / 1 / 11 |
92% |
1,572 ms |
19.5 tok/s |
| Code+Logic (4) | 4/4 (100%) |
8.00 |
0 / 0 / 4 |
100% |
1,551 ms |
18.3 tok/s |
| Total Scored (20) | 18/20 (90.0%) |
— | — | — | — | — |
--no-mmproj-offload)With official mmproj-gemma-4-26B-BF16.gguf (1.2 GB) kept in system RAM via --no-mmproj-offload, peak VRAM remains 2,724–2,820 / 4,096 MiB (> 1.25 GiB headroom), reading synthetic bar-chart values (5/5 exact) at 17.5 tok/s (K=8) and 42.7 tok/s (K=2, 3.08s wall).
benchmarks/local_ab_adaptive_verify.json)Measured on the same RTX 3050 Ti 4 GB server with gemma4_kat_v1.gguf (code/crte/adaptive_reasoner.py, code/crte/eval_adaptive_verify.py):
Suite A — Budget-Forced Thinking (8 hard <think> problems: 4 Math + 4 Code/Logic):
| Mode | Accuracy | Total Wall | Time-to-Correct | Mean Tokens | Forced-Close |
|---|---|---|---|---|---|
plain_k8_512t |
7/8 (87.5%) |
82.44s |
11.78s |
128.9 |
0% |
budget_k8_180t |
7/8 (87.5%) |
77.24s |
11.03s |
117.2 |
0% |
budget_k4_180t |
7/8 (87.5%) |
53.56s |
7.65s (-35.1%, 1.54×) |
120.2 |
12% |
Suite B — Adaptive Verification (8 unit-tested Python coding problems):
| Mode | Accuracy | Total Wall | Time-to-Correct | Escalated | Forced-Close |
|---|---|---|---|---|---|
plain_k8_single (640t <think>) |
0/8 (0.0%) |
343.80s |
n/a |
0% |
0% |
verify_k4_nothink_to_k8 (K=4 no-think → unittest → K=8 + 280t on fail) |
7/8 (87.5%) |
263.89s (-23.2%) |
37.70s |
50% |
50% |
verify_k4_think160_to_k8 (K=4 160t → unittest → K=8 + 280t on fail) |
6/8 (75.0%) |
291.80s |
48.63s |
38% |
100% |
Baseline & test caveats (explicitly preserved):
- Bounded-budget baseline:
plain_k8_singlescored0/8specifically because unconstrained<|channel>thoughthit the640-token generation cap before closing<channel|>and emitting Python code. This compares bounded-latency consumer workflows, not unlimited-token generation.- Small suites (
n=8each): Controlled engineering checks, not HumanEval/LiveCodeBench claims.- Recorded test-case bug disclosure: In the recorded
local_ab_adaptive_verify.jsonrun,grid_shortest_pathcontained an incorrect expected assertion (12instead of the true BFS distance10). The assertion is fixed to10incode/crte/eval_adaptive_verify.py, while the reported table preserves the unmodified7/8raw measurement without retroactive score inflation.
bf16 on Blackwell 96 GB)120 steps × micro-batch 2 (960 multimodal examples), 311.0s, peak VRAM = 51.0 GiB, mean_lora_B_norm = 0.2337:K=2 Easy NLL: 1.4772 → 1.0002 (-32.3%)K=4 Easy NLL: 0.9697 → 0.8981K=8/4/2 Hard Text NLL: 1.51–1.70 → 0.31–0.36 (-79%..-80%)K=8/4/2 Hard Vision NLL: 1.29–1.38 → 0.06–0.11v1.0.1-moe-topk, commit 498eca1, upstream llama.cpp 5bacb7c868a2bc98682de15f447fc1ce17c9c49c):git clone -b v1.0.1-moe-topk https://github.com/Zwannfrederick/argus.git
git clone https://github.com/ggml-org/llama.cpp.git
git -C llama.cpp checkout 5bacb7c868a2bc98682de15f447fc1ce17c9c49c
git -C llama.cpp apply "$PWD/argus/integrations/llama.cpp/argus.patch"
cmake -S llama.cpp -B llama.cpp/build-cuda -DGGML_CUDA=ON -DCMAKE_BUILD_TYPE=Release
cmake --build llama.cpp/build-cuda --target llama-server -j
gemma-4-26B_q4_0-it.gguf (13.44 GiB) and optionally mmproj-gemma-4-26B-BF16.gguf.ARGUS_AUTO=1 ARGUS_P3_COALESCE=1 ./llama.cpp/build-cuda/bin/llama-server \
-m gemma-4-26B_q4_0-it.gguf \
--lora gemma4_kat_v1.gguf \
--mmproj mmproj-gemma-4-26B-BF16.gguf --no-mmproj-offload \
-c 32768 -ngl 99 -ncmoe 30 -fa on -nkvo -ctk q4_0 -ctv q4_0 \
-np 1 -t 4 -tb 6 -b 512 -ub 512 --load-mode mmap --no-warmup \
--embeddings --pooling last --port 18181
K routing (zero PyTorch, pure NumPy):# Max quality thinking at K=8 (~18-20 tok/s) / Easy at K=2 (~31-38 tok/s)
python3 argus_voc_router.py --url http://127.0.0.1:18181 --voc-dir . --interactive
# Turbo thinking at K=4 (~27-28 tok/s — matched K=8 on our 16-problem Hard suite)
python3 argus_voc_router.py --url http://127.0.0.1:18181 --voc-dir . --think-k 4 --interactive
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained(
"google/gemma-4-26B-A4B-it-qat-q4_0-unquantized",
torch_dtype=torch.bfloat16,
device_map="auto",
)
model = PeftModel.from_pretrained(base_model, "ZwannFrederick/Gemma-4-26B-A4B-QAT-KAT-v1")
All training, calibration, and benchmark scripts are bundled in code/crte/:
code/crte/gemma4_qat_kat.py + code/crte/gemma4_qat_data.pyPYTHONPATH=code python3 -m crte.gemma4_qat_kat \
--model google/gemma-4-26B-A4B-it-qat-q4_0-unquantized \
--steps 120 --micro-batch 2 --grad-accum 4 --out ./out_kat_v1
Q4_0-native self-supervised VoC calibration (0 cloud GPU): code/crte/calibrate_voc_q40.pycode/crte/eval_gemma4_argus_ab.pyARGUS_LLAMA_SERVER=./llama.cpp/build-cuda/bin/llama-server \
ARGUS_QAT_MODEL=./gemma-4-26B_q4_0-it.gguf \
ARGUS_MMPROJ=./mmproj-gemma-4-26B-BF16.gguf \
PYTHONPATH=code python3 -m crte.eval_gemma4_argus_ab --lora ./gemma4_kat_v1.gguf --out ./ab_result.json
~12.25 GiB pinned for 30/30 MoE expert layers) + ≥ 4 GB VRAM. On 16 GB RAM machines, unpinned expert layers will page-fault from SSD and drop to ~1–4 tok/s.20 scored prompts (4 Easy, 12 Hard Math, 4 Code+Logic) plus 2 Aleatoric and 3.2K Needle. Treat these as controlled engineering evidence, not broad MMLU/GPQA claims.<think> 512-token truncation: Part of the Base 0/4 → KAT 3/4 (MathTH) and Base 1/4 → KAT 4/4 (CodeTH) gap comes from Base Gemma 4 exhausting the 512-token cap inside <|channel>thought without closing <channel|>; KAT-LoRA specifically improves concise thinking completion within tight consumer latency budgets.Code+Logic (no-think) K=4 moved 2/4 → 1/4 (-1 item; rises to 4/4 with <think>)./embeddings VoC probe adds ~216–373 ms on short prompts and ~1.55s on ~90-token prompts because SERVER_TASK_TYPE_EMBEDDING currently does not share its prefill KV cache with /v1/chat/completions.mtp-gemma-4-26B-A4B-it.gguf (441 MB, --spec-type draft-mtp -ngld 99 --fit off) on the same RTX 3050 Ti slowed decode by -9.6% (K=8), -18.9% (K=4), and -11.1% (K=2) despite 50–61% acceptance (3,086 MiB VRAM).3.64× the single-token expert reads), which would outweigh accepted draft tokens on a bandwidth-bound DDR4 bus. Real expert routing is skewed/non-uniform, so treat 29.1 / 3.64× as an analytical hypothesis rather than a profiled bus-traffic measurement. By contrast, dynamic moe_top_k directly reduces active expert reads per step.mmproj OOM: Loading mmproj-gemma-4-26B-BF16.gguf onto a 4 GB GPU (3,678 MiB) leaves insufficient room for pp compute buffers (+545 MiB); always pass --no-mmproj-offload on 4 GB GPUs.