Vision-language models¶
A vision-language model (VLM) is a language model that has been given eyes: a vision encoder turns an image into a few hundred to a few thousand vectors, a small connector maps them into the language model's embedding space, and from then on the image is just more tokens in the context. Almost everything interesting about VLMs (what they can read, what they hallucinate, what they cost) follows from how those visual tokens are made, how many there are, and what data taught the model to use them.
10,000 ft
Large language models know a great deal about the world but only through text. CLIP and ViTs learned to see but cannot talk. VLMs join the two and are now the default interface to visual data: reading documents and charts, answering questions about photos, operating computers from screenshots (computer-use agents), and, extended with action outputs, controlling robots (embodied AI). They also feed back into generation: SD3 was trained partly on captions written by a VLM (latent diffusion). Frontier assistants accept images natively; their internals are not public, but the open models (LLaVA, Qwen-VL, PaliGemma, Idefics, Molmo, InternVL) all use the recipe on this page, and their papers explain which choices matter.
2,000 ft
The standard recipe has three parts and three training stages. Parts: a pre-trained vision encoder (a CLIP or SigLIP ViT) produces patch features; a connector (a linear layer, a 2-layer MLP, or a learned resampler) maps them to the LLM's width and often reduces their number; a pre-trained decoder LLM reads them interleaved with text tokens and predicts text. Stages: (1) alignment: freeze both models and train only the connector on image–caption pairs; (2) multimodal pre-training / instruction tuning: unfreeze and train on interleaved documents, OCR, charts and instruction-following conversations, with the loss on the answer tokens only; (3) preference or RL tuning to reduce hallucination and improve reasoning. At inference, the image tokens are a prefix that is processed once and cached.
Ground level¶
What the language model needs¶
A decoder LLM consumes a sequence of vectors of width \(d_{\text{LLM}}\) (4,096 for a typical 7–8B model) and is trained to predict the next text token. To make it see, you must deliver visual information as vectors in that same space, in a form its existing weights can use. That breaks into three questions, which organise the whole field:
- Which visual features? The output of a pre-trained encoder, almost always a contrastively trained ViT, because its features are already aligned with language. Crucially, VLMs use the patch features (a grid of vectors), not CLIP's pooled embedding, so that position and detail survive.
- How do they get into the LLM? Either as tokens in the sequence (self-attention sees them like words), or through new cross-attention layers that text tokens use to look at them.
- How many? Each visual token costs as much LLM compute as a text token. A 336×336 image is 576 tokens in LLaVA-1.5; an A4 page at reading resolution is around 5,000 in Qwen2-VL. Resolution is accuracy for text-heavy images and cost for everything.
Four ways to wire vision into a language model¶
Cross-attention (Flamingo, 2022). Alayrac et al. froze a 70B Chinchilla LM and inserted new gated cross-attention blocks between its layers. Text positions attend to visual tokens through them, and each new block's output is multiplied by \(\tanh(\alpha)\) with \(\alpha\) initialised to 0, so at the start of training the model is exactly the original LM, and vision is let in gradually. A Perceiver Resampler compresses any number of image or video features to 64 visual tokens using a fixed set of learned queries that cross-attend to the features. Flamingo was trained on M3W, interleaved text and images from about 43 million web pages, plus image–text and video–text pairs, and it could learn a new task from a handful of interleaved examples in its prompt. Removing the interleaved data cost more than 17% of its average performance in the ablations.
Learned queries (BLIP-2, 2023). Li et al. trained a 188M-parameter Q-Former between a frozen image encoder and a frozen LLM: 32 learned queries that extract a \(32\times768\) summary of the image, first trained with contrastive, matching and captioning losses to pull out text-relevant information, then trained so that its output, as a soft prompt, makes the frozen LLM produce the caption. It beat Flamingo-80B by 8.7 points on zero-shot VQAv2 with 54× fewer trainable parameters.
A projector into the sequence (LLaVA, 2023). Liu et al. did the simplest possible thing: take CLIP ViT-L/14's grid features, multiply by one trainable matrix \(W\) to reach the LLM's width, and put the resulting vectors in the prompt where the image goes. The LLM attends to them with its ordinary self-attention. Earlier work had done the same for captioning (ClipCap, Mokady et al. 2021; Frozen, Tsimpoukelli et al. 2021); LLaVA's contribution was the data, below. LLaVA-1.5 (Liu et al. 2023) swapped the matrix for a 2-layer MLP and the encoder for the 336-pixel CLIP, and this design, a ViT plus an MLP connector plus an LLM, became the default for open VLMs.
Early fusion (Fuyu, Chameleon). Skip the separate encoder: feed linearly embedded raw patches straight into the decoder (Adept's Fuyu-8B, 2023), or turn images into discrete tokens with a VQ tokenizer and train one transformer on mixed sequences from scratch. Chameleon (Chameleon Team 2024) encodes a 512×512 image as 1,024 tokens from an 8,192-entry codebook inside a 65,536-token vocabulary, so the same model can both read and generate images in any interleaving. Training such models from scratch is unstable (Chameleon needed QK-norm and other changes) and expensive, but it is the direction of "natively multimodal" models.
Which is best? Two careful ablation studies answered differently for different regimes. Idefics2's (Laurençon et al. 2024) Finding 2: with the backbones frozen, cross-attention wins; once you train the backbones, the fully autoregressive (tokens-in-the-sequence) design wins, even though the cross-attention variant has more parameters. MM1 (McKinzie et al. 2024) ranked the design choices by impact: image resolution first, then the encoder's capacity and pre-training data, with "little evidence that architectural decisions of how visual data is fed into the LLM matter". In practice: put the tokens in the sequence, and spend your effort on resolution and data.
LLaVA: the data was the idea¶
In early 2023 there were almost no multimodal instruction-following datasets: VQA datasets have one-word answers, caption datasets have one sentence. LLaVA manufactured one with a text-only GPT-4. For each COCO image, they gave GPT-4 the human-written captions and the bounding boxes as text, plus a few hand-written examples, and asked it to write (a) conversations about the image, (b) detailed descriptions and © complex-reasoning questions with answers, as if it could see. The result, LLaVA-Instruct-158K, had 58K conversations, 23K descriptions and 77K reasoning samples.
Training was two cheap stages on 8 A100s:
- Feature alignment. Freeze CLIP and the LLM (Vicuna); train only \(W\) on 595K filtered CC3M image–caption pairs, one epoch. The connector learns to map image features to vectors that make the frozen LLM say the caption.
- Instruction tuning. Keep CLIP frozen; train \(W\) and the LLM on the 158K instructions for three epochs.
LLaVA-1.5 then showed how far the recipe went with public data: 1.2M samples in total, MLP connector, 336px input, academic VQA datasets mixed in with a response-format prompt ("Answer the question using a single word or phrase.") so short-answer benchmarks did not teach the model to be terse in conversation. The 13B model trained in about one day on one 8-A100 node and reached the state of the art on 11 benchmarks.
Worked example: what stage 1 actually learns
LLaVA-1.5's connector maps 1,024-wide CLIP features to Vicuna-13B's 5,120: a 2-layer MLP of about \(1024\cdot5120 + 5120\cdot5120 \approx 31\)M parameters, trained on 558K captions while 13 billion LLM parameters and 300 million vision parameters stay frozen. That such a small map, trained so briefly, lets a frozen LLM describe images says that the two pre-trained spaces were already nearly linearly related: both encode the same world. Build it below reproduces the effect, including when it fails.
Resolution, tiling and the token budget¶
A fixed 336×336 input is fine for "what animal is this?" and hopeless for a receipt or a spreadsheet screenshot, where each character must cover a few patches. Three families of fixes emerged, and the token counts differ by an order of magnitude:
- Tiling (AnyRes). LLaVA-NeXT (January 2024) picks a grid of 336-pixel tiles that best fits the image's aspect ratio (up to 672×672, 336×1344 or 1344×336), encodes each tile separately, and adds a downscaled overview image: up to \(5\times576 = 2{,}880\) tokens. LLaVA-OneVision (Li et al. 2024) extends the scheme with SigLIP's 729 tokens per 384-pixel crop.
- Native dynamic resolution. Qwen2-VL (Wang et al. 2024) trains its ViT on images at their own resolution (rounded to multiples of 28 pixels), with 2-D rotary position embeddings instead of a fixed grid of learned ones, then merges each 2×2 block of 14-pixel patches into one token with an MLP. One LLM token per 28×28 pixels: a 224×224 image becomes 64 tokens plus two delimiters, 66 in all. This is NaViT's idea (vision transformers) carried into the VLM.
- Pixel shuffle. Idefics3 and InternVL fold each 2×2 neighbourhood of patch features into the channel dimension (space-to-depth), cutting tokens 4× before the MLP. Idefics3 encodes each 364×364 tile as 169 tokens instead of 676.
Position in 2-D (and time). An LLM's RoPE encodes a 1-D position. Flattening an image row by row puts vertically adjacent patches 24 or 100 positions apart. Qwen2-VL's M-RoPE splits the rotary dimensions into temporal, height and width parts: text tokens use the same index for all three (so it reduces to ordinary RoPE), image tokens keep a constant time index and get their row and column, and video frames increment the time index. Positions after an image restart above the largest index used, which also keeps position values small for long videos.
Prefix attention, outputs beyond text, and grounding¶
Most VLMs use the LLM's causal mask throughout. PaliGemma (Beyer et al. 2024) uses a prefix-LM mask instead: image tokens and the text prompt attend to each other in both directions, and only the answer is causal. The image tokens can then "read" the question before the answer begins.
Because the output is text, any structured output can be written as tokens:
- Boxes and masks. PaliGemma adds 1,024 location tokens
<loc0000>…<loc1023>(normalised coordinates in 1,024 bins; four make a box) and 128<seg>tokens that decode to a mask. Kosmos-2 (Peng et al. 2023) grounded phrases to boxes the same way. Qwen2.5-VL (Bai et al. 2025) instead writes absolute pixel coordinates as plain numbers or JSON, which works because its encoder sees the image at its real size. - Points. Molmo (Deitke et al. 2024) trains on pointing data so it can answer "where?" and count by pointing at each instance, which is also the primitive a GUI agent needs to click.
- Actions. RT-2 (Brohan et al. 2023) and OpenVLA (Kim et al. 2024) write robot actions as discretised tokens: a vision-language-action model is a VLM whose vocabulary includes motor commands.
Data: what VLMs are actually trained on¶
The architecture is now commodity; the data decides the model. A modern mix contains:
- Captions, increasingly re-captioned: ShareGPT4V (Chen et al. 2023) showed that replacing short alt-text with dense, detailed captions improves alignment across benchmarks.
- Interleaved web documents, for multi-image reasoning and in-context learning: OBELICS (Laurençon et al. 2023) has 141M web pages with 353M images and 115B text tokens. MM1 found interleaved and text-only data are what preserve few-shot and text abilities, while caption data drives zero-shot captioning.
- OCR, documents, charts, tables, screenshots, often synthetic: render text or charts with known content and ask about them.
- Grounding and pointing data, for boxes and clicks.
- Instruction and reasoning conversations, increasingly with long chains of thought.
- Text-only data, mixed in throughout so the LLM does not forget how to write.
There is a provenance question here. Many open VLMs were trained on descriptions written by proprietary VLMs, which makes them, in Molmo's authors' words, "effectively distillations of proprietary VLMs". Molmo's PixMo dataset avoided this by having annotators speak about each image for 60–90 seconds, then transcribing: 712K images with 1.3M dense descriptions, written by no model. Speaking is faster than typing, and people say more.
Hallucination and the language prior¶
The characteristic VLM failure is describing things that are not there. Ask about a kitchen and the model may mention a refrigerator that is out of frame, because refrigerators and kitchens co-occur in its training data. POPE (Li et al. 2023) measures this with yes/no questions about objects sampled at random, by frequency, or adversarially by co-occurrence; models hallucinate most in the co-occurrence setting.
The cause is visible in the probability: the model's answer combines what the pixels support with a strong language prior learned from text, and when the visual evidence is weak (a small object, low resolution, a token budget that blurred it away), the prior wins. Two benchmark studies make the point from the evaluation side. Cambrian-1 (Tong et al. 2024) evaluated a range of models with the image removed: on MMMU, MathVista, AI2D and ScienceQA-image the score fell by less than 5%, so those benchmarks mostly measure the LLM. "Eyes Wide Shut" (Tong et al. 2024) built MMVP from CLIP-blind pairs, images that CLIP embeds as similar despite obvious differences, and found that GPT-4V and CLIP-based open models fail on the same visual patterns that CLIP does: a VLM cannot see what its encoder cannot distinguish. Mixing in self-supervised DINOv2 features improved visual grounding.
A high multimodal benchmark score is not evidence the model looks
Before trusting a VLM evaluation, run it with the image blanked out. If the score barely moves, you are measuring the language model. The same check catches leakage in your own evals.
History¶
How the field converged
Image captioning with a CNN encoder and an RNN decoder (2014–15) was the first neural VLM, and visual question answering became a benchmark in 2015. Through 2019–2021, BERT-style models (ViLBERT, LXMERT, UNITER) fused region features and text for classification-style tasks. The shift to generative VLMs built on large frozen LMs came in 2021–22: Frozen and ClipCap showed a frozen LM could be prompted with projected visual features, and DeepMind's Flamingo (Jean-Baptiste Alayrac and colleagues, April 2022) showed few-shot multimodal learning at 80B parameters. In April 2023, a month after GPT-4 was announced with image input that the public could not yet use, Haotian Liu, Chunyuan Li, Qingyang Wu and Yong Jae Lee released LLaVA with code, data and weights. Its simplicity made it the template for the open ecosystem; the field then moved on to resolution, data quality and evaluation, and the Qwen, InternVL, Idefics, PaliGemma and Molmo families pushed open models close to the proprietary ones on most benchmarks.
First principles¶
Why can a small connector work at all? A pre-trained ViT and a pre-trained LLM were trained on different data with different objectives, but both had to model the same world, so their representations of a concept are related by something close to a linear map. Merullo et al. 2022 showed that a single linear projection from a frozen image encoder into a frozen LM's input space is enough for captioning, and that how well it works depends on how linguistically aligned the image encoder is (CLIP better than a supervised ResNet better than a self-supervised one). The connector does not need to learn vision; it only needs to learn the change of basis between two existing descriptions of the world. The toy in Build it shows the condition: the training data must contain enough distinct concepts to pin down that map.
Why freeze first? At initialisation the connector outputs noise. Backpropagating that noise into a pre-trained LLM damages it: the LLM learns to ignore the image slot or, worse, degrades its language ability. Training the connector alone first (LLaVA), gating new layers to zero (Flamingo's \(\tanh(\alpha)\)), or warming up the encoder's learning rate slowly (PaliGemma) are the same idea: never let an untrained component send large gradients into a trained one.
Why is the token count the central cost? Everything after the connector is an LLM forward pass, and its cost is linear in sequence length for the MLPs and quadratic for attention. A 4,958-token page costs a 7B model about 69 TFLOPs of prefill before it writes a word (Build it). That is why every design trades resolution against tokens, and why token reduction (resamplers, 2×2 merges, pixel shuffle) is the most active engineering area.
Why do VLMs hallucinate? Write the model's answer distribution, loosely, as \(p(a\mid \text{image}, q) \propto p(a\mid q)\;\frac{p(\text{image features}\mid a, q)}{p(\text{image features}\mid q)}\). The first factor is the language prior, learned from trillions of text tokens; the second is the visual evidence, learned from far less data and limited by what the encoder preserved. When the evidence ratio is near 1 (the object is small, or blurred away by the token budget, or a CLIP-blind detail), the prior decides. More resolution and better encoders raise the evidence; preference tuning against hallucinated answers lowers the prior's weight.
The maths¶
The projector path. Image \(\mathbf{x}\), vision encoder \(g\) producing \(N_v\) patch features of width \(d_v\), connector \(c\), LLM token embeddings \(\mathbf{e}(\cdot)\) of width \(d\):
For LLaVA-1.5-13B: \(N_v = N'_v = 576\), \(d_v = 1024\), \(d = 5120\). With a 2×2 merge (Qwen2-VL), each group of four neighbouring rows of \(Z_v\) is concatenated to width \(4d_v\) before the MLP, so \(N'_v = N_v/4\).
The training loss. The sequence is \([\,\mathbf{e}(t_{1:m}),\, H_v,\, \mathbf{e}(q),\,\mathbf{e}(a_{1:T})\,]\) (system text, image, question, answer). Only answer tokens are scored:
which in code means setting the label of every non-answer position to the ignore index. In stage 1 only the connector's parameters receive gradients; in stage 2 the LLM's do as well.
Gated cross-attention (Flamingo). With text hidden states \(\mathbf{y}\) and visual tokens \(X_v\), each new block computes
then the frozen LM layer. With \(\alpha = 0\) the block is the identity.
Learned-query resampling (Perceiver Resampler, Q-Former). With \(K\) learned queries \(Q\in\mathbb{R}^{K\times d}\), a few layers of \(Q \leftarrow Q + \operatorname{Attn}(Q, [X_v; Q], [X_v; Q])\), \(Q \leftarrow Q + \operatorname{FFW}(Q)\) reduce any \(N_v\) to \(K\) tokens (64 in Flamingo, 32 in BLIP-2). Cost per layer is \(O(K N_v d)\) instead of \(O(N_v^2 d)\).
Token counts. For patch size \(p\), merge factor \(m\) per side and an image resized to \(H\times W\) (multiples of \(pm\)):
Qwen2-VL: \(p = 14\), \(m = 2\), so one token per \(28\times28\) pixels; Idefics3: \(p = 14\), \(m=2\) by pixel shuffle on 364-pixel tiles, \(26^2/4 = 169\) per tile.
M-RoPE. For a token with position triple \((t, h, w)\), split the rotary frequency pairs into three groups and rotate group 1 by angle \(t\,\theta_j\), group 2 by \(h\,\theta_j\), group 3 by \(w\,\theta_j\). The attention score between two tokens then depends on their relative time, row and column offsets separately. For text, $t = h = w = $ the 1-D position, recovering RoPE.
Prefill cost. A dense decoder with \(P\) parameters spends about \(2P\) FLOPs per token in the forward pass, so an image of \(N\) tokens costs \(\approx 2PN\) FLOPs to prefill (plus attention's \(O(N^2 d L)\) term, which dominates only for very long sequences). See compute maths.
Build it¶
First, the token budget. This compares how four VLM families turn the same images into LLM tokens (simplified from their preprocessing code; LLaVA-NeXT's count ignores its row-separator tokens).
import math
def llava15(w, h): # resize/pad to 336x336, ViT-L/14 -> 24x24 patches
return 24 * 24
def llava_next(w, h, grids=((2, 2), (1, 2), (2, 1), (1, 3), (3, 1), (1, 4), (4, 1))):
"""AnyRes: pick the 336-px tile grid that keeps the most resolution, wastes least."""
best = None
for rows, cols in grids:
gw, gh = 336 * cols, 336 * rows
s = min(gw / w, gh / h)
eff = min(w * s * h * s, w * h)
key = (eff, -(gw * gh - eff))
if best is None or key > best[0]:
best = (key, rows * cols)
return 576 * (1 + best[1]) # tiles + one downscaled overview (ignoring newline tokens)
def qwen2vl(w, h, max_tokens=16384, min_tokens=4):
"""Simplified smart_resize: snap to multiples of 28 px; one token per 28x28 (2x2 merged 14-px patches)."""
H, W = round(h / 28) * 28, round(w / 28) * 28
if H * W > max_tokens * 784:
b = math.sqrt(h * w / (max_tokens * 784)); H, W = math.floor(h / b / 28) * 28, math.floor(w / b / 28) * 28
if H * W < min_tokens * 784:
b = math.sqrt(min_tokens * 784 / (h * w)); H, W = math.ceil(h * b / 28) * 28, math.ceil(w * b / 28) * 28
return (H // 28) * (W // 28) + 2 # + <|vision_start|>, <|vision_end|>
def idefics3(w, h, tile=364, longest=1820):
"""Resize longest side to <= 1820, cut 364-px tiles; pixel shuffle: 26x26 -> 169 tokens each."""
s = min(1.0, longest / max(w, h)); w, h = w * s, h * s
tiles = math.ceil(w / tile) * math.ceil(h / tile)
return 169 * (tiles + (1 if tiles > 1 else 0)) # + global downscaled image
images = {"thumbnail 336x336": (336, 336), "photo 1024x768": (1024, 768),
"screenshot 1920x1080": (1920, 1080), "A4 page @200dpi 1654x2339": (1654, 2339)}
print(f"{'image':28s}{'LLaVA-1.5':>10s}{'LLaVA-NeXT':>11s}{'Qwen2-VL':>10s}{'Idefics3':>10s}")
for name, (w, h) in images.items():
print(f"{name:28s}{llava15(w,h):10d}{llava_next(w,h):11d}{qwen2vl(w,h):10d}{idefics3(w,h):10d}")
n = qwen2vl(1654, 2339)
print(f"\nprefill for one A4 page into a 7B LLM: {n} tokens x 2 x 7e9 = {2*7e9*n/1e12:.0f} TFLOP;"
f" attention matrix {n*n/1e6:.0f}M entries per head per layer")
Output:
image LLaVA-1.5 LLaVA-NeXT Qwen2-VL Idefics3
thumbnail 336x336 576 1728 146 169
photo 1024x768 576 2880 1001 1690
screenshot 1920x1080 576 2880 2693 2704
A4 page @200dpi 1654x2339 576 2880 4958 4225
prefill for one A4 page into a 7B LLM: 4958 tokens x 2 x 7e9 = 69 TFLOP; attention matrix 25M entries per head per layer
Read the columns as design philosophies. LLaVA-1.5 pays the same 576 tokens for a thumbnail and a document page: wasteful for the first, blind for the second (squeezed to 336 pixels, an A4 page's 10-point body text is about 4 pixels from ascender to descender). AnyRes spends 1,728 tokens upsampling a thumbnail it cannot improve. Native resolution (Qwen2-VL) scales cost with pixels: 146 tokens for the thumbnail, nearly 5,000 for the page. Pixel shuffle (Idefics3) lands in between. None is free: the page costs 69 TFLOPs of prefill, about 60× the thumbnail.
Second, the connector. A frozen "LLM" embeds 60 concepts; a frozen "vision encoder" sees noisy photos of them in a different space. Both are generated from a shared 16-dimensional hidden meaning, standing in for "both models learned the same world". We fit the connector, one linear map with a bias, by least squares on photos of the first few concepts, then test on 20 concepts it has never seen: does the projected photo land nearest the right word?
import numpy as np
rng = np.random.default_rng(0)
# 60 concepts share a hidden 16-d "meaning". A frozen LLM embeds each concept's word in 64-d;
# a frozen vision encoder sees noisy images of it in 48-d. Neither space was built for the other.
n_concepts, k, d_llm, d_vis = 60, 16, 64, 48
meaning = rng.standard_normal((n_concepts, k))
word_emb = meaning @ rng.standard_normal((k, d_llm)) + 0.3 * rng.standard_normal((n_concepts, d_llm))
B = rng.standard_normal((k, d_vis))
def vision(c, n): # n noisy "photos" of concept c
return (meaning[c] + 0.4 * rng.standard_normal((n, k))) @ B + 0.5 * rng.standard_normal((n, d_vis))
def nearest_word(v): # which LLM token is this vector closest to?
a = v / np.linalg.norm(v, axis=1, keepdims=True)
b = word_emb / np.linalg.norm(word_emb, axis=1, keepdims=True)
return np.argmax(a @ b.T, axis=1)
test = np.arange(40, 60) # 20 concepts never shown to the connector
Xt = np.vstack([vision(c, 20) for c in test]); yt = np.repeat(test, 20)
print("concepts seen | linear connector: acc on UNSEEN concepts | random connector")
for n_train in [4, 8, 16, 24, 40]:
train = np.arange(n_train)
X = np.vstack([vision(c, 20) for c in train]) # (20 n_train, 48) image features
Y = np.repeat(word_emb[train], 20, axis=0) # target: the caption word's embedding
W, *_ = np.linalg.lstsq(np.c_[X, np.ones(len(X))], Y, rcond=None) # the whole "projector"
acc = np.mean(nearest_word(np.c_[Xt, np.ones(len(Xt))] @ W) == yt)
rnd = np.mean(nearest_word(Xt @ rng.standard_normal((d_vis, d_llm))) == yt)
print(f"{n_train:13d} | {acc:39.2f} | {rnd:16.2f}")
Output:
concepts seen | linear connector: acc on UNSEEN concepts | random connector
4 | 0.00 | 0.04
8 | 0.18 | 0.00
16 | 0.87 | 0.01
24 | 0.98 | 0.02
40 | 1.00 | 0.03
Chance is 1/60. With 4 or 8 training concepts the connector memorises a few directions and fails on new concepts. At 16, the dimension of the shared meaning, the map is pinned down and generalises to concepts it never saw (87%); by 24 it is essentially perfect. That is the mechanism behind LLaVA's stage 1, in miniature: the connector learns a change of basis between two spaces, not a lookup table, so it generalises exactly when the alignment data spans the space. Real stage-1 data has hundreds of thousands of captions for the same reason.
Things to try
- Break linearity. Replace the vision features with
np.tanh(...)of themselves. How many concepts does a linear connector need now? Fit a 2-layer MLP (NumPy, a few hundred steps of gradient descent) and compare: this is LLaVA-1.5's linear-to-MLP upgrade. - A weaker encoder. Add a component to
visionthat has nothing to do withmeaning(say3.0 * rng.standard_normal(...)). Accuracy falls: language-aligned encoders matter. - Token budget. Extend
qwen2vlwithmax_tokens=1280(a common deployment cap). What resolution does the A4 page get, and how tall is a 10-point line of text then? - Blind baseline. Take any VLM you can run (via
transformersormlx-vlm), ask it 20 questions about images with the images replaced by a grey square, and score it. Repeat with the real images. The difference is what your benchmark actually measures.
In practice¶
- Pick by task. For documents, charts and screenshots, prefer models with native or tiled high resolution and OCR-heavy training (the Qwen-VL family, InternVL, Idefics3-style models) and budget the tokens. For grounding and counting, models trained with points or boxes (Molmo, PaliGemma, Qwen2.5-VL and later). For small-device use, 2–4B models with SigLIP encoders.
- Set the resolution deliberately. Most serving stacks let you cap pixels or tokens per
image. Too low and text vanishes; too high and latency and cost explode. Measure accuracy
against
max_pixelson your own documents. - Put the image first, the question after. Most models were trained that way. For multiple images, label them in text ("Image 1:", "Image 2:") so you can refer to them.
- Ask for structure. Coordinates, JSON fields and lists are more reliable than prose for extraction, and are checkable. Validate the output schema (structured outputs).
- Evaluate with ablations. Blank-image baselines, swapped-image controls ("does the answer change when the image does?") and adversarial co-occurrence questions catch hallucination that aggregate accuracy hides (evals in practice).
- Fine-tuning. Usually freeze the vision encoder and train the connector plus LoRA adapters on the LLM (LoRA); keep some general instruction data in the mix so the model does not forget how to converse.
Common misconceptions¶
\"The VLM sees the image\"
It sees what the encoder kept, at the resolution the preprocessor chose, compressed by the connector. If a detail was lost at any of those stages, no amount of prompting recovers it, and the language prior will often fill the gap with something plausible.
\"Bigger vision encoders are the main lever\"
Idefics2's Finding 1: for a fixed parameter budget, the language backbone matters more than the vision backbone. MM1 ranks resolution above encoder size. A larger encoder at low resolution often loses to a smaller one at high resolution.
\"Natively multimodal means no vision encoder\"
"Native" usually describes training (images present from early pre-training, sometimes with image outputs), not the absence of an image encoder. Most such systems still turn pixels into continuous or discrete tokens with a dedicated encoder or tokenizer.
Check yourself¶
Why do VLMs use the ViT's patch features rather than CLIP's pooled embedding?
The pooled embedding is one vector optimised to match a caption; it discards where things are and most fine detail (text, small objects, counts). The patch grid keeps one vector per region, so the LLM can attend to the part of the image a question is about.
Flamingo initialises its gates with α = 0. What would go wrong with α = 1?
The freshly initialised cross-attention would add large random vectors to every hidden state of the frozen LM from the first step. Its outputs would be garbage, and the gradients from that garbage would train the new layers in a bad regime. With \(\tanh(0) = 0\) the model starts as the exact original LM and learns how much vision to let in.
A 1920×1080 screenshot goes into a Qwen2-VL-style model (one token per 28×28 pixels). How many visual tokens, roughly, and what would a 2×2 → 3×3 merge change?
\(1092/28 = 39\) rows and \(1932/28 = 69\) columns after rounding: \(39\times69 = 2{,}691\) tokens (plus two delimiters). A 3×3 merge (one token per 42×42 pixels) would give about \(26\times46 = 1{,}196\): 2.25× cheaper, but each token now summarises a region larger than a line of small UI text.
In LLaVA's stage 1, why train only the projector?
The projector starts random, so its outputs are noise. If the LLM were trainable, it would be updated by gradients caused by that noise and could learn to ignore the image slot or lose language ability. Training only the projector first aligns the visual tokens with the LLM's input space; once they carry meaning, unfreezing the LLM is safe and useful.
Why does LLaVA-1.5 add 'Answer the question using a single word or phrase.' to VQA training data?
Academic VQA datasets have one- or two-word answers. Mixed without a cue, they teach the model to answer everything tersely, damaging conversation. The format prompt makes the brevity conditional on an explicit instruction, so the model learns both behaviours.
Cambrian-1 found MMMU drops by less than 5% when the image is removed. What does that tell you, and how would you build a benchmark that avoids it?
MMMU mostly measures the LLM's knowledge and reasoning; many questions are answerable from the text (or guessable from the options). A vision-centric benchmark needs questions whose answers are not predictable from text: e.g. paired images that differ in one visual property (MMVP's CLIP-blind pairs), counting, spatial relations, or reading text that appears only in the image, plus a blind baseline reported alongside every score.
Hard: when would you choose cross-attention over putting image tokens in the sequence?
When the LLM must stay frozen (Idefics2's Finding 2: cross-attention wins with frozen backbones), when text-only behaviour must be preserved exactly (gates at zero), or when images are many and long-lived (video, many-image documents) so that keeping them out of the self-attention sequence and its KV cache saves memory. The cost is extra parameters and weaker interaction between image and text at every layer.
Hard: in the connector toy, accuracy on unseen concepts jumps between 8 and 16 training concepts. Explain the threshold.
Both spaces are (noisy) linear images of a 16-dimensional meaning space. A linear map fitted on \(n\) concepts only learns how the map acts on the span of those \(n\) meaning vectors; with \(n < 16\), a new concept's meaning has components outside that span, which the least-squares fit maps arbitrarily. Once the training concepts span all 16 directions, the map is determined everywhere and generalises. Real alignment data must likewise cover the space of visual concepts, which is why stage 1 uses hundreds of thousands of varied captions rather than a few hundred.
Go deeper¶
Papers
- Visual Instruction Tuning — Liu, Li, Wu and Lee, 2023 (LLaVA); and Improved Baselines with Visual Instruction Tuning — Liu et al., 2023 (LLaVA-1.5). Section 3 of the first is the data trick; the second is the recipe everyone copied.
- Flamingo: a Visual Language Model for Few-Shot Learning — Alayrac et al., 2022. Section 2 and Figure 4 for gated cross-attention and the resampler; the ablation table for what mattered.
- BLIP-2 — Li, Li, Savarese and Hoi, 2023. The Q-Former and its two-stage training.
- What matters when building vision-language models? — Laurençon et al., 2024 (Idefics2). Six findings, each backed by an ablation: the best single paper on VLM design.
- MM1: Methods, Analysis & Insights from Multimodal LLM Pre-training — McKinzie et al., 2024. What the data mix does.
- Qwen2-VL — Wang et al., 2024. Naive dynamic resolution and M-RoPE; follow with the Qwen3-VL report (2025).
- PaliGemma: A versatile 3B VLM for transfer — Beyer et al., 2024. Prefix-LM, location tokens, and unusually honest ablations.
- Molmo and PixMo — Deitke et al., 2024. Open data without distillation; pointing.
- Cambrian-1 — Tong et al., 2024; and Eyes Wide Shut? — Tong et al., 2024. How VLM benchmarks mislead, and what VLMs cannot see.
- Chameleon: Mixed-Modal Early-Fusion Foundation Models — Chameleon Team, 2024. The early-fusion alternative and why it is hard to train.
Videos and lectures
- Stanford CS231N, Spring 2025, Lecture 16: Vision and Language — The university survey of the area.
- Coding a Multimodal (Vision) Language Model from scratch in PyTorch — Umar Jamil. Builds PaliGemma (SigLIP + Gemma) line by line in about six hours.
- Lucas Beyer: Vision in the Age of LLMs — ETH Zürich Robot Learning, 2026. A PaliGemma/SigLIP author on where vision fits now.
Articles and blog posts
- Understanding Multimodal LLMs — Sebastian Raschka. The two main architectures compared, with a survey of recent models.
- Multimodality and Large Multimodal Models — Chip Huyen, 2023. CLIP to Flamingo, explained for engineers.
- Vision Language Models (Better, faster, stronger) — Hugging Face, 2025. A map of the 2025 landscape: any-to-any models, reasoning, small VLMs, agents.
- Generalized Visual Language Models — Lilian Weng, 2022. The pre-LLaVA history in one place.
Code
- huggingface/nanoVLM — A small, readable VLM (SigLIP + small LM + pixel-shuffle connector) you can train on one GPU.
- haotian-liu/LLaVA — The reference implementation and data.
- QwenLM/Qwen3-VL — Production-grade open VLM code, including the resizing logic.
Where this leads¶
- Video and world models — the same encoders over time, and models that generate rather than describe.
- Computer-use and long-horizon agents — VLMs reading screens and pointing at what to click.
- Embodied AI and robotics — vision-language-action models.
- Speech and audio — the same encoder-plus-LLM pattern for sound.
- Evals in practice — building evaluations that would catch a VLM not looking.