Vision encoders: how can image patches join the text?
Text has token embeddings. Could a Vision Transformer (ViT) give images something similar, without fixing their shape or discarding too much detail?
We want to ask a language model about a photograph, but its familiar input is a sequence of token vectors. Could each pixel become a position, or could one vector hold the whole image?
Keep a small piece at each position
Both extremes leave a difficulty: too many positions, or too much information squeezed into one. Try a middle ground: split the picture into patches, then give each patch a learned vector.
The sequence is shorter, but each vector was calculated from its own patch alone. A brown patch could belong to a roof, a branch or an animal. What could tell us which?
Keep track of where a patch came from
Attention could request the missing context, but the same patch projection is used everywhere in the image. How would it distinguish the top-left corner from the bottom-right?
One answer is a learned position vector (coming soon) for each place in the patch grid, added to its content vector. The table learns information about location; it is separate from the weights that recognise patch content.
Reuse the transformer block
Now the patches have content and location. Could the familiar attention and feed-forward layers let them exchange information?
This is ordinary multi-head attention, with one important change from causal text attention: a patch can attend to any patch in the image. The map is full rather than triangular; the complete image is already available.
Let the patch count change
We have drawn an 896 × 896 crop, but the attention weights act on vector width, not the number of patches. Could we keep a larger image instead of resizing it to that shape?
Yes, provided the position scheme and surrounding model support the new grid: doubling both image dimensions gives four times as many patches and 16 times as many attention pairs. Fixed-size crops make training batches, compute and the downstream token budget per crop predictable; they are not a requirement of attention.
Our worked encoder uses a learned 64 × 64 position grid and a standard fixed-crop path. A different grid needs positions too, but those can be interpolated or represented another way; the optional comparison below explores that choice.
Combine patches after they have context
Could we average neighbouring vectors now that they have exchanged information?
Averaging each 4 × 4 group leaves 256 positions, at the cost of some fine detail. Each vector still has 1,152 coordinates; averaging is one compression choice, not a rule for vision encoders.
Make image and text vectors fit together
The text vectors have a different width. Could another learned projection bridge that gap?
These are continuous image representations, often called soft tokens. They can sit among text embeddings; we do not need to turn the image into words first.
Follow the resulting image path
Each step now has a reason: patches keep local detail, attention adds context, pooling shortens the sequence, and projection matches its width to the text.
This worked path belongs to Gemma 3, using a 27-layer SigLIP Vision Transformer (ViT). Extra crops preserve more high-resolution detail, but add positions again. Could we make a similarly useful sequence from sound?
Keep a different image shape or resolution
Resizing every image to a fixed square can discard detail or distort its proportions. Could we keep its aspect ratio and choose a patch grid within a compute budget instead?
A learned position grid can be resampled for the new layout: the NaFlex path of SigLIP2 does this. Alternatively, Pixtral-based encoders use 2D RoPE, rotating queries and keys according to row and column.
These choices can coexist: Qwen3.5 and Kimi’s MoonViT combine learned spatial positions with rotary positions. Variable grids still have a patch budget, and a checkpoint needs training and preprocessing that support the layouts we give it.
Keep the coordinates before learning how to combine them
Averaging merges neighbouring coordinates immediately. Could we retain them separately until learned weights decide how to mix them?
Concatenating a 2 × 2 group turns four vectors into one vector four times as wide, before learned mixing reduces that width. This rearrangement is often called spatial patch merging or pixel unshuffle; unlike averaging, the rearrangement itself discards no coordinates.
Qwen3.5, Llama 4 and C-RADIO in Nemotron use 2 × 2 merging. DeepSeek-V4.1 uses 3 × 3 unshuffle before a two-layer projector; the learned width reduction can still lose information.
Change how the image features are built
The goal was useful image vectors, rather than a particular transformer. Other encoders change how those vectors gain context:
| Choice | What changes | Examples in our model catalogue |
|---|---|---|
| Transformer blocks | Attention exchanges information between image patches; normalisation, feed-forward layers and positional rules vary. | SigLIP, MoonViT, Pixtral, DeepSeek-ViT, Qwen vision |
| Convolutional encoder | Convolutions build a feature hierarchy instead of a stack of self-attention blocks. | MobileNet-V5 in Gemma 3n |
| Convolution and attention | Local pattern processing and attention appear within the same encoder. | LFM3 |
| Restricted and full attention | Some layers connect a smaller neighbourhood; others exchange information more widely. | Perception Encoder in Muse Spark |
| More than the last feature layer | Intermediate image features also feed later processing. | Qwen3-VL-derived WeVisOne |
These encoders can still produce a shorter sequence at the language model’s input width. The diagram above expands the SigLIP example; it does not imply that every vision encoder uses its LayerNorm, GELU, biases or 16-head layout.
Sources and worked example
- Gemma 3 technical report.
- Google’s full SigLIP implementation: learned grid positions, 16 heads of width 72, pre-LayerNorm residual blocks, a 4,304-wide GELU MLP and a final LayerNorm.
- Google’s SigLIP vision configuration: 27 layers, width 1,152, RGB patches of size 14.
- Gemma 3 model implementation: average pooling, RMSNorm, the multimodal projection and image-block attention masks.
- SigLIP position interpolation, SigLIP2 variable-grid positions, Pixtral axial RoPE and Qwen3.5 vision positions and patch merger.
- Vision Transformer and SigLIP.
The worked profiles are Gemma 3 4B, 12B and 27B; the text-only 1B is excluded. All three use the illustrated image path. The picture and learned matrix cells illustrate roles and shapes. One 896-pixel crop produces 4,096 patch positions and 256 pooled positions; image markers and extra crops add sequence positions beyond that count. The resolution comparison is a hypothetical larger crop using the same projection shapes, not a supported Gemma 3 input mode. Pair counts are per head and exclude implementation overhead. The optional position-choice and merging comparisons illustrate proposed alternatives at the selected reference widths; they do not change Gemma 3’s actual learned-grid and averaging path. The position-grid cells are schematic; interpolation does not guarantee accuracy on unseen resolutions. The main diagram follows one image, so it shows bidirectional attention without a decoding KV cache. This article explains input understanding, rather than image generation.