Skip to main content

Module gemma_spec

Module gemma_spec 

Source
Expand description

gemma4 MTP spec-decode: the “gemma4-assistant” drafter (4-layer, Q-only attention over the MAIN model’s KV cache — no draft KV, no trims) + the greedy draft/verify loop.

Wiring verified from llama gemma4-assistant.cpp + llama-model.cpp:2162 (HANDOVER “GEMMA4 MTP DRAFTER — VERIFIED WIRING”): per draft token, x = MAIN tok_embd(token) * sqrt(2816); xh = concat(x, h[2816]) -> pre_proj [5632->1024]; 4 gemma-style blocks whose attention projects Q ONLY and attends the main cache (SWA layers 0..2 -> main layer n-2 = 28 windowed; global layer 3 -> main layer n-1 = 29 full); dense GELU_PAR ffn; final output_norm -> TIED 1024-dim head (no softcap); h_next = post_proj [1024->2816].

Structs§

GemmaDraft
GemmaDraftLayer
TrimAdapt
Serve-time adaptive trim (MEMRA_GEMMA_TRIM_ADAPT=): the static FR trim’s whole loss is coverage escapes — tokens the base emits that the trim can’t propose (guaranteed rejections; the oracle control that injected the exact escapees flipped a -17% cell to +2% at identical acceptance, jsonl 2026-07-19). Every escape self-identifies at serve time: it arrives as a verify CORRECTION token (and its cousins ride in with the prompt), so the head keeps n_spare extra rows and learns them — prompt ids up front, corrections as they land. First miss pays one rejected round; every recurrence after is proposable. Rows are written into the existing device buffers (no realloc — captured graphs keep their baked addresses).