gemma4: the assistant head as a serial drafter that reads the trunk's cache

Google's Gemma 4 assistant (Gemma4AssistantForCausalLM), merged under
`draft.` by `rad-convert --draft-model`, declared when the container carries
it and the deployment speculates (max_spec > 0):

  x  = pre_projection(concat(E_trunk[tok] * sqrt(n_trunk), h_trunk))
  x  = 4 layers (3 sliding, 1 full): q-only attention over the TRUNK's cache,
       o_proj, plain-gain sandwich norms, GELU ffn, per-layer scalar
  hd = norm(x); logits = the head's own tied table (no soft-cap)
  h' = post_projection(hd), the next round's hidden state

h_trunk is the trunk's final-normed hidden state. Each head layer reads the
last trunk layer of its class (58 sliding, 59 full on the 31B), as vLLM wires
it. The head keeps no cache, so it is declared with rad_drafter_shared_kv:
one row a drafting sequence, every round at the committed position.

TP: q heads row-sharded with the trunk's kv heads; o_proj and down are
column-sharded and all-reduced before their post-norm; projections and norms
replicated; the lm_head vocab-sharded through the ordinary sampler chain.

Declare refuses a head whose kv geometry, window, rotary or vocabulary differs
from the trunk's, and use_ordered_embeddings (centroid masking). The probe
answers draft depth 3 for `--num-speculative-tokens auto`.

arch_test: no head without one or at max_spec 0; shapes, name maps, the
drafter declaration; the issue order of a history pass and a round; the
attention reading trunk layers 10/11 of the 12-layer fixture; TP2 reduces
before each post-norm; a history pass of the wrong shape is refused.
This commit is contained in:
keptn42 committed 2026-10-10 19:15:05 +00:00
1 parent 997e1ae05f
commit 8bde9f9c16
4 files changed
+867 -18

No files matched your search

@@ -10,6 +10,13 @@
# embedding + lm_head are bf16 and are kept as the checkpoint holds them -- a weight no rule
# matches is served in its checkpoint form. A rank-1 weight a pattern happens to match is declined
# by the quantiser and kept as it is, so the norms stay bf16 even under a broad pattern.
#
# With the assistant (draft) head merged in -- add `--draft-model <gemma-4-31B-it-assistant>` --
# its weights are declared as `mtp.*` and no rule below matches them: the head is served bf16 as
# Google ships it (0.9 GB). The patterns are anchored, so `blk.*` never reaches `mtp.blk.*`.
# Its lm_head (`mtp.output.weight`, 0.5 GB, read once a draft round) may be made int8 with
# mtp.output.weight rtn codes=i8 group=128 scale=bf16 clamp=sym
# and the head then reads it through logits_gemm_i8; a draft only proposes, the trunk verifies.
blk.*.attn_q.weight rtn codes=i4 group=128 scale=f16
blk.*.attn_k.weight rtn codes=i4 group=128 scale=f16