Skip to content

gemma4: admit the 31B's MTP assistant as a drafter - #1385

Merged
ashhart merged 3 commits into
ashhart:mainfrom
ThomasHalwax:pr/gemma4-31b-assistant
Oct 31, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
ThomasHalwax:pr/gemma4-31b-assistant

Conversation

@ThomasHalwax

@ThomasHalwax ThomasHalwax commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1383.

On CUDA, the assistant parser (cuda_assistant_weights.zig) takes either type pair (gemma4_unified_assistant/gemma4_unified_text or gemma4_assistant/gemma4_text) and requires the target's query heads instead of a fixed 16. A mismatched pair is BadDraftConfig, another type UnsupportedAssistantType. The --drafter message names both assistants. Fixture: the 31B assistant's config.json at 627c5ec1; tests admit it against the dense 31B and refuse it against the 12B, and refuse an unknown assistant type, gemma4_assistant over a gemma4_unified_text config and the 31B's config with 16 query heads (the last two are red on main). No forward or kernel change. Metal stays as on main.

Receipts (one GB10, CUDA 13.0, driver 580.173.02; target mlx-community/gemma-4-31B-it-4bit @ 696d436c, assistant @ 627c5ec1; server --context 131072 --parallel 4 --vision --no-thinking):

Assistant No drafter z-lab DFlash
German prose, 16 prompts, T 0.2, one stream 28.3 tok/s 12.2 20.3
Tokens per round (incl. the verified one) 2.83 1 2.06
Decode after a 6k / 24k / 48k / 81k prompt 36.8 / 30.9 / 23.3 / 22.7 12.1 / 11.2 / 10.2 / 9.2 18.6 / 13.0 / 9.0 / 6.9
Cold prefill 6k / 24k / 48k / 81k 7.4 / 32.6 / 79.9 / 168 s 7.2 / 31.8 / 78.4 / 167 s 7.6 / 33.0 / 80.3 / 169 s
  • Drafted equals "draft": false: 16/16 texts identical.
  • 4 concurrent equal solo: 16/16 (77.5 tok/s total).
  • Images with --vision: 8/8.
  • Resumed follow-ups after a 24k prompt and an unrelated 16k prompt in between resume at the kept mark.
  • Measured on the branch's parent at faccd11c; rebased on 40c6406b, the same prompts give identical texts.

Host: zig build test-cuda-host passes (the FAIL CPU reference comparison lines appear on main as well); test-gemma4-cuda-host 31/31; tools/zig/lean_check.py adds no findings over main (433). The CI steps of no-gpu.yml (zig build test, test-kernel-contract, test-golden, test-server-security test-pull-security) and zig fmt --check build.zig zig pass locally on Linux.

Changelog suggestion: Gemma 4 31B takes Google's MTP assistant (google/gemma-4-31B-it-assistant) as --drafter on CUDA (#1383). On a GB10 it decodes German prose at 28.3 tokens/s against 12.2 undrafted and 20.3 with DFlash, with identical tokens.

@ashhart

ashhart commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Thanks @ThomasHalwax for #1383 and the receipts: 28.3 against 12.2 tokens a second with identical texts is a real step for the 31B. The CUDA side reads well. textType pairs each assistant type with its text type, a mismatched pair is BadDraftConfig, taking the query heads from the target still admits the 12B's assistant, and the CUDA forward already sizes everything from c.heads. Your new test is red on main, and the branch merges cleanly onto current main.

  1. Please leave Metal as it is on main in this PR. The same change at zig/src/families/gemma4/assistant_weights.zig:43 and :50 admits the 31B's assistant on Metal too, but it hasn't run on a Mac and no CI has compiled those tests. We only admit what has been run, and Metal's docs still say the 31B takes one drafter (docs/recipes/gemma-4-native.md:93) and the assistant only the 12B's (docs/recipes/gemma-4-12b-native.md:45). So please drop the changes to assistant_weights.zig and zig/src/native/gemma4.zig, and give CUDA the refusals instead, in a test beside cuda_assistant_weights.zig:291: an unknown assistant type, gemma4_assistant over a gemma4_unified_text config, and the 31B's config with 16 query heads against the 31B (the last two are red on main). CUDA has no refusal-by-name test today. We'll open Metal ourselves once we've run the 31B with its assistant on an M5.

Once that's in, we'll run the 31B MLX 4-bit with the assistant on a GB10: drafted == plain, greedy and sampled, concurrent == solo at four streams, images with --vision, decode speed against no drafter and against DFlash, and the 12B with its own assistant against main by token hash.

@ThomasHalwax

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Done in 2db58ff:

  • assistant_weights.zig and zig/src/native/gemma4.zig are back as on main; the PR now touches CUDA only.
  • A refusal test beside the admission tests in cuda_assistant_weights.zig, built from the 31B fixture: an unknown assistant type (UnsupportedAssistantType), gemma4_assistant over a gemma4_unified_text config (BadDraftConfig) and the 31B's config with 16 query heads against the 31B (UnsupportedAssistantGeometry). On main it fails at the second case (UnsupportedAssistantType).

test-gemma4-cuda-host 31/31, the no-gpu.yml steps and zig fmt --check pass locally, lean check adds nothing. The description is updated; the receipts stand, as the CUDA code is unchanged. Metal is yours.

@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thanks @ThomasHalwax, and sorry this sat after your fixes. Both points are answered in 2db58ff: Metal is back as on main, and CUDA refuses assistants by type with a test. We've rebased it onto main (clean) with a changelog line from your suggestion. We don't have the 31B assistant on our GB10s, so it lands on your receipts for the drafted path. We're running the 31B on a GB10 without a drafter, main against this, to confirm nothing else moved. Then it lands.

@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Result, @ThomasHalwax: Gemma 4 31B MLX 4-bit on a GB10 without a drafter, main against this, alternating fresh servers. Prompt tokens are equal to main (0 of 20 rows differ), and the stream sweep is level at 1, 2, 4 and 8 streams (0.0%). Prefill is level from 2k to 32k, and 64k reads 0.3% lower (552 against 550.6 tok/s). The only lines on that path are an error message and a comment, and the assistant parser runs only with --drafter, so that's binary layout, not your change. With your drafted receipts, it's ready. It lands once our Mac gate is back up, after an overnight Xcode update broke it.

ThomasHalwax and others added 3 commits October 31, 2026 12:04
…, with the target's query heads

google/gemma-4-31B-it-assistant has the 12B assistant's tensors, depth and width and no ordered embeddings; it differs
only in its type names (gemma4_assistant / gemma4_text) and in 32 query heads, its target's. Both parsers (CUDA, Metal)
take either type pair and require the target's query heads instead of a fixed 16. Fixture: the 31B assistant's config.
@ashhart
ashhart force-pushed the pr/gemma4-31b-assistant branch from 2db58ff to 66d0fdd Compare October 31, 2026 12:04
@ashhart
ashhart merged commit a4f8cda into ashhart:main Oct 31, 2026
9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thank you @ThomasHalwax. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in 1.2.1, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thanks @ThomasHalwax! Gemma 4 31B on CUDA drafting with Google's MTP assistant is in 1.2.1: https://github.com/ashhart/TensorFold/releases/tag/v1.2.1

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.

Gemma 4 31B: admit Google's MTP assistant (google/gemma-4-31B-it-assistant) as a drafter

2 participants