Chapter 4: Vision-Language Alignment
Master the bridge architectures that connect vision encoders to language models. From simple linear projections to sophisticated Q-Former and Perceiver Resampler designs, understand how visual representations are translated into the language model's embedding space and how different approaches trade off between token efficiency, information preservation, and computational cost.
- Topics
- 7
- Videos
- 7
- Min read
- 47
Chapter Overview
The alignment problem in VLMs is fundamentally about bridging two representation spaces that were trained independently: the vision encoder's feature space (optimized for visual similarity via contrastive learning) and the LLM's embedding space (optimized for next-token prediction of text). These spaces encode different types of information in different geometric structures, and the bridge module must translate between them faithfully.
The bridge architecture is arguably the most critical design decision in a VLM. It determines how much visual information reaches the language model, how many tokens the LLM must process (directly impacting inference cost), and whether the model can preserve fine-grained spatial details or must compress to a coarse summary.
The field has explored a rich design space:
- Linear Projection (LLaVA): The simplest bridge---a single matrix multiply. Fast, preserves all spatial tokens, but limited in representational capacity.
- Q-Former (BLIP-2): Learned query tokens cross-attend to image features, compressing 257 image tokens to just 32. Powerful but adds significant parameters and complexity.
- Perceiver Resampler (Flamingo): Fixed latent tokens cross-attend to visual features. A clean, principled approach to information compression.
- MLP Projectors (LLaVA-1.5): Multi-layer projectors with nonlinearity. The practical sweet spot that most modern VLMs use.
- Dynamic Resolution (LLaVA-NeXT, SigLIP2): Handle arbitrary image sizes without distortion.
This chapter covers each approach in detail, with mathematical formulations, implementation walkthroughs, and a systematic comparison of trade-offs.
Chapter Roadmap
Click any topic to jump in
The Alignment Problem
Vision encoders and LLMs speak different languages. CLIP groups by visual similarity (dogs and cats are close), LLMs group by linguistic meaning (dogs and cats are far apart). A bridge module must translate between these two worlds.
Each takes a different approach to the same problem
Linear Projection (LLaVA)
The simplest possible bridge: one matrix multiply converts each image patch independently. Surprisingly competitive — if CLIP and the LLM are both strong, a simple coordinate transform is enough.
Q-Former (BLIP-2)
32 learnable "question" tokens cross-attend to the image, each specializing to extract different info (objects, colors, layout). Compresses 257 image tokens down to just 32 — an 8x reduction.
Perceiver (Flamingo)
Fixed latent tokens iteratively refine themselves by repeatedly cross-attending to image features. Similar goal to Q-Former (compression) but with a cleaner, more principled architecture.
MLP Projectors
A 2-layer MLP (linear → GELU → linear) replaces the single linear projection. The nonlinearity lets it learn curved boundaries between concepts that a flat projection can't capture. This is what most modern VLMs actually use.
Dynamic Resolution
Real images come in all sizes and aspect ratios. AnyRes tiles a high-res image into patches processed separately, then merges. NaFlex uses flexible positional encodings. Both avoid distortion from resizing.
Comparing Architectures
A decision framework: Linear/MLP preserves all detail but costs more LLM tokens. Q-Former/Perceiver compresses aggressively but may lose fine-grained info. The right choice depends on your task — OCR needs full tokens, classification doesn't.
Topics
7 topics in this chapter
A frozen CLIP ViT-L hands you 576 vectors of width 1024, trained so that an image lands near its caption under cosine similarity. A frozen Vicuna-7B expects vectors of width 4096, trained so that each one helps predict the next word. Neither model has ever seen the other's coordinates. How do you get the language model to read the picture? The previous chapter described the language backbone; this chapter is about the bridge (also called the connector or projector) that sits between the two. Three questions organize it. First, how different are the two spaces, and what kind of map is needed? Second, how much should the bridge compress: keep all 576 tokens, or squeeze them to 32 or 64, accepting the information-bottleneck trade-off? Third, how is the bridge trained: BLIP-2 pre-aligns a 188M-parameter Q-Former with three objectives on 129M images, while LLaVA trains a single linear layer on 595K caption pairs before instruction tuning. The rest of the chapter works through linear, Q-Former, Perceiver and MLP bridges, then dynamic resolution, and closes with a comparison.
Definition
The vision-language alignment problem is to learn a bridge that turns a vision encoder's features into inputs the language model can use. The bridge must change dimension (for example 1024 to 4096), translate between representations trained for different objectives, and choose how many tokens to pass on, trading information kept against the LLM's sequence cost.
In this topic
- 1Representational Gap
- 2Information Bottleneck Principle
- 3Alignment Training Objectives
Representational Gap
Why can't you just copy CLIP vectors into the LLM? The two spaces were shaped by different objectives. CLIP's contrastive loss places images near their captions, so features cluster by what things look like and how they are described; two dog breeds sit close together. The LLM's embeddings and hidden states are shaped by next-token prediction, so they encode what tends to come next. The formula's compares cosine similarity of the same pair, dog and cat, under the vision features and the LLM representation . The bridge's job is to make visual features legible to the LLM, not to make them look like word embeddings.
A linear bridge can stretch and rotate, so it can amplify a small breed-specific direction relative to a large shared one; cosine similarity is not preserved by such maps, so 0.92 in CLIP space need not stay 0.92 after projection. What a linear map cannot do is create information: if two inputs are identical in feature space, any bridge sends them to the same output. A separate effect, the modality gap (Liang et al. 2022), means image and text embeddings in CLIP occupy different cones, so even well-aligned models keep the modalities apart.
A CLIP encoder produces similar features for a Labrador and a Golden Retriever (cosine similarity 0.92). The LLM needs to distinguish them in text. How does the bridge help?
Information Bottleneck Principle
The bridge module creates a compressed representation of the visual input . By the data processing inequality, cannot contain more information about the target text than the original image does. The design question is: how much compression is optimal? Too little compression (all 576 tokens) wastes LLM compute on redundant information. Too much compression (32 tokens) may lose critical visual details. The optimal bottleneck preserves all task-relevant information while discarding irrelevant visual detail.
For a chain the data processing inequality gives and also , which is the frozen formula: the bridge output cannot know more about the answer than it knows about the image. The information bottleneck objective, minimize , formalizes the trade-off. Token count is only a proxy for : 576 vectors are not lossless (the encoder already discarded detail at 336 px), and 32 vectors of width 768 still carry a lot of information.
BLIP-2's Q-Former compresses 257 ViT tokens to 32 query tokens (8x compression). For the task of OCR (reading text in an image), is this compression too aggressive?
Alignment Training Objectives
How do you teach a bridge what matters before the LLM is involved? BLIP-2 trains its Q-Former with three losses at once. Image-Text Contrastive () pulls matching image and text embeddings together and pushes mismatched ones apart. Image-Text Matching () is a binary classifier on fused image-text pairs, trained with hard negatives. Image-grounded Text Generation () makes the queries carry enough to generate the caption. Simpler bridges skip this stage: LLaVA's projector learns only from the language-model loss, first on captions and then on instructions. The pre-alignment costs a large dataset and a separate training stage.
The three losses use one set of Q-Former weights under different attention masks. ITC is a softmax over a batch of image-text similarities, so it shapes global geometry; ITM is a cross-entropy on matched versus hard-negative pairs, so it sharpens fine distinctions; ITG is next-token likelihood, so it forces the queries to carry generatable content. The total is a multi-task objective; BLIP-2's ablations show removing ITG hurts the stage-2 generative transfer.
LLaVA trains its projector only with the language-model generation loss (first on 595K caption pairs, then on 158K instruction examples). BLIP-2 first pre-trains its Q-Former with ITC+ITM+ITG on 129M images. Which approach is more data-efficient?
Theory Exercise
Problem:
A VLM must handle both coarse tasks (image classification, scene description) and fine-grained tasks (OCR, object counting, visual question answering about small details). Design a bridge architecture that adapts its compression ratio based on the task. Describe the architecture and how it would decide how many tokens to pass to the LLM.
Hints:
- Consider a two-path architecture: compressed and uncompressed
- The model could learn to route based on the text query
- Think about how LLaVA-NeXT's anyres already addresses this partially
If CLIP already knows what is in the image and Vicuna already knows how to talk, how much machinery does the bridge actually need? LLaVA (Liu et al., 2023) tested the minimal answer: one weight matrix and a bias, applied to each patch feature independently, mapping width 1024 to the LLM's width. The previous topic framed alignment as translating between two coordinate systems; this topic shows how far the simplest translation goes. For CLIP ViT-L/14 at 336 px and a 4096-wide LLM, the projector has 4,198,400 parameters, about 0.06 percent of a 7B model. LLaVA trains it in two stages: first only the projector, on 595K filtered CC3M caption pairs with both models frozen; then the projector and the full LLM together on 158K instruction-following examples. On 8 A100s the paper reports under 4 hours for stage 1 and under 10 hours for stage 2. We will compute the projector's size, see why it never mixes patches, and examine why the LLM is frozen in stage 1 but trained in stage 2.
Definition
A linear projection bridge applies one affine map to every vision feature , with . It changes width but keeps one output token per input patch, mixes no information across patches, and leaves all cross-patch reasoning to the language model's self-attention.
In this topic
- 1Linear Projection Formula
- 2Training Strategy: Two-Stage
Linear Projection Formula
The map is , where is patch 's feature, has shape , and is a bias of width . For CLIP ViT-L () into Vicuna-13B (), holds 5,242,880 weights. The same is applied to every patch independently, so the bridge never mixes neighbouring patches; the LLM's self-attention does that afterwards. The design is cheap and preserves the full grid of tokens, but it gives no control over token count: 576 patches always become 576 LLM tokens.
An affine map can rotate, scale and shift, but it cannot bend: if two patch features are not linearly separable in CLIP space, they are not separable in its output either. That limitation matters less than it sounds, because the projected tokens feed a deep nonlinear LLM that can separate them later. LLaVA-1.5's switch from linear to a two-layer MLP gave modest gains, for example GQA 46.8 to 47.3 and MME 1323.8 to 1355.2 in its ablation table, not a dramatic jump.
CLIP ViT-L/14 at 336×336 produces 576 patches of dimension 1024. The target LLM has . Calculate the projection parameters and total visual token count.
Training Strategy: Two-Stage
Why two stages? In stage 1 only is trained, minimizing , the language-model loss on 595K image-caption pairs filtered from CC3M, with the vision encoder and LLM frozen. This lands visual tokens somewhere the frozen LLM can already read. In stage 2 both and the LLM weights are trained on with 158K visual instruction examples (58K conversations, 23K detailed descriptions, 77K complex reasoning). LLaVA's paper reports 1 epoch of stage 1 at learning rate 2e-3 and 3 epochs of stage 2 at 2e-5 on 8 A100s. Skipping stage 1 means the LLM's first updates chase noise from a random projector.
Stage 1 is not a least-squares problem: the loss is next-token cross-entropy computed through a frozen, nonlinear LLM, so it is non-convex in even with everything else fixed, and there are no target embeddings to regress onto. It is still small and well-conditioned, with 4.2M trainable parameters and a high learning rate (2e-3). Stage 2 unfreezes about 7B more parameters at a 100x lower rate (2e-5), so the language model adapts gently to an input distribution that stage 1 has already made sensible.
Why freeze the LLM in Stage 1 but unfreeze it in Stage 2?
Theory Exercise
Problem:
The linear projection treats each patch independently. Design an experiment to test whether inter-patch interaction in the bridge improves performance. What baseline and test conditions would you use? What metrics would you measure?
Hints:
- Compare linear projection (no inter-patch interaction) vs a bridge with self-attention among patches
- Think about tasks that require spatial reasoning across patches
- Consider both benchmark accuracy and inference speed
Related Problems on PixelBank
A linear projector passes every patch to the LLM, so a 257-token ViT-g output costs 257 positions of LLM attention, and the LLM must be fine-tuned to read them. BLIP-2 (Li et al., 2023) asked whether a small trained module could do the reading for a frozen LLM and hand over only a summary. Its answer is the Q-Former: a 12-layer transformer, initialized from BERT-base, holding 32 learned query vectors of width 768. The queries talk to each other through self-attention in every layer and read the frozen image features through cross-attention inserted every other block. Their 32 outputs pass through one linear layer into the LLM. The previous topic's linear bridge used 4.2M parameters and 595K captions; the Q-Former uses 188M parameters, counting the queries, and is pre-trained on 129M images with three objectives before the LLM is ever attached. We will look at the queries, count the attention work honestly, and see what each pre-training objective contributes. Training the largest BLIP-2 took under 9 days on a single 16-A100 machine.
Definition
The Q-Former is a lightweight transformer with learned query embeddings (, width 768 in BLIP-2) that read frozen image features through cross-attention and coordinate through self-attention. Its outputs, linearly projected to the LLM width, form a fixed-length visual prefix no matter how many patches the encoder produced.
In this topic
- 1Learned Query Tokens
- 2Cross-Attention to Image Features
- 3Three-Stage Pre-training
Learned Query Tokens
What does the Q-Former ask the image? Its queries are vectors of width , learned during pre-training and identical for every image. They are model parameters, not image features; only after cross-attention do the outputs depend on the picture. Training pushes the queries to extract different things, since 32 copies of the same summary would waste capacity, but which query ends up encoding what is not fixed in advance. The count is a design choice: more queries keep more detail at higher LLM cost, and BLIP-2 used 32 without publishing a sweep over that number.
The queries live in the Q-Former's own 768-dimensional space, not in image-feature space. Each cross-attention output is , a convex combination of projected patch features, so each of the 32 outputs is a learned weighted average of the image. With 12 heads, each query forms 12 such averages per cross-attention layer. The bottleneck is 32 × 768 numbers per image, about 24.6K floats, versus 257 × 1408 (about 362K) for the ViT-g features it reads.
Why use 32 queries instead of 1 (maximum compression) or 256 (no compression)?
Cross-Attention to Image Features
Here holds the frozen encoder's patch features; the queries supply , while and project the image features into keys and values, and is the key width. The image features never attend to anything, so the encoder output is computed once and only read. BLIP-2 initializes the Q-Former from BERT-base and inserts cross-attention every other block, so 6 of its 12 layers read the image while all 12 run self-attention among the queries. That keeps the image-reading cost proportional to instead of quadratic in the patch count.
Each row of the attention matrix is a probability distribution over patches, so each query-head pair forms its own weighted view of the image. Self-attention among queries between cross-attention layers lets them share what they have read, which is one mechanism for avoiding redundant views, but nothing forces the 32 rows to be independent. Cost is linear in patch count: doubling resolution to about 1,028 patches quadruples the cross-attention cost but leaves the LLM's 32 tokens unchanged.
In BLIP-2, the Q-Former has 12 layers with both self-attention and cross-attention. How many total attention operations per image?
Three-Stage Pre-training
The Q-Former is pre-trained with three objectives: Image-Text Contrastive (ITC) aligns the global image and text representations using contrastive loss (similar to CLIP). Image-Text Matching (ITM) trains a binary classifier to determine if an image-text pair matches. Image-grounded Text Generation (ITG) trains the Q-Former to generate text captions from the query outputs. Different attention masks are used for each objective: ITC uses unimodal masks, ITM uses bidirectional, ITG uses causal.
Each objective imposes a different attention mask structure on the same transformer weights. ITC uses a block-diagonal mask (queries and text attend only within their modality — no cross-modal flow). ITM uses a full bidirectional mask (every token attends to every other token). ITG uses a causal mask (each text token attends only to previous text tokens and all queries). This progression — independent bidirectional causal — systematically increases the model's capacity to mix visual and textual information, training the shared weights to handle all three regimes of cross-modal interaction.
Why are three separate objectives needed? Could you use just the generation loss (ITG)?
Theory Exercise
Problem:
Compare the parameter efficiency of Q-Former (BLIP-2) vs Linear Projection (LLaVA). The Q-Former has 188M parameters trained on 129M image-text pairs. The linear projection has 4.2M parameters trained on 595K pairs. Calculate the parameter-to-data ratio for each and discuss which is more practical.
Hints:
- Parameter-to-data ratio: parameters / training examples
- Consider training compute (FLOPs) as well as parameters
- Think about the cost of the pre-training data collection
Flamingo had to handle not just one image but interleaved sequences of images and video frames, each producing a large grid of features from an NFNet-F6 encoder. Feeding all of them to a 70B language model was not an option. How do you turn a variable number of visual features into a small, fixed number of tokens? The previous topic's Q-Former answered with learned queries pre-trained on contrastive and matching objectives. Flamingo's Perceiver Resampler (Alayrac et al., 2022) uses the same basic idea, learned latent vectors reading the image through cross-attention, but trains it end-to-end with the language-modeling loss on web data. In Flamingo it has 6 layers, outputs 64 visual tokens per image or video, and has about 200M parameters at every model size. A detail that is easy to miss: the latents' keys and values include the latents themselves, concatenated with the visual features. We will walk through the layer update, how the latents are learned, and how the method relates to plain attention pooling, then look at what the published ablations say about token count.
Definition
A Perceiver Resampler maps a variable-length set of visual features to a fixed set of latent tokens. Each layer lets the learned latents attend to the concatenation of and itself, then applies a feed-forward block, both with residual connections. Flamingo uses and 6 layers, and its outputs feed gated cross-attention layers in the LLM.
In this topic
- 1Perceiver Cross-Attention
- 2Latent Token Initialization
- 3Comparison with Attention Pooling
Perceiver Cross-Attention
Each of the layers updates the latents by attending to the visual features and then applying a feed-forward block (FFN), both with residual connections. The visual features stay fixed across layers and never attend to anything themselves; they are only read. Flamingo's pseudo-code adds one detail the frozen formula omits: the keys and values are the concatenation of the visual features and the current latents, so latents also see each other in the same attention step. Stacking layers lets latents refine what they extract once they know what the others hold. Cost per layer is attention scores for latents and features.
Write one layer as , then . Each latent's attention output is a convex combination of visual features and other latents, so it is a soft selection plus a coordination step. The residual form means a layer can leave a latent nearly unchanged when its current summary is already useful. Cost is linear in the number of features , so a 5-frame video costs five times one image in the resampler but still yields 64 tokens.
Flamingo uses 64 latent tokens with 6 Perceiver layers. The ViT produces 256 patch features. Calculate the total cross-attention operations.
Latent Token Initialization
Where do the latents come from? They are vectors of width , drawn at random from at the start of training and then learned like any other weight; at inference they are fixed, the same for every image. Unlike the Q-Former's queries, they receive no contrastive or matching pre-training. Their only signal is the language-modeling loss flowing back from the frozen LLM through the gated cross-attention layers, so they learn to carry whatever helps predict text. Because Flamingo's gates start closed, those gradients are small early on. Flamingo found a medium resampler best and observed unstable training when the resampler was enlarged together with the LM.
Random initialization only breaks symmetry: if all latents started equal they would receive equal gradients and stay equal. After training, the latents are fixed query vectors, so at inference the resampler is a deterministic function of the image. Nothing makes their roles interpretable; any permutation of the 64 latents would work equally well, as long as the downstream layers were permuted to match. The learned latents matter only as starting queries; the six layers of attention do the image-dependent work.
How do the Perceiver Resampler's latent tokens differ from the Q-Former's learned queries?
Comparison with Attention Pooling
Attention pooling, as in CLIP's ResNet head, uses one query to produce one summary vector from the features . The Perceiver Resampler generalizes it to latent queries , so it outputs summaries, each a different weighted average. With it reduces to attention pooling. With close to the input count it no longer compresses, though it still mixes features. Choosing sets the trade-off between detail and LLM cost. Published ablations show the curve flattens quickly for general benchmarks: Idefics2 saw no gain beyond 64 tokens, while document and OCR models keep many more.
Attention pooling computes a single weighted average , which lies in the convex hull of the input features — a single point, regardless of the input's dimensionality. The Perceiver's latent tokens each attend differently, so the output spans up to linearly independent directions in feature space. With latents, the output can represent a -dimensional subspace of the input, while pooling collapses everything to a 1D projection. This is precisely why pooling loses spatial information: it projects a high-rank feature set onto a rank-1 output.
Idefics2 replaced 729 SigLIP tokens per image with a 64-latent perceiver resampler and reports an average score of 71.7 with 64 latents versus 71.2 with 128. Flamingo also uses 64. What does this say about choosing , and when would you raise it?
Theory Exercise
Problem:
The Perceiver Resampler uses the same image features as keys/values in every layer. Would it help to use different image features at different layers (e.g., features from different ViT layers)? Design an experiment to test this hypothesis.
Hints:
- Different ViT layers capture different levels of abstraction
- Early ViT layers: edges, textures. Late layers: objects, semantics
- Consider a 'feature pyramid' approach
The previous topics bracketed the design space: a linear layer that keeps every token but can only apply an affine map, and query-based resamplers that compress hard but need extra pre-training. LLaVA-1.5 (Liu et al., 2023) settled on something in between that became the open-source default: a two-layer MLP with a GELU, applied to each patch exactly as the linear layer was. It adds about 21M parameters for a 7B LLM, still a rounding error, and in LLaVA-1.5's ablation it nudged GQA from 46.8 to 47.3 and MME from 1323.8 to 1355.2. Those are small gains, and most of LLaVA-1.5's improvement came from data, 336 px inputs and the larger LLM. The point is that a cheap nonlinearity costs nothing and never hurts. This topic covers three neighbours: the MLP itself; Flamingo-style gated cross-attention adapters, which inject vision inside the LLM instead of lengthening its input; and the projector comparisons in Honeybee and MM1, which show when locality-preserving designs matter and when the connector barely matters at all.
Definition
An MLP projector maps each vision feature to the LLM width with two linear layers and a nonlinearity, , keeping one token per patch. An adapter instead inserts new layers inside the LLM, such as gated cross-attention, so visual information enters the hidden states rather than the input sequence.
In this topic
- 1Two-Layer MLP Projector
- 2Gated Cross-Attention Adapters
- 3Projector Architecture Search
Two-Layer MLP Projector
The projector computes for each patch feature . lifts it to a hidden width, GELU bends the map, and produces the LLM-width token; and are biases. LLaVA-1.5 sets , so for ViT-L (width 1024) feeding a 7B model (width 4096) the second matrix alone is four times the first, and the total is about 21.0M parameters, not the 8.4M that two equal matrices would suggest. Like the linear layer, it maps each patch independently, so the token count and the lack of spatial mixing are unchanged from the linear bridge.
The MLP introduces a nonlinear feature transformation. The hidden layer creates nonlinear decision boundaries in the vision feature space, enabling the projection to separate features that are linearly entangled. With hidden dimension , the first layer "lifts" features to a higher-dimensional space where linearly inseparable clusters become separable (Cover's theorem), then projects back to .
LLaVA-1.5 uses , , . Calculate the total MLP parameters and compare to linear projection.
Gated Cross-Attention Adapters
Instead of lengthening the LLM's input, adapters insert new layers between frozen LLM blocks. At layer , the hidden states cross-attend to visual tokens , and the result is scaled by , a gate that starts at 0 so the model initially behaves exactly like the original LLM. Flamingo inserts these every fourth layer in Flamingo-9B and every seventh in Flamingo-80B, a trade-off its ablation measured: every fourth layer trained 66 percent faster than every layer for a 1.9 percent drop in score. Idefics2 later found the cross-attention design better with frozen backbones but worse once the backbones were adapted with LoRA.
At the block computes exactly. Gradients still flow: is nonzero because at 0, while the cross-attention weights get zero gradient at first because they are multiplied by . A PyTorch check gave and an exactly zero gradient for the attention weights. So the gate opens first, then the new layer starts learning. Nothing forces to grow monotonically; it can shrink or go negative.
Compare token-prepending (LLaVA) vs adapter injection (Flamingo) for a 7B LLM with 32 layers, 256 image features, and 200 text tokens.
Projector Architecture Search
Does the projector design matter? Honeybee (Cha et al., 2023) compared linear projectors, resamplers and its own C-Abstractor (convolutional, locality-preserving) and D-Abstractor (deformable attention). Resamplers did worst on spatial tasks because they lose local context; linear projectors kept locality but were stuck at one token per patch; at the same 256 tokens the C-Abstractor scored 56.3 versus 52.6 for linear on six spatial tasks. MM1 (McKinzie et al., 2024) reached a sobering conclusion: image resolution and token count mattered a lot, and connector type comparatively little, with average pooling matching the C-Abstractor at low token counts. Pick the token budget first, then the projector.
Three numbers describe a projector: the token count it emits, whether it mixes neighbouring patches (locality), and its parameter count. MM1's ablations suggest token count dominates; Honeybee's suggest locality matters once you compress, since a convolution can merge a 2 × 2 neighbourhood without losing which patch was where, while a resampler's learned queries may ignore regions entirely. Parameter count barely matters: every projector here is under 1 percent of the LLM.
The C-Abstractor uses 2D convolutions on the image feature grid. Why might this help compared to a per-token MLP?
Theory Exercise
Problem:
Design a hybrid projector that combines the strengths of MLP (nonlinear projection) and C-Abstractor (spatial awareness): a "Spatial MLP" that first applies local spatial aggregation, then per-token nonlinear projection. Specify the architecture, parameter count, and expected advantages.
Hints:
- Consider a depthwise convolution for efficient spatial aggregation
- The spatial step operates on the 2D grid before flattening
- Compare parameter count with MLP-2 and C-Abstractor separately
Related Problems on PixelBank
A CLIP ViT-L/14 at 336 px sees every image as a 24 × 24 grid of patches, whether it is a phone photo, a 1920 × 1080 screenshot or an A4 page. Downscaling a document to 336 px makes 10-point text unreadable; upscaling a thumbnail wastes compute; squashing a panorama distorts it. How do you give a fixed-resolution encoder more pixels? The previous topics fixed the bridge; this one changes what goes into the encoder. Two families dominate. Tiling (LLaVA-1.5-HD, LLaVA-NeXT's AnyRes) picks a grid of 336 px crops that best fits the image, encodes each crop separately, and adds one downscaled global view. Native resolution (SigLIP 2's NaFlex, Qwen2-VL) resizes the image to keep its aspect ratio under a patch budget and runs the encoder on a variable-shaped grid. Both multiply visual tokens. Hugging Face's LLaVA-NeXT processor counts 2,928 visual tokens for a 1024 × 1024 image versus 576 at plain 336 px, so token compression comes along with them. We will compute real token counts for each method.
Definition
Dynamic resolution means encoding an image at a resolution and aspect ratio chosen per input rather than one fixed square. Tiling methods split the image into encoder-sized crops plus a global thumbnail; native-resolution methods vary the patch grid's shape under a token budget. Both trade more visual tokens for finer detail, often followed by token compression.
In this topic
- 1AnyRes Tiling (LLaVA-NeXT)
- 2NaFlex (SigLIP2)
- 3Token Compression for High-Resolution
AnyRes Tiling (LLaVA-NeXT)
AnyRes picks, from a fixed list of grid resolutions, the one that best fits the image (for the original LLaVA-NeXT checkpoints: 672 × 336, 336 × 672, 672 × 672, 1008 × 336, 336 × 1008), resizes the image into it with padding, and cuts it into 336 px tiles. Each tile and a downscaled global view are encoded separately, passes for tiles. The global view gives scene context; the tiles give detail. LLaVA-NeXT then strips features that fall in padding and adds one newline token per row, so counts are not simply : Hugging Face's processor gives 2,928 for a 1024 × 1024 image, not 2,880.
For a capped grid list the token count does not grow with image area: the largest LLaVA-NeXT grid is 2 × 2 (or 3 × 1), so any large image costs at most about 2,928 tokens. The resolution is capped too, at 672 px on the long side for the 2 × 2 grid, so a 4K screenshot loses detail anyway. LLaVA-OneVision raised the cap (up to a 6 × 6 grid with 729-token SigLIP crops) and bilinearly downsamples features when the total exceeds a threshold, keeping the maximum near 7,290 tokens per image.
A user uploads a 1920×1080 (16:9) screenshot. LLaVA-NeXT uses a 336 px ViT (576 tokens per view) and the grid list 672×336, 336×672, 672×672, 1008×336, 336×1008. Which grid is chosen, and how many visual tokens does the LLM receive?
NaFlex (SigLIP2)
NaFlex (Native Flexible resolution) avoids tiling entirely. Instead, it processes the image at its native aspect ratio by varying the number of ViT patches. The image is resized so that the total token count stays under a budget , but the aspect ratio is preserved. A square 1024×1024 image and a panoramic 2048×512 image produce different grid shapes (e.g., 24×24 vs 48×12) but similar total token counts. This eliminates tiling artifacts and distortion.
Standard ViTs require fixed resolution because positional embeddings are learned for exactly patches. NaFlex decouples position from resolution by using 2D interpolation: for input size , it interpolates to . This preserves the relative spatial structure while adapting to arbitrary aspect ratios without tiling overhead — a single forward pass handles any resolution.
NaFlex with patch size and . What resolution can a 16:9 image be processed at?
Token Compression for High-Resolution
Tiling multiplies visual tokens, and every one costs LLM compute in every layer, so models compress. The frozen formula shows the simplest form: average each 2 × 2 block of the feature grid into one token , cutting the count 4x while keeping the grid's layout. Alternatives include bilinear downsampling of the feature map (LLaVA-OneVision does this once the total exceeds its threshold), merging similar tokens, and pruning tokens the LLM barely attends to, as FastV does after layer 2. The original LLaVA-NeXT image models did not pool tile features. Compression trades away exactly the fine detail that tiling was meant to add.
A average is a low-pass filter on the feature grid: it keeps the average of each block and discards the variation inside it. When neighbouring patch features are nearly equal, as in sky or wall regions, little is lost; when a character stroke lives in one patch, it gets diluted 4x. The trade-off is therefore task-dependent in a predictable way: pooling hurts OCR and small-object counting more than scene description. Pooling the tiles but not the global view, as in this example, keeps scene context at full grid density.
A 4-tile anyres image produces tokens. Apply 2×2 average pooling to each tile's tokens. What is the final count?
Theory Exercise
Problem:
Compare the effective resolution (pixels per ViT patch) and total token count for three approaches processing a 1024×768 photograph: (A) Standard resize to 336×336, (B) LLaVA-NeXT anyres with 2×2 tiles, (C) NaFlex with and .
Hints:
- Standard: resize distorts aspect ratio (4:3 -> 1:1)
- Anyres: 2x2 tiles at 336×336 + 1 global view
- NaFlex: find h,w such that h*w <= 576 and w/h = 4/3
You now have four bridges on the table: linear and MLP projectors that keep every patch, Q-Former and Perceiver resamplers that compress to 32 or 64 learned queries, and gated cross-attention adapters that inject vision inside the LLM. Which should you use? The earlier topics each argued for one design; this topic puts them side by side with the published numbers, and those numbers come with a caveat. Most comparisons change several things at once. When LLaVA-1.5 (576 tokens) beats BLIP-2 (32 tokens) on TextVQA, 61.3 to 42.5, it also has a different LLM, different training data and a fine-tuned rather than frozen language model. The cleaner ablations point the same way but less dramatically. MM1 found that resolution and token count matter far more than connector type. Idefics2 found a 64-latent perceiver beat 729 raw tokens by 8.5 points on its benchmark mix. Honeybee found that locality matters for spatial tasks once you compress. We will build a trade-off picture, a decision procedure for real deployments, and an honest reading of benchmark tables.
Definition
Comparing bridge architectures means evaluating them on a common footing: visual tokens sent to the LLM, information preserved (especially fine detail and spatial layout), trainable parameters, training stages and data, and inference cost. A fair comparison changes only the bridge and keeps the encoder, resolution, LLM and data fixed.
In this topic
- 1Token Efficiency vs. Information Preservation
- 2Practical Decision Matrix
- 3Benchmark Comparison
Token Efficiency vs. Information Preservation
Every bridge picks a point on one curve. Token efficiency is inversely proportional to the output count , since the LLM's cost grows with it. Information preserved is the fraction of mutual information between bridge output and image that survives, and the frozen formula's ratio is only a crude proxy for it. Linear and MLP projectors keep all tokens; the Q-Former keeps 32; a Perceiver keeps whatever you choose. The proxy breaks in both directions: 576 tokens at 336 px already lose small text, and 64 learned latents beat 729 raw tokens in Idefics2's ablation. Decide by task, not by the ratio.
The trade-off can be formalized as where is the token count. Accuracy is concave in (diminishing returns — going from 32→64 tokens helps more than 512→1024), while Cost is superlinear (LLM attention is ). The Pareto-optimal bridge depends on the curvature of both functions for your specific task: OCR has steep accuracy gains from more tokens; classification has a flat curve beyond ~32 tokens.
Rank the bridge architectures by token efficiency and information preservation for: (a) image captioning, (b) OCR, (c) visual question answering.
Practical Decision Matrix
In practice the two-layer MLP is the default for new open VLMs because it is simple, adds about 21M parameters for a 7B LLM, keeps every token, and trains with LLaVA's two-stage recipe (a projector warm-up on about 558K captions, then instruction tuning). Learned-query resamplers are chosen when visual tokens must be capped, as with many images per prompt or a tight context: Flamingo and Idefics2 use 64 per image. Gated cross-attention adapters suit a frozen LLM whose input format you cannot change, since they leave the text sequence alone. None works with a closed API model, since all need access to embeddings or layers.
Treat it as constrained minimization: choose the bridge minimizing cost subject to accuracy at least a task threshold . Visual-token cost enters in two places: dense layers scale with token count, x more for an MLP than a Q-Former, and the image-image attention block scales with its square, x, though that block is a small share of total FLOPs at these lengths. Where sits is an empirical question for your task; measure it on held-out data rather than borrowing a benchmark threshold.
You are building a VLM for three deployment scenarios. Recommend a bridge for each: (A) Cloud API with A100 GPU, unlimited context (B) Mobile phone with 4GB RAM limit (C) Multi-image chat assistant handling 5+ images per turn
Benchmark Comparison
Benchmark tables are where bridge debates are usually settled, and also where they are most often misread. Score is a weighted sum of per-benchmark accuracies, and both the weights and the benchmark mix (VQAv2, GQA, TextVQA, POPE, MMBench) change the ranking. Across published models, keep-all-tokens designs lead on text-rich tasks: on TextVQA in LLaVA-1.5's comparison table, BLIP-2 scores 42.5 and InstructBLIP-13B 50.7 with 32 tokens, against 61.3 for LLaVA-1.5-13B. But those rows also differ in LLM, data and resolution, so they do not isolate the bridge. Controlled ablations (MM1, Idefics2, Honeybee) are the evidence to trust.
Accuracy per token, , rewards whatever uses the fewest tokens: a model scoring 1 percent with one token would beat everything. Accuracy is bounded and saturating in token count, so compare marginal gains instead: how much accuracy each doubling of tokens buys at fixed encoder, LLM and data. Idefics2 measured one such step: going from 64 to 128 latents changed its average from 71.7 to 71.2, so the marginal value there was zero.
LLaVA-1.5's comparison table reports TextVQA accuracy of 42.5 for BLIP-2 (32 visual tokens), 50.7 for InstructBLIP-13B (32 tokens), 61.5 for Qwen-VL-Chat (256 tokens at 448 px) and 61.3 for LLaVA-1.5-13B (576 tokens at 336 px). Compute accuracy per visual token for each, and explain what the comparison does and does not show.
Theory Exercise
Problem:
Design a benchmark specifically for evaluating bridge architectures that tests: (1) coarse understanding, (2) fine-grained detail, (3) spatial reasoning, (4) multi-object counting, and (5) text reading. For each dimension, provide 2 example questions and explain which bridge architectures would struggle.
Hints:
- Each dimension tests a different aspect of information preservation
- Coarse understanding favors compressed bridges
- Fine-grained detail favors uncompressed bridges
- Include images that specifically test bridge limitations