vllm.model_executor.models.gemma4_mtp
¶
Inference-only Gemma4 MTP (Multi-Token Prediction) model.
The Gemma4 assistant model is a lightweight decoder that shares KV cache with the target (backbone) model. All assistant decoder layers are KV-shared: they only have Q projections (no K/V projections or norms), and read K/V from the target model's cache at runtime.
Checkpoint layout (gemma4_assistant)::
model.embed_tokens.* -- token embeddings
model.layers.{i}.* -- decoder layers (Q-only attention + MLP)
model.norm.* -- final RMSNorm
pre_projection.* -- Linear(2 * backbone_hidden_size, hidden_size)
post_projection.* -- Linear(hidden_size, backbone_hidden_size)
lm_head.* -- language model head (tied to embed_tokens)
masked_embedding.centroids.* -- centroid projection (when use_ordered_embeddings)
masked_embedding.token_ordering -- token-to-centroid mapping buffer
Classes:
-
Gemma4MTP–Gemma4 Multi-Token Prediction model for speculative decoding.
-
Gemma4MTPAttention–Q-only attention for Gemma4 MTP layers.
-
Gemma4MTPMaskedEmbedder–Sparse logit computation via centroid-based vocabulary masking.
-
Gemma4MultiTokenPredictor–
Gemma4MTP
¶
Bases: Module
Gemma4 Multi-Token Prediction model for speculative decoding.
forward() returns (draft_hidden_states, backbone_hidden_states). The proposer uses draft_hidden_states for compute_logits (via the draft-dim lm_head) and backbone_hidden_states for the hidden-state feedback buffer.
Methods:
-
get_top_tokens–Sparse argmax via centroids masking. Returns token IDs directly.
get_top_tokens(hidden_states)
¶
Sparse argmax via centroids masking. Returns token IDs directly.
Gemma4MTPAttention
¶
Bases: Module
Q-only attention for Gemma4 MTP layers.
K/V come from the target model's KV cache via
kv_sharing_target_layer_name (set by the proposer after
model construction).
Gemma4MTPMaskedEmbedder
¶
Bases: Module
Sparse logit computation via centroid-based vocabulary masking.
Instead of computing logits against the full vocabulary, projects hidden states to centroid scores, selects top-K centroids, and computes logits only for the ~top_k * (vocab_size / num_centroids) tokens belonging to those centroids.
Methods:
-
forward–Full-vocab logits with non-selected positions masked to -inf.
-
get_top_tokens–Sparse argmax — returns vocab token IDs without full-vocab tensor.
Gemma4MultiTokenPredictor
¶
Bases: Module
Methods:
-
forward–Returns (draft_hidden_states, backbone_hidden_states).
forward(input_ids, positions, hidden_states, intermediate_tensors=None, inputs_embeds=None, spec_step_idx=0)
¶
Returns (draft_hidden_states, backbone_hidden_states).
draft_hidden_states: draft-dim, used by compute_logits via lm_head. backbone_hidden_states: backbone-dim, stored in the proposer's hidden-state buffer and fed back as input to the next step.