inference/research
verifiedhigh · 0.90updated 2026-10-03

Gemma 2 2B

dense 2.614B

Fields

id
models/gemma-2-2b
Family
gemma-2
Vendor
Google
Release year
2024
Architecture
dense
Params (B)
2.614
Active params (B)
2.614
Hidden size
2,304
Layers
26
KV heads
4
Head dim
256
GQA ratio
2
Max context
8,192
Context scaling method
native
Activation
gelu_pytorch_tanh
Attention variant
GQA + logit softcapping (attn 50.0, final 30.0) + sliding-window (4096, 5:1 local:global)
KV cache (bytes/token)
106,496
FLOPs per active token
5,230,000,000
Open weights
yes
License
Gemma Terms of Use
notes
Two serving-relevant mechanisms in one config, both ignored by most quick specs. (1) attn_logit_softcapping 50.0 and final_logit_softcapping 30.0: attention logits and output logits are tanh-clamped. This is numerically load-bearing for stability, and kernels that skip the tanh clamp silently diverge from the reference. (2) sliding_window 4096 with a 5:1 local-to-global alternating pattern — every 6th layer is full-attention over the whole 8192 context. head_dim = 256 is stated explicitly in config.json (it is NOT hidden_size/num_heads = 2304/8 = 288), and that oversized head_dim is the whole point of the GQA design here. kv_cache_bytes_per_token = num_layers * num_kv_heads * head_dim * 2 * 2 = 26 * 4 * 256 * 2 * 2 = 106496 bytes/token at bf16. That is 40x Phi-3 mini's 24576 bytes/token on a model with two-thirds the parameters — a 128k-context claim on a Gemma-2-class KV shape would be 12.7 GiB per sequence at the math above, which is why the sliding window matters so much in practice. query_pre_attn_scalar 256 scales queries before the dot product, compensating for the large head_dim. config.json was read from the unsloth/gemma-2-2b mirror because google/gemma-2-2b is license-gated (HTTP 401 unauthenticated); params_b = 2.614 is confirmed against the gated repo's own safetensors metadata (2614341888), so the mirror is faithful. ONNX community ports exist. 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: naive 26*4,096 = 106,496 B/token; effective with local support = (4*4096*c + 22*4096*4096)/c = 16,384 + 369,098,752/c. At this model's own 8,192 max context that is only 1.73x, because w=4096 is half the context - the 5:1 Gemma-2 pattern was designed when 4096 was long context, so the saving is small now and this is the weakest SWA case in the repo. CONTEXT_SCALING_METHOD (native): rope_scaling null at theta 1e4 over 8192.

Notes

Two serving-relevant mechanisms in one config, both ignored by most quick specs. (1) attn_logit_softcapping 50.0 and final_logit_softcapping 30.0: attention logits and output logits are tanh-clamped. This is numerically load-bearing for stability, and kernels that skip the tanh clamp silently diverge from the reference. (2) sliding_window 4096 with a 5:1 local-to-global alternating pattern — every 6th layer is full-attention over the whole 8192 context. head_dim = 256 is stated explicitly in config.json (it is NOT hidden_size/num_heads = 2304/8 = 288), and that oversized head_dim is the whole point of the GQA design here. kv_cache_bytes_per_token = num_layers * num_kv_heads * head_dim * 2 * 2 = 26 * 4 * 256 * 2 * 2 = 106496 bytes/token at bf16. That is 40x Phi-3 mini's 24576 bytes/token on a model with two-thirds the parameters — a 128k-context claim on a Gemma-2-class KV shape would be 12.7 GiB per sequence at the math above, which is why the sliding window matters so much in practice. query_pre_attn_scalar 256 scales queries before the dot product, compensating for the large head_dim. config.json was read from the unsloth/gemma-2-2b mirror because google/gemma-2-2b is license-gated (HTTP 401 unauthenticated); params_b = 2.614 is confirmed against the gated repo's own safetensors metadata (2614341888), so the mirror is faithful. ONNX community ports exist.

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: naive 26*4,096 = 106,496 B/token; effective with local support = (4*4096*c + 22*4096*4096)/c = 16,384 + 369,098,752/c. At this model's own 8,192 max context that is only 1.73x, because w=4096 is half the context - the 5:1 Gemma-2 pattern was designed when 4096 was long context, so the saving is small now and this is the weakest SWA case in the repo.

CONTEXT_SCALING_METHOD (native): rope_scaling null at theta 1e4 over 8192.

Cross-references

This record references no other records — it is a leaf. It is cited by 0.