A Gemma 4 ViT image feature encoder extracted from Google's Gemma 4 E4B-it multimodal language model. This is the native VLM vision encoder with a spatial k×k soft-token pool + √D scale (bit-perfect with the HuggingFace Gemma4VisionModel reference implementation). The architecture is a custom ViT with 2D RoPE, gated MLP (GELU-tanh), RMS normalization on Q/K/V, and a 4-norm sandwich block layout.
Weights were imported directly from the source VLM's vision tower (Gemma 4 E4B-it); outputs match the transformersGemma4VisionModel implementation bit-for-bit on matching inputs.
Gemma 4 expects raw [0, 1]-range pixel tensors — the model maps them internally to [-1, 1] via 2 * (x - 0.5). The pretrained_cfg therefore declares mean=(0, 0, 0) / std=(1, 1, 1) to disable normalization in timm's standard transform pipeline and avoid double-normalization.
The encoder supports NaFlex-style variable-resolution inputs and integrates with timm's NaFlex data pipeline (see timm.data.naflex_loader / --naflex-loader in train.py). Both raw (B, C, H, W) images and pre-patchified (B, N, ...) tensors (plus patch_coord / patch_valid) are accepted — so the same model can be trained or fine-tuned with dynamic batch sizing that preserves native aspect ratios at flexible resolutions, or run at a fixed square input size.