Chapter 2: Vision Encoders
Explore the vision encoders that power modern VLMs: from convolutional feature extractors to Vision Transformers, CLIP, SigLIP, DINOv2, and scaled architectures like InternViT. Understand how each encodes images into the feature representations that language models reason over.
- Topics
- 7
- Demo
- 1
- Videos
- 3
- Min read
- 48
Chapter Overview
The vision encoder is the first component in any VLM pipeline. Its job is to transform raw pixel data---a dense 3D tensor of RGB values---into a sequence of high-dimensional feature vectors that capture the semantic content of the image. The quality of these visual features determines the upper bound of what the entire VLM can perceive and reason about.
The evolution of vision encoders mirrors the broader history of computer vision:
-
Convolutional Neural Networks (CNNs): ResNet, EfficientNet, and their variants dominated from 2015 to 2020. They produce hierarchical feature maps through learned convolutional filters, capturing increasingly abstract patterns at each layer.
-
Vision Transformers (ViT): Dosovitskiy et al. (2020) showed that the same transformer architecture used for language could process images by treating image patches as tokens. ViTs have largely replaced CNNs as the standard vision backbone.
-
Contrastively-trained encoders: CLIP (2021) and SigLIP (2023) train ViTs to produce features aligned with text embeddings, creating a shared vision-language representation space. These are the most common encoders in modern VLMs.
-
Self-supervised encoders: DINOv2 (2023) trains ViTs without any text supervision, producing rich visual features through self-distillation. These features excel at dense prediction tasks.
-
Scaled encoders: InternViT-6B (2024) pushes the parameter count to 6 billion, demonstrating that scaling vision encoders improves VLM performance, analogous to scaling laws for LLMs.
The key trade-offs in choosing a vision encoder are:
- Feature quality: How much semantic information is captured per patch token?
- Resolution handling: Can the encoder process high-resolution images without quadratic cost explosion?
- Alignment to language: Are the features already in a space compatible with text representations?
- Computational cost: How many FLOPs per image, and how many output tokens?
where is the number of patches for image resolution and patch size .
Chapter Roadmap
Click any topic to jump in
CNN Feature Extractors
How convolutional networks extract hierarchical visual features — the starting point before transformers.
Vision Transformer (ViT)
Splitting images into patches and processing them with self-attention — the architecture that replaced CNNs for VLMs.
Contrastive, sigmoid contrastive, and self-supervised
CLIP Encoder
Contrastive pre-training aligns vision features with language — the most common VLM backbone.
SigLIP
Sigmoid loss removes the need for global batch normalization — simpler and more scalable than CLIP.
DINOv2
Self-distillation without labels produces rich spatial features — complementary to contrastive encoders.
InternViT & Scaling
Scaling vision encoders to 6B parameters with dynamic resolution — pushing the frontier of visual understanding.
Choosing an Encoder
Frozen vs fine-tuned, resolution vs tokens, feature granularity — how to pick the right encoder for your VLM.
Topics
7 topics in this chapter
An LLM consumes a sequence of vectors, but a photograph arrives as a dense grid of RGB intensities with no notion of a token, and nothing in the language model knows what to do with it. The chapter introduction framed the vision encoder as the component that closes that gap, and for roughly five years the only serious answer was a convolutional network. Before you can judge the Vision Transformer that follows, you need a concrete picture of what it displaced: how stacked convolutions build a hierarchy from edges to textures to whole objects, what a feature map of shape actually contains, and how that tensor gets flattened into something an LLM can read. The order here is deliberate. First the mechanics of CNN backbones and their output shapes, then the specific limitations that pushed the field elsewhere: local receptive fields, fixed resolution, tokens as an afterthought, no text alignment, and spatial precision traded away. This is not archaeology. Region-based CNN features powered the first generation of VQA systems, and hybrid designs still borrow convolutional stems today.
In this topic
- 1CNNs as Vision Backbones
- 2Limitations of CNNs for VLMs
CNNs as Vision Backbones
A CNN processes an image through a series of convolutional layers, each applying learnable filters that detect patterns at increasing levels of abstraction:
- Early layers: Detect edges, textures, and color gradients (local patterns)
- Middle layers: Detect parts of objects (eyes, wheels, windows)
- Deep layers: Detect entire objects and scenes (faces, cars, rooms)
The output of a CNN backbone is a feature map: a 3D tensor of shape where is the number of feature channels, and are the spatially downsampled dimensions. For ResNet-50 processing a image, the final feature map is ---2048 channels at spatial resolution.
For VLMs, this feature map can be flattened into a sequence of tokens of dimension 2048, then projected into the LLM's embedding space.
The feature map dimension follows while spatial extent shrinks as . The total information budget per layer stays roughly constant: . This means no information is created or destroyed — it is merely re-encoded from spatial to channel dimensions.
A ResNet-50 backbone produces a feature map of shape (2048, 7, 7) for a 224x224 input image. How does this compare to a ViT-L/14 processing the same image?
Limitations of CNNs for VLMs
While CNNs remain useful in some contexts, they have fundamental limitations as VLM encoders:
-
Limited receptive field: Each CNN feature only captures a local region. Global context requires very deep stacking of layers, making it indirect.
-
Fixed spatial resolution: The feature map resolution is determined by the architecture. Changing input resolution requires interpolation or architectural changes.
-
No built-in token sequence: LLMs expect a sequence of tokens. Converting CNN feature maps to tokens is an afterthought rather than a native design.
-
No text alignment: CNNs are typically pre-trained on ImageNet classification, which provides category-level understanding but not the rich semantic features learned through text-aligned training (CLIP).
-
Translation equivariance, not invariance: Convolutions detect patterns regardless of position, which is useful for classification but means spatial information is partially lost---problematic for grounding tasks.
The effective receptive field (ERF) of a CNN grows as with depth , not as the theoretical receptive field suggests. After 50 layers of convolutions the ERF covers roughly of the image, meaning deep CNN features are still largely local. Self-attention achieves a global receptive field ( attention matrix) in a single layer.
Why did Bottom-Up Top-Down Attention (Anderson et al., 2018)---one of the most successful early VLM approaches---use Faster R-CNN instead of a standard ResNet classifier?
Theory Exercise
Problem:
Explain why Vision Transformers replaced CNNs as the dominant vision encoder in VLMs despite CNNs having lower computational cost and decades of optimization. Identify at least three architectural properties of ViTs that make them inherently better suited for the VLM pipeline.
Hints:
- Consider how self-attention creates global receptive fields vs. local convolutions
- Think about how ViT outputs naturally map to the token-based interface of LLMs
- Consider the alignment between ViT training objectives (CLIP) and VLM requirements
Related Problems on PixelBank
A ResNet-50 hands you 49 coarse tokens whose receptive fields are local and whose spatial detail was traded away for channel depth, and squeezing global context out of it means stacking layers until the effective receptive field grudgingly widens. The previous topic, Convolutional Feature Extractors, ended on exactly that limitation. The Vision Transformer answers it by refusing to treat images as a special case at all: cut the picture into fixed-size patches, project each one to a vector, and run the same self-attention stack that already worked for text, so every patch sees every other patch in the very first layer. The arc follows the data through the model. First patch embedding, where becomes tokens and grows quadratically with resolution. Then self-attention over those patches and its price. Then the CLS token versus the full patch sequence, a choice every VLM must make. Finally positional encodings, the piece you interpolate whenever you run an encoder at a resolution it was never pre-trained on.
In this topic
- 1Patch Embedding
- 2Self-Attention on Image Patches
- 3CLS Token and Feature Aggregation
- 4Positional Encoding Strategies
Patch Embedding
ViT converts an image into a sequence of tokens through three steps:
-
Patchification: The image is divided into non-overlapping patches of size .
-
Linear projection: Each patch is flattened and multiplied by a learnable embedding matrix to produce a -dimensional token.
-
Positional encoding: A learnable positional embedding is added to encode spatial location. A special token is prepended for global representation.
The result is a sequence of tokens, each of dimension , that the transformer layers process with self-attention.
Resolution scaling: For a ViT, a image produces tokens, while a image produces tokens. This quadratic scaling in token count is a key consideration for VLMs.
The embedding matrix is equivalent to a convolution with kernel size stride . In frequency terms, the patch projection acts as a low-pass filter with cutoff wavelength pixels (Nyquist limit). Halving the patch size doubles the spatial bandwidth and quadruples the token count: .
For ViT-B/16 (patch size 16, embedding dim 768) processing a 384x384 image: (a) How many patch tokens? (b) What is the embedding matrix size? (c) Total embedding parameters?
Self-Attention on Image Patches
After patch embedding, the token sequence passes through transformer layers, each consisting of multi-head self-attention (MHSA) and a feed-forward network (FFN):
In self-attention, each patch token computes queries (), keys (), and values () through linear projections. The attention score between patches and measures their relevance: . Each patch's output is a weighted sum of all patches' values, with weights determined by attention scores.
With attention heads, each head can learn different types of relationships (e.g., spatial proximity, color similarity, semantic similarity), and their outputs are concatenated.
Computational cost: Self-attention scales as where is the number of patches. For a 224px image with 256 patches, this is manageable. For a 1344px image with 9,216 patches, the cost becomes attention scores per layer---a significant bottleneck.
Attention complexity is where . Doubling resolution at fixed quadruples , making attention cost scale as the fourth power of resolution: . This quartic scaling is the fundamental reason VLMs must use token compression or tiling for high-resolution inputs.
ViT-L has 24 transformer layers with 16 attention heads and d=1024. For an input of 576 tokens (384x384 image, patch size 14), how many total attention computations are performed?
CLS Token and Feature Aggregation
ViTs offer two strategies for producing a global image representation:
-
CLS token: A special learnable token prepended to the patch sequence. Through self-attention, it aggregates information from all patches across all layers. The final CLS token's hidden state serves as a global image embedding.
-
Global Average Pooling (GAP): Average all patch token outputs to produce a single vector. Eliminates the need for a special token.
For VLMs, neither approach is typically used in isolation. Instead, VLMs use all patch tokens as visual input to the language model, because the LLM needs fine-grained spatial information to answer questions like "What color is the object on the left?" The CLS token may be included as an additional summary token, but the patch tokens are essential.
Some VLMs (BLIP-2, Flamingo) use only a subset of patch tokens or compress them through a bridge module to reduce the sequence length for the LLM.
The CLS token acts as a rank-1 bottleneck: it projects the full patch matrix into a single -dimensional vector, discarding at least degrees of freedom. For and , this means retaining at most of the spatial information, which is why VLMs prefer the full patch sequence.
Why do VLMs typically pass ALL patch tokens to the LLM rather than just the CLS token? Doesn't the CLS token already contain a summary of the entire image?
Positional Encoding Strategies
Since self-attention is permutation-invariant (it treats the input as a set, not a sequence), positional information must be explicitly injected. ViT uses learnable positional embeddings---a matrix that is added to the token embeddings.
Types of positional encoding in vision encoders:
-
1D learnable (original ViT): Each of the positions gets a unique learned vector. The model must learn 2D spatial structure from data.
-
2D sinusoidal: Separate sine/cosine encodings for row and column positions, concatenated. Encodes 2D structure explicitly.
-
Rotary Position Embedding (RoPE): Applied to queries and keys in attention, encodes relative distances. Used in newer vision encoders for better resolution generalization.
Resolution transfer: When fine-tuning at a different resolution than pre-training, the number of patches changes. Positional embeddings are typically interpolated (bicubic) to the new grid size. This works well in practice but introduces a small performance drop at very different resolutions.
Learned 1D positional embeddings implicitly encode a 2D grid: the cosine similarity between positions and decays with Manhattan distance. Bicubic interpolation to a new grid works because the learned embeddings are smooth in 2D — nearby positions have similar vectors, so intermediate values are well-approximated by polynomial interpolation.
A ViT is pre-trained at 224x224 resolution (16x16 = 256 patches with p=14). You want to use it at 448x448 (32x32 = 1024 patches). How do you handle the positional embeddings?
Theory Exercise
Problem:
ViT-L/14 produces 256 patch tokens for a 224x224 image. A user submits a 1024x1024 image. Calculate: (a) the number of tokens, (b) the self-attention FLOPs relative to 224x224, and (c) propose two strategies to handle this without exploding compute.
Hints:
- Token count scales quadratically with image dimension when patch size is fixed
- Self-attention FLOPs scale as O(N^2), so the total scaling is quartic in image dimension
- Think about both pre-processing (resize, tile) and architectural (token merging, windowed attention) solutions
The Vision Transformer from the previous topic is an architecture, not a set of weights, and what you train it on turns out to matter more than the layer count. Train a ViT on ImageNet labels and every image collapses toward one of a thousand category names; a VLM asked about a weathered red door, a handwritten sign, or the mood of a scene has nothing to work with. CLIP dropped labels entirely and learned from 400 million image-text pairs scraped from the web, pulling matched images and captions together in a shared embedding space. That single choice is why a CLIP ViT, rather than a classification ViT, sits inside most open-source VLMs. The topic starts with the contrastive objective itself and the reason batch size is load-bearing rather than an implementation detail. It then pins down ViT-L/14 concretely, the configuration you will actually load, before asking why these features transfer so well: language alignment, semantic breadth, compositionality, and the fine-grained spatial precision that the objective quietly gives up.
In this topic
- 1Contrastive Pre-Training Objective
- 2CLIP ViT-L/14: The Standard Backbone
- 3Why CLIP Features Work for VLMs
Contrastive Pre-Training Objective
CLIP trains a vision encoder (ViT) and a text encoder (Transformer) jointly on image-text pairs. For a batch of pairs, the training objective maximizes the cosine similarity between matching image-text pairs while minimizing it for non-matching pairs.
The loss is symmetric: , where classifies images to texts and classifies texts to images.
The temperature parameter (learned, typically initialized to 0.07) controls the sharpness of the distribution. Lower makes the loss more sensitive to small similarity differences.
Training scale: CLIP was trained on 400M image-text pairs (WebImageText dataset) for 32 epochs with batch size 32,768. The large batch size is critical because each batch provides negative examples per sample.
Cosine similarity constrains embeddings to the unit hypersphere . The capacity grows exponentially with dimension: in , roughly nearly-orthogonal vectors can coexist. This means CLIP can encode an astronomically large number of distinct concepts, limited not by geometry but by the quality of training data.
Why does CLIP need such large batch sizes (32,768)? What happens with a batch size of 32?
CLIP ViT-L/14: The Standard Backbone
CLIP ViT-L/14 has become the de facto standard vision encoder for open-source VLMs. Its specific configuration:
| Parameter | Value |
|---|---|
| Architecture | ViT-Large |
| Patch size | 14x14 |
| Hidden dim | 1024 |
| Layers | 24 |
| Heads | 16 |
| Parameters | 304M |
| Training data | 400M image-text pairs |
| Resolution | 224x224 (336x336 with fine-tuning) |
Feature properties:
- Output: 257 tokens (1 CLS + 256 patches) at 224x224
- CLS token: Global image representation, used for retrieval
- Patch tokens: Local features, used by VLMs for detailed reasoning
- Features are normalized (unit vectors on the hypersphere)
- Features are aligned with CLIP text encoder's output space
Used by: LLaVA, LLaVA-NeXT, ShareGPT4V, Cambrian, and dozens of other VLMs.
At 336px, token count is versus at 224px — a increase. The LLM attention cost scales quadratically in sequence length, so the total VLM cost increase is closer to , not . This quadratic penalty is why resolution upgrades have diminishing returns for fixed compute.
LLaVA-1.5 uses CLIP ViT-L/14 at 336x336 resolution (up from 224x224). How does this change affect the visual features and VLM performance?
Why CLIP Features Work for VLMs
CLIP's features are particularly effective for VLMs because of three key properties:
-
Language alignment: CLIP features live in the same embedding space as text. An image of a dog and the text "a dog" produce similar vectors. This means the bridge module only needs to handle dimensional transformation, not conceptual alignment.
-
Semantic richness: Trained on 400M diverse image-text pairs (not just ImageNet's 1,000 categories), CLIP features encode concepts far beyond object categories: actions, attributes, scenes, text in images, emotions, styles, and abstract concepts.
-
Compositional understanding: Because training captions describe compositions ("a red car next to a blue house"), CLIP learns to encode visual compositions, not just individual objects. This compositional understanding transfers to VLMs.
Limitation: CLIP's contrastive objective optimizes for global image-text matching, which may not fully preserve fine-grained spatial information. Patch-level features are useful but not as spatially precise as features from models trained with dense objectives (like DINOv2).
CLIP's contrastive loss maximizes — the mutual information between vision and text representations — across the training set. This means CLIP features retain exactly the visual information that co-varies with language, discarding texture noise and imaging artifacts. The bridge module's job reduces to a dimensionality transform rather than a full semantic realignment.
A VLM built on CLIP ViT-L can describe images fluently but struggles with precise counting ('How many apples are there?'). Why might CLIP features be suboptimal for counting, and what could help?
Theory Exercise
Problem:
CLIP was trained with symmetric contrastive loss (both image-to-text and text-to-image). Some researchers have proposed asymmetric variants where the image encoder receives stronger gradients than the text encoder. Analyze: (1) Why might asymmetric training help VLMs? (2) What could go wrong? (3) Design an experiment to test this hypothesis.
Hints:
- Think about which encoder is more important for the downstream VLM task
- Consider that the text encoder is often discarded (only the vision encoder is used in VLMs)
- Think about how gradient flow affects what the vision encoder learns to represent
CLIP's softmax carries a hidden cost you only feel when you try to reproduce it. Because the denominator sums over every candidate in the batch, each score is coupled to all the others, so training demands both an enormous batch (32,768 in the original recipe) and an all-reduce of the full similarity matrix across every GPU on every step. The previous topic left you with an encoder you can download but an objective you probably cannot afford to rerun. SigLIP changes one thing: score each image-text pair on its own with a sigmoid, asking whether these two match rather than which of 32,768 captions is the right one. The pairs decouple, the all-reduce disappears, and modest batches stop being a handicap. The topic works outward from that loss. First the sigmoid objective and its gradient, where the entire argument lives; then SO400M, the shape-optimized 400M checkpoint that ships inside PaliGemma and Idefics2; and finally the practical question of which of the two encoders to reach for on a given project.
In this topic
- 1Sigmoid Contrastive Loss
- 2SigLIP-SO400M Architecture
- 3SigLIP vs. CLIP: When to Choose Which
Sigmoid Contrastive Loss
where , indicates matching pairs, and is the sigmoid function.
CLIP's softmax loss treats each image as an -way classification problem: "which of the texts matches this image?" SigLIP instead treats each image-text pair independently: "does this specific image match this specific text?" This is a binary classification problem for each of the pairs in the batch.
Key advantages over CLIP's softmax:
-
No global normalization: Softmax requires computing scores across the entire batch (global communication). Sigmoid computes each pair independently, enabling efficient distributed training.
-
Better batch scaling: CLIP's softmax benefits from very large batches (32K) because more negatives = harder classification. SigLIP's sigmoid works well with smaller batches because each pair provides an independent learning signal.
-
Smoother gradients: Softmax can produce very sharp gradients for hard negatives, causing training instability. Sigmoid provides more uniform gradients.
-
Learnable bias: The bias term and temperature are learnable, allowing the model to calibrate its confidence.
The softmax denominator couples all gradients in a row — changing any single score changes all probabilities via the partition function. The sigmoid decouples pairs completely: depends only on . This makes SigLIP embarrassingly parallel across GPUs, eliminating the all-reduce bottleneck that limits CLIP's distributed scaling.
For a batch of B=4 image-text pairs, CLIP computes a 4x4 softmax loss (4+4=8 cross-entropy terms). SigLIP computes 4x4=16 binary cross-entropy terms. How does the gradient computation differ?
SigLIP-SO400M Architecture
SigLIP-SO400M (Shape-Optimized, 400M parameters) is the most commonly used SigLIP variant in modern VLMs. It was trained on WebLI (a curated web-scale dataset) with the sigmoid loss.
Key specifications:
- Vision encoder: ViT with ~400M parameters
- Patch size: 14
- Hidden dimension: 1152
- Layers: 27
- Native resolution: 384x384 (producing 729 tokens)
Used in:
- PaliGemma (Google)
- LLaVA-OneVision
- InternVL (as one of the encoder options)
- Idefics2 (HuggingFace)
SigLIP-SO400M consistently outperforms CLIP ViT-L/14 (304M) on VLM benchmarks, likely due to both the sigmoid loss and the larger model size (400M vs. 304M parameters).
The hidden dimension increase from (CLIP) to (SigLIP-SO400M) gives more parameters per attention layer. Combined with 27 vs 24 layers, the total encoder has more capacity per layer and more total depth-capacity, explaining the consistent +1-3% benchmark improvements.
SigLIP-SO400M has 1152-dim embeddings and 729 tokens at 384x384. A VLM using Llama-3-8B (4096-dim) needs to bridge this. Calculate the bridge dimensions and compare to CLIP ViT-L.
SigLIP vs. CLIP: When to Choose Which
The choice between SigLIP and CLIP as a VLM vision encoder depends on several factors:
Choose SigLIP when:
- You need a larger vision encoder (SO400M > ViT-L/304M)
- Training your own CLIP-like model at scale (sigmoid loss is easier to distribute)
- Building a VLM that will be fine-tuned end-to-end (smoother gradients)
Choose CLIP when:
- Using an existing CLIP-based pipeline (LLaVA, etc.)
- You need the extensive CLIP ecosystem (pre-computed features, fine-tuned variants)
- Model size is constrained (CLIP ViT-B/16 at 86M is much smaller than SigLIP-SO400M)
In practice:
- Both produce features of similar quality for VLMs
- SigLIP has a slight edge on most benchmarks (+1-3%)
- The specific VLM training recipe (data, bridge design, LLM) matters more than the vision encoder choice
- Modern VLMs increasingly default to SigLIP for new projects
The gradient variance of softmax loss scales as (variance reduction through averaging over negatives), while sigmoid loss variance scales as (averaging over pairs). For , sigmoid has lower gradient variance, directly translating to more stable optimization and less sensitivity to learning rate selection.
A research lab wants to train a CLIP-like model on 2 billion proprietary medical image-text pairs distributed across 256 GPUs. Should they use softmax (CLIP) or sigmoid (SigLIP) loss?
Theory Exercise
Problem:
SigLIP's loss function treats each of the B^2 pairs in a batch independently. This means there are B matching pairs and B^2 - B non-matching pairs. For B=1024, the ratio is 1024:1047552 (about 1:1023). Analyze: (1) Does this class imbalance affect training? (2) How does it compare to CLIP's implicit handling of negatives? (3) Propose a modification to address any issues.
Hints:
- Think about the gradient magnitude from positive vs. negative pairs
- Consider how CLIP's softmax naturally handles the ratio via normalization
- Think about focal loss or other techniques for handling class imbalance
Both encoders you have met so far land in the same narrow band: CLIP ViT-L at 304M parameters, SigLIP-SO400M at 400M. Meanwhile the language model beside them grew from 7B to 13B to 70B, and almost nobody asked whether the vision side was the thing holding the system back. If the encoder cannot resolve the small print on a form or separate two overlapping objects, no amount of LLM scale recovers that detail, because it was never encoded in the first place. InternViT-6B is the experiment that tests the assumption, pushing a vision encoder to 6 billion parameters, roughly twenty times CLIP ViT-L. The topic builds the case in three steps. First the architecture itself, and what 48 layers at 3200 dimensions buys you per patch. Then dynamic resolution and aspect-ratio handling, because capacity is wasted if a letter-sized document gets squashed into a square. Finally the scaling-law picture: parameters and resolution have to grow together, which is the finding that should change how you budget a VLM.
In this topic
- 1InternViT-6B Architecture
- 2Dynamic Resolution and Aspect Ratio Handling
- 3Scaling Laws for Vision Encoders
InternViT-6B Architecture
InternViT-6B is a Vision Transformer with 6 billion parameters, trained with both contrastive (CLIP-like) and generative objectives. Its scale dwarfs conventional vision encoders:
| Model | Params | Layers | Hidden Dim | Heads |
|---|---|---|---|---|
| CLIP ViT-L/14 | 304M | 24 | 1024 | 16 |
| SigLIP-SO400M | 400M | 27 | 1152 | 16 |
| InternViT-6B | 5,902M | 48 | 3200 | 25 |
InternViT-6B has nearly 20x more parameters than CLIP ViT-L. This scale enables:
- Richer per-patch features (3200-dim vs. 1024-dim)
- More transformer layers for deeper contextual processing
- Better fine-grained understanding (OCR, small objects, dense scenes)
Training: Progressive training at multiple resolutions (224 384 448), with a custom dynamic resolution strategy that handles arbitrary aspect ratios.
With 48 layers and , the total self-attention FLOP count per image at 448px is — about that of CLIP ViT-L. The per-head dimension of matches the value used in Llama-2-70B, suggesting a converged optimal head size across modalities.
InternViT-6B uses 3200-dim hidden size with 25 attention heads. What is the per-head dimension, and how does this compare to standard ViTs?
Dynamic Resolution and Aspect Ratio Handling
Real-world images come in diverse resolutions and aspect ratios. A naive approach (resize to fixed square) distorts content and loses information. Modern scaled vision encoders handle this through dynamic resolution strategies:
-
Padding: Resize the shorter side to the target, pad the longer side with zeros. Preserves aspect ratio but wastes computation on padding.
-
Sub-image tiling (InternVL, LLaVA-NeXT): Split the image into tiles that fit the encoder's native resolution. A 1280x720 image might become 3 tiles of 448x448 (overlapping) plus a 448x448 downsampled thumbnail.
-
NaFlex (SigLIP2): Dynamically adjust the number of patches based on image content, producing a variable-length token sequence.
Why this matters for VLMs: Document images, screenshots, and photographs have very different aspect ratios. A letter-sized document (8.5:11) contains critical text that would be illegible if squeezed into a 1:1 square.
For an image of height and width , the optimal tiling minimizes aspect-ratio distortion: . The total token count is where is the tile size, giving a linear-in-tiles (not quadratic-in-resolution) scaling of compute — the key insight that makes high-resolution processing tractable.
A user uploads a 3000x2000 pixel photograph to a VLM with InternViT-6B (max resolution 448x448 per tile, max 12 tiles). How is the image processed?
Scaling Laws for Vision Encoders
The success of InternViT-6B suggests that vision encoder scaling laws exist, similar to those for LLMs. Empirical observations:
-
More parameters = better features: InternViT-6B produces richer per-token features than ViT-L, leading to better VLM performance across all benchmarks.
-
Diminishing returns at fixed resolution: Scaling the encoder while keeping resolution fixed shows diminishing improvements. The bottleneck shifts to the number of patches (information available to encode).
-
Resolution and parameters must co-scale: The best results come from increasing both resolution (more patches) and encoder size (richer features per patch) simultaneously.
-
Vision encoder scaling is underexplored: Most VLM research scales the LLM (7B 13B 70B) while keeping the vision encoder fixed. InternVL showed that allocating more parameters to vision has outsized benefits.
Implication: The optimal VLM may have a much larger vision encoder than current designs. If LLMs benefit from 70B+ parameters, there is no reason vision encoders should stop at 6B.
Empirically, vision encoder performance scales as , where both terms contribute independently. Doubling parameters at fixed resolution gives improvement, while doubling resolution (quadrupling tokens) gives . When , resolution scaling dominates — explaining why InternVL co-scales both.
A VLM has two configurations: (A) InternViT-6B + Llama-7B = 13B total, (B) CLIP ViT-L-304M + Llama-13B = 13.3B total. Same total params. Which performs better on visual tasks?
Theory Exercise
Problem:
Design a scaling experiment to determine the optimal parameter allocation between vision encoder and LLM for a fixed total compute budget. Specify: (1) the configurations to test, (2) the benchmarks to evaluate, (3) how you would control for confounding variables, and (4) what outcome would change current VLM design practices.
Hints:
- Consider at least 5 configurations with different vision:LLM parameter ratios
- Include benchmarks that stress-test vision (OCR, spatial) and reasoning (MMMU) separately
- Think about confounding variables: training data quality, bridge design, training recipe
Related Problems on PixelBank
CLIP and SigLIP differ in their loss functions, but they share an assumption: that captions are the supervision signal. That assumption carries a cost the CLIP topic already exposed. A model trained to match "three apples" against a photograph never has to represent each apple separately, so counting, part identification, and depth ordering stay weak no matter how the contrastive loss is written, and captions simply do not mention most of what an image contains. DINOv2 removes text from the picture entirely and learns from the image alone, using a student-teacher setup in which a student seeing small local crops must reproduce the output of a teacher seeing the whole image. Predicting global structure from a patch of fur is what forces patch-level features to become genuinely informative. The topic covers the self-distillation machinery first, including the EMA teacher, multi-crop views, and why no negative pairs are needed, then the properties that follow: dense spatial precision, instance-level discrimination, no language alignment, and attention maps that segment objects unprompted.
In this topic
- 1Self-Distillation Framework
- 2DINOv2 Feature Properties
Self-Distillation Framework
DINOv2 uses a student-teacher framework with exponential moving average (EMA) updates:
- Student network: Processes both global and local crop views of the image. Weights are updated by gradient descent.
- Teacher network: Processes only global crop views. Weights are an EMA of the student: where .
The loss encourages the student to produce the same output distribution as the teacher across different augmented views of the same image. Since the teacher sees global views while the student sees both global and local crops, the student learns to predict global context from local information.
No negative pairs needed: Unlike CLIP/SigLIP, DINO does not require explicit negative examples. The centering and sharpening of the teacher's outputs prevent mode collapse (all images mapping to the same representation).
The EMA update with means the teacher's effective learning rate is times the student's. Over steps, the teacher integrates a Polyak-averaged trajectory: , an exponentially-weighted moving average that smooths away gradient noise and prevents the teacher from collapsing to trivial solutions.
DINOv2 uses 2 global crops (covering 50-100% of the image) and 10 local crops (covering 5-50% of the image). Why this asymmetry, and what does each crop type contribute to learning?
DINOv2 Feature Properties
DINOv2 features have distinctive properties compared to CLIP:
-
Dense, spatially precise features: Because DINOv2 is trained with local crops, its patch-level features encode precise spatial information. This makes DINOv2 superior for dense prediction tasks (segmentation, depth estimation).
-
Instance-level discrimination: DINOv2 can distinguish between individual instances of the same class (e.g., different dogs) better than CLIP, which primarily learns category-level features.
-
No language alignment: DINOv2 features are not aligned to text. They encode visual similarity and structure but cannot be directly compared to text embeddings. This requires a more capable bridge module in VLMs.
-
Emergent properties: DINOv2 features exhibit remarkable emergent behaviors---attention maps naturally segment objects, patch-level features cluster semantically without supervision, and linear probes on frozen features achieve strong performance on diverse tasks.
For VLMs: DINOv2's dense features complement CLIP's semantic features. Some VLMs (Cambrian-1, Eagle) combine both encoders to get the best of both worlds.
DINOv2 features form clusters in that correspond to semantic parts without any label supervision: the -nearest-neighbor graph of patch features naturally segments objects. Formally, the learned feature map induces a metric where iff patches belong to the same semantic region. This emerges because the multi-crop loss forces local patches to predict global structure.
A VLM uses CLIP ViT-L for visual encoding. The model can describe images well but struggles with: (a) counting objects, (b) identifying specific parts of objects, (c) depth ordering. Would adding DINOv2 features help?
Theory Exercise
Problem:
DINOv2 is trained without any text supervision, yet when used in VLMs, the bridge module can learn to map DINOv2 features to the LLM's embedding space. Why does this work? What must the bridge module learn that is different from when CLIP features are used?
Hints:
- Think about what information is already present in DINOv2 features vs. what is missing
- Consider how CLIP's text alignment makes the bridge module's job easier
- Think about the bridge module's role as a 'translator' between representation spaces
Related Problems on PixelBank
Six encoders in, and there is no winner, which is the honest and slightly uncomfortable conclusion. CLIP gives you language alignment, SigLIP a better-scaling objective and a larger checkpoint, DINOv2 spatial precision with no text alignment at all, InternViT raw capacity at a steep price. The decision in front of you is not which is best but which axis your product is constrained on, and the preceding topics have laid out exactly three. Whether to freeze the encoder or fine-tune it comes first, because it sets your training cost and your exposure to catastrophic forgetting. Resolution against token count comes second, and it is the axis people underestimate: LLM attention is quadratic in token count while token count is quadratic in resolution, so tripling the resolution multiplies attention cost by 81. Feature granularity comes last, matching encoder characteristics to what the application actually needs, whether that is OCR, grounding, retrieval, or open-ended description. Work through these three and the choice usually makes itself, including the option of concatenating two encoders when one will not do.
In this topic
- 1Frozen vs. Fine-Tuned Vision Encoders
- 2Resolution vs. Token Count Trade-Off
- 3Feature Granularity Comparison
Frozen vs. Fine-Tuned Vision Encoders
A critical design choice: should the vision encoder's weights be fixed (frozen) during VLM training, or updated (fine-tuned)?
Frozen encoder:
- Preserves the pre-trained feature quality
- Much cheaper to train (no gradients through the encoder)
- Allows using pre-computed features (offline extraction)
- Used by: BLIP-2, Flamingo, early LLaVA
Fine-tuned encoder:
- Features adapt specifically to the VLM's needs
- Can learn task-specific visual patterns not captured during pre-training
- Risk: catastrophic forgetting of pre-trained capabilities
- Used by: LLaVA-1.5+, InternVL, Qwen-VL
Practical guideline: Start with a frozen encoder (faster iteration). If performance plateaus, unlock the encoder with a low learning rate ( lower than the bridge module).
Fine-tuning a pre-trained encoder is equivalent to walking along the loss landscape from the CLIP/SigLIP minimum toward the VLM-specific minimum. If the two minima are in the same basin (small distributional shift), a small learning rate suffices. If they are in different basins (large shift), aggressive fine-tuning causes catastrophic forgetting — the weights cross a loss barrier and lose the pre-trained basin entirely. LoRA constrains updates to a low-rank subspace with , keeping the trajectory close to the original minimum.
A VLM with a frozen CLIP encoder achieves 75% on MMBench. After unfreezing the vision encoder (lr=1e-6), it achieves 79% after 1 epoch but drops to 71% after 5 epochs. What happened?
Resolution vs. Token Count Trade-Off
Higher resolution means more visual detail but also more tokens, increasing computational cost quadratically in the LLM's attention layers.
| Resolution | Patches (p=14) | LLM Attention Cost |
|---|---|---|
| 224x224 | 256 | 1.0x (baseline) |
| 336x336 | 576 | 5.1x |
| 448x448 | 1,024 | 16.0x |
| 672x672 | 2,304 | 81.0x |
| 1344x1344 | 9,216 | 1,296x |
When high resolution matters:
- OCR / document understanding (text must be readable)
- Fine-grained recognition (bird species, product details)
- Spatial reasoning with small objects
- Chart/graph interpretation
When 224-336px is sufficient:
- Scene classification
- Object detection (coarse)
- General image captioning
- Binary VQA (yes/no questions)
LLM self-attention over visual tokens costs FLOPs per layer. Since , the total cost is — quartic in resolution. Going from 224px to 672px () multiplies attention cost by . Token-compressing bridges break this quartic scaling by mapping tokens to , reducing cost to .
A VLM must process 100 images per minute for a real-time surveillance system. Each image is 1920x1080. The LLM can process 10,000 tokens/second. What resolution should the vision encoder use?
Feature Granularity Comparison
Different encoders produce features with different granularity characteristics:
CLIP ViT-L/14:
- Strong semantic features (category-level)
- Good text alignment
- Weaker spatial precision
- Best for: general VQA, captioning, retrieval
SigLIP-SO400M:
- Slightly better semantic features than CLIP
- Efficient training
- Better calibrated confidence
- Best for: general-purpose VLMs, production deployment
DINOv2 ViT-g:
- Excellent spatial features (instance-level)
- No text alignment (needs stronger bridge)
- Best for: dense prediction, counting, segmentation, grounding
InternViT-6B:
- Richest overall features (most parameters)
- Strong on both semantics and spatial detail
- Highest computational cost
- Best for: document understanding, maximum quality regardless of cost
Combined encoders (Cambrian-1 approach):
- CLIP + DINOv2 features concatenated per patch
- Best of both worlds: semantic + spatial
- Double the bridge module size and visual tokens
- Best for: research, benchmarks, when accuracy is paramount
The information content per token scales roughly as bits, where is the encoder size and is the token count. CLIP ViT-L gives bits/token while InternViT-6B gives bits/token. These extra 4.5 bits per token compound across 256 tokens, yielding additional bits of visual information — enough to encode roughly 150 extra characters of text-equivalent detail.
You are building three VLMs for different products. Select the optimal vision encoder for each: (1) A mobile photography assistant, (2) A document digitization service, (3) A visual search engine.
Theory Exercise
Problem:
A VLM research team has budget for one major training run. They must decide between: (A) CLIP ViT-L at 672x672 (2,304 tokens per image), or (B) InternViT-6B at 224x224 (256 tokens per image). Both use the same LLM. Analyze which configuration will perform better on (1) OCR tasks, (2) visual reasoning tasks, and (3) general VQA. Consider both feature quality and computational efficiency.
Hints:
- More tokens at moderate feature quality vs. fewer tokens at high feature quality
- OCR depends heavily on resolution; reasoning depends on feature richness
- Consider what happens during the LLM's attention: how does it use 2,304 vs. 256 tokens?