Skip to content

gemma4: admit the E4B geometry in the family config; each backend refuses it until it computes it - #1400

Closed
Mirrdhyn wants to merge 1 commit into
ashhart:mainfrom
hygurlabs:e4b-family-config
Closed

Mirrdhyn wants to merge 1 commit into
ashhart:mainfrom
hygurlabs:e4b-family-config

Conversation

@Mirrdhyn

@Mirrdhyn Mirrdhyn commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Part of #1222, first of three stacked PRs for the E-series family parts (A config, B tensor plan, C host per-layer inputs; the converter is separate).

  • config.zig reads and checks the E4B geometry: hidden_size_per_layer_input, vocab_size_per_layer_input, num_kv_shared_layers, attention_k_eq_v: false, sliding_window. New constant e4b, and cacheOwner(): the layer whose cache a shared layer reads (the last sliding or global owner before the shared run, 22 and 23 on E4B).
  • The three refusals move from the config parser to each backend's admission: Config.requireDense(), called by Metal (model.zig) and CUDA (cuda_weights.zig), before a weight is read or the device touched. A backend lifts it when it lands the E-series with its receipts.
  • cuda_config.zig stays the twin of config.zig (the existing test checks they differ only in their first lines).
  • Fixture fixtures/config_e4b.json (text config of the public E4B checkpoint).

Error names change for malformed configs: a 31B or 12B config carrying a per-layer input, shared layers or separate values used to fail with GemmaPerLayerInputsNotServed / GemmaSharedKvNotServed / GemmaKeysNotValues; it now fails with UnsupportedGemmaGeometry (or BadGemmaConfig when the values contradict each other). A real E4B checkpoint still fails with GemmaPerLayerInputsNotServed, now from the backend.

Receipt

  • Environment: this stack against main without it (full gate on c0c7bd2, resumed check on 40c6406, host suites again on eea9dc9); Zig 0.17.0; CUDA on a GB10 (sm_121); Metal on an M4 Max.
  • Exactness (CUDA, served Gemma 4 12B, MLX affine 4/64 from google/gemma-4-12B-it 707f0a3b, drafter -assistant 46d4c6f1, greedy, --parallel 4): token_sha identical before and after on 6 prompts (short to 25,287 tokens), drafted equal to "draft": false on all 6; bench_concurrent.py --alone --serial at 1, 2 and 4 streams, code and chat: 0 unequal, 0 failed, before and after. Resumed equals fresh (--prompt-cache-gib 8): a chat's second turn over a 12,152-token prompt, asked cold (0 cached), then resumed (12,145 cached) twice, with "draft": false, and 4 at once: one token digest across all, before and after.
  • Decode speed (CUDA, bench_openai.py, median tok/s, before / after): code 30.6 / 31.9, chat 66.6 / 67.8; 4 streams aggregate: code 116.3 / 116.2, chat 236.3 / 234.5.
  • Prompt speed (CUDA, cold, tok/s, before / after): 3,182 tokens 2449.7 / 2425.7; 13,142 tokens 2176.9 / 2158.2; 27,110 tokens 1855.4 / 1839.3 (within run-to-run noise).
  • Kernel contract (CUDA, no kernel changed): before and after SUMMARY 340 kernels: 340 pass gates 1-4, 0 fail, 5 known findings; 94 controls: 94 red as planted, 0 missed; 150 limit problems (exit 1 from the 150 limit problems, identical on main).
  • Tests (CUDA host): test, test-kernel-contract, test-golden, fuzz-cortheon, test-cuda-host, test-gemma4-config, the seven test-gemma4-*-host steps, check-native-cuda-host, compile-config-server, test-checkpoint-config: all exit 0 before and after; tf-cuda-test cases of the final gate plus window, window-rows, window-bench gemma: all exit 0. zig fmt --check 0; lean_check.py 433 problems before and after.
  • Tests (Metal): zig build test 0; zig build test test-golden 0, "0 unexpected differences"; test-gemma4-config 0 (59/59 with the stack).
  • Not run: Gemma 4 served on Metal (the 12B checkpoint is not on my M4 Max, and its link is too slow to fetch it today); on Metal the change is the requireDense() call before the device opens, covered by the config tests. tf-cuda-test gemma4-states (needs the 31B and its drafter). The full CUDA gate ran on c0c7bd2; after rebasing on eea9dc9 (no Gemma 4 file touched upstream) the host suites above were rerun, all 0.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. No bits change.
  • No GPU kernel changed; the CUDA SUMMARY line is above.
  • Prompt processing is no slower than the last release.
  • Platforms: CUDA (GB10) served and tested; Metal (M4 Max) tested, not served. Not run on M1 to M3, M5.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths.

@ashhart

ashhart commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Landed on main as 9346b9a, in 1.1.7, with #1401. Thank you!

@ashhart ashhart closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants