Gemma 4 31B (dense, multimodal)
Fields
models/gemma-4-31bNotes
KV GEOMETRY, NOW DERIVED (was null). Gemma 4 uses TWO head geometries in one stack, so the single-formula field is the sum of two terms, both explicit in config: sliding layers = num_layers_sliding x num_key_value_heads x head_dim x 2 x bytes; full layers = num_layers_full x num_global_key_value_heads x global_head_dim x 2 x bytes. DERIVATION for Gemma 4 31B: 50 sliding layers x 16 kv_heads x 256 head_dim x 2 (K+V) x 2 bytes (bf16) = 819,200 B PLUS 10 full-attention layers x 4 global kv_heads x 512 global_head_dim x 2 x 2 = 81,920 B, TOTAL 901,120 B/token (880.0 KiB). layer_types enumerates the split explicitly (50 sliding_attention + 10 full_attention, full at 0-based indices 5,11,17,23,29,35,41,47,53,59). attention_k_eq_v is true and num_kv_shared_layers is 0, so no layer shares cache with a neighbour. PARAMS: 31.27B is the safetensors weight count including the vision tower. Dense (num_experts is null). Google's doc puts the BF16 footprint at 69.9 GB, SFP8 at 34.9 GB, Q4_0 at 17.5 GB. KV left null for the same reason as the 26B A4B: sliding layers use head_dim 256 with 16 KV heads while global layers use global_head_dim 512 with 4 global KV heads (4*512 = 2048 vs 16*256 = 4096 elements), across 10 global layers of 60. Two geometries, one stack, no single config field to derive from. This is the direct dense-vs-MoE counterpart to the 26B A4B: roughly the same weight count (31.3B vs 25.8B) but 31.3B active per token versus 4B, against the same 256k context and the same hybrid-attention family.
SERVICEABILITY JOIN (added 2026-10-03; the architecture x engine matrix this record was missing, with a citation per cell in docs/13-model-compatibility.md): FAMILY=sliding-window. REQUIRED KERNEL CLASS: a local/windowed attention decode kernel plus per-layer-type cache management. The kernel requirement is not cosmetic: flop/sliding-window-hybrid-attention records that a local layer's decode cost is constant in context (it reads exactly w KV entries) so its arithmetic intensity stays at ~1 flop/byte forever, while the global layers' bytes still grow linearly - the two layer classes have opposite scaling and one kernel must serve both. SUPPORTED BY (cited): vLLM lists sliding attention inside its fallback envelope - 'Attention types: full attention and/or sliding attention' - but ALSO has native rows for the specific SWA architectures: GptOssForCausalLM, Gemma3ForCausalLM, Gemma4ForCausalLM, Olmo3ForCausalLM, GraniteMoeSWAForCausalLM, GraniteSWAForCausalLM [[mdl2-vllm-supported-models-2026-10]]. SGLang's generative table names GPT-OSS as 'hybrid sliding-window-attention MoE model ... with per-layer-type RoPE (YARN on full-attention layers, default on sliding-attention layers) and a softplus per-head attention gate', and lists granite-swash SWA models [[mdl2-sglang-generative-models]]. llama.cpp exposes SWA as first-class KV keys rather than a flag: %%s.attention.sliding_window and %%s.attention.sliding_window_pattern exist as distinct keys per architecture class, alongside SWA-specific width keys, which is direct evidence that SWA changes the cache layout rather than adding an attention flag [[mdl2-llamacpp-arch-class-registry]]. THE PER-CELL CONSEQUENCE: an engine WITHOUT local-attention support does not fail, it silently allocates a full-context cache for every layer. docs/13-model-compatibility.md tabulates this as the KV overpay table; for this model the naive figure in kv_cache_bytes_per_token is the worst case and the effective figure is what the windowed layers actually hold. TWO HARD GATES THAT ARE NOT ABOUT WINDOW SIZE. (1) TensorRT-LLM publishes a per-architecture 'Sliding Window Attention' column and it is NOT uniformly Yes: Yes for DeepseekV4ForCausalLM, Gemma4ForConditionalGeneration, Gemma4UnifiedForConditionalGeneration and Step3p7ForConditionalGeneration, and explicitly No for Qwen3NextForCausalLM, while the DeepSeek-V3/V3.2/GLM/GPT-OSS/Llama-4/Qwen3.5/Kimi-K3/Nemotron-H rows read N/A [[mdl2-trtllm-supported-models]]. (2) On B200 with vLLM 0.23.1rc1.dev843 + flashinfer-python 0.6.14, a 50-of-60-layer SWA Gemma-4 checkpoint with --kv-cache-dtype fp8_e4m3 and MTP spec-decode (k=7) produces fluent output containing sporadic wrong tokens and short repetition loops once seq_len passes the 1024-token window, because flashinfer's trtllm spec-as-decode kernel mis-computes sliding-window attention for BF16-Q + FP8-KV at certain seq_len/page alignments and vLLM's scale bookkeeping double-applies k/v scales - gotcha-flashinfer-bf16q-fp8kv-spec-decode-corrupts-swa, severity BLOCKER. FP8-Q + spec is clean; BF16-Q + no spec is clean; either drop quantized KV, drop spec decode, or drop the disable_flashinfer_q_quantization flag. This is the cleanest statement in the repo that quantized KV and speculative decoding are not independently safe on an SWA model. (3) FlashInfer also rejects large head sizes at engine init, which is a separate SM120 gap from the page-block one: head_size not supported for gemma-4-31b-it's head_dim 256 / global_head_dim 512 on RTX PRO 6000 [[flashinfer-rejects-large-head-dim]]. (4) On Hopper, vLLM 0.30.0's vllm_flash_attn silently ignores num_splits on SM90, costing 48% per-token decode at batch 1 for Gemma-4 26B-A4B-it global layers (1 query token, 2 KV heads, 2 of an H100's 132 SMs with work), with TRITON_ATTN recovering ~70% [[fa4-num-splits-ignored-sm90]]. (5) vLLM's own scheduler granularity interacts with SWA groups: issue #53786 asks for fine-grained prefix hits for sliding-window groups, and hybrid reconciliation already caps the combined hit at the shorter boundary [[eagle-prefix-cache-last-block-drop]]. (6) On Apple Silicon the class is a cache-CLASS problem, not a kernel problem: mlx-lm's sliding-window layers use RotatingKVCache, which had no quantized implementation, so --kv-bits passes a hasattr presence check and raises NotImplementedError on the first request instead of at startup; the fix (PR 1584) adds RotatingQuantizedKVCache, and the commonly-recommended monkeypatch silently gives up the max_kv_size window bound and yields an unbounded cache [[mlx-kv-bits-crashes-on-first-request-for-hybrid-attention]] [[mdl2-mlxlm-pr1584-rotating-quantized-kv]]. KV OVERPAY NOT COMPUTABLE FROM THIS RECORD for the same reason (global_head_dim 512 with 4 global KV heads against local head_dim 256 with 16). This is the exact checkpoint named in the FlashInfer head_size rejection, and it also appears in the SWA spec-decode corruption record at 50 of 60 layers SWA with window 1024 on B200 [[flashinfer-bf16q-fp8kv-spec-decode-corrupts-swa]] [[flashinfer-rejects-large-head-dim]]. Note TRT-LLM's matrix records KV Cache Reuse = No for both Gemma 4 rows even though the architecture is supported - so an engine that supports the model may still refuse to reuse its KV [[mdl2-trtllm-supported-models]].
CONTEXT_SCALING_METHOD (native): SCHEME RECLASSIFIED (2026-10-04): was 'per-layer-type rope' read as a scaling method. per-layer-type rope_parameters with no factor; 262144 reached natively.
LAYER LAYOUT (gemma-4-31b): layer_types read verbatim from config, one entry per layer; attention_layer_indices are the 0-based positions of the full-attention entries.
Cross-references
This record references no other records — it is a leaf. It is cited by 2.