How vision-language systems connect visual representations with language models to describe images, answer questions, and process multimodal prompts.
A Vision-Language Model (VLM) accepts visual and language inputs and produces outputs conditioned on both. The term covers multiple architectures: some connect separately pretrained components, while others train multimodal components jointly.
One engineering challenge is the interface. Images begin as spatial arrays of continuous pixel values, while language models consume sequences of vectors associated with discrete tokens. A VLM needs a defined path that turns visual evidence into features the downstream predictor can use.
Here's the entire VLM pipeline in concrete tensor shapes (we'll unpack each box in later chapters):
Watch projected image features and text embeddings form one LLaVA-style input sequence. The teal nodes are visual, orange nodes are textual.
The vision encoder converts a raw image into a sequence of feature vectors. The systems studied here commonly use a ViT (Vision Transformer): split the image into fixed-size patches, embed each patch, add position information, and process the sequence with transformer layers.
The output has a sequence axis like text embeddings, but its feature width and learned representation can differ. LLaVA's connector supplies the language model's required width before concatenation.
Let's trace the shapes for LLaVA-1.5's CLIP ViT-L/14@336. It takes a 336×336 image and uses 14×14 pixel patches:
See how an image is sliced into patches. Each patch becomes a token for the transformer. Adjust patch size to see the trade-off between resolution and sequence length.
| Published system | Vision component | Relevant output handling |
|---|---|---|
| Original LLaVA | CLIP ViT-L/14 | Selected grid features, class token excluded; width 1024 |
| LLaVA-1.5 | CLIP ViT-L/14@336 | Layer -2 patch features; 576 positions, width 1024 |
| Flamingo | Frozen contrastively trained NFNet-F6 | Flattened feature grid enters a 64-output Perceiver Resampler |
| Qwen-VL | OpenCLIP ViT-bigG initialization | Single-layer 256-query visual receptor |
| Qwen2-VL | 675M ViT trained for image/video | 2D-RoPE and adjacent 2×2 token merge |
LLaVA-1.5's released configuration selects layer -2 patch features. CLIP's transformer retains a state at every token position; its separate global image representation selects the class-token state and applies a learned projection.
Where else do you see the same encoder used with different amounts of its output? (Hint: think about how the Transformer lesson shows hidden states at every layer.)
672/14 = 48 patches per side, so 48×48 = 2,304 tokens, each of dimension 1024 in this illustration. That is 4× as many positions as the 336-pixel case. A plain full-attention grid therefore compares 23042/5762 = 16× as many position pairs; end-to-end runtime also depends on the implementation and hardware.
If patch size changes to 28×28, the grid becomes (672/28)2 = 24×24 = 576 positions. Each patch covers 28×28×3 = 2,352 pixel values instead of 588, producing a coarser spatial grid with fewer attention pairs. Measure task accuracy to determine how that change affects fine details.
A pretrained vision encoder and language model can expose different feature widths and interfaces. LLaVA therefore uses a learned connector before supplying visual features to the language model.
Original LLaVA uses one linear projection; LLaVA-1.5 uses a two-layer MLP; Flamingo combines a Perceiver Resampler with gated cross-attention. Each interface produces the features its downstream language component consumes; none requires a patch to correspond to one word.
LLaVA-1.5 uses a 2-layer MLP to project from CLIP's 1024-dim space to Vicuna-13B's 5120-dim space:
| Connector | Verified configuration | Visual outputs | Example |
|---|---|---|---|
| Linear | 1024→5120, about 5.25M parameters for Vicuna-13B | 256 at CLIP@224 | Original LLaVA |
| Two-layer MLP | 1024→dLLM→dLLM; about 31.5M for d=5120 | 576 at CLIP@336 | LLaVA-1.5-13B |
| Perceiver Resampler | Learned latents cross-attend to a variable visual feature map | 64 | Flamingo |
| Visual receptor | Cross-attention with learned query embeddings | 256 | Qwen-VL |
The real connector maps 1024 dimensions to 5120. This two-dimensional sketch isolates one property of a learned linear map: changing its weights moves every input point coherently.
The official LLaVA projector builder implements mlp2x_gelu as Linear(vision width, LLM hidden width) → GELU → Linear(LLM hidden width, LLM hidden width). For CLIP width 1024 and Vicuna-13B width 5120, calculate the parameter count including biases.
Layer 1 has 5,248,000 parameters. Layer 2 has 26,219,520. Total: 31,467,520 ≈ 31.5M, about 0.24% of a nominal 13-billion-parameter LLM. A 4096-wide version has about 21.0M parameters and matches a 7B-width LLaMA/Vicuna model, not Vicuna-13B.
mlp2x_gelu connector. The module takes [batch, n_patches, vision_dim] and outputs [batch, n_patches, llm_dim]. This connector preserves token count.python import torch import torch.nn as nn class VisionProjection(nn.Module): def __init__(self, vision_dim: int, llm_dim: int): super().__init__() self.mlp = nn.Sequential( nn.Linear(vision_dim, llm_dim), # 1024 -> 5120 nn.GELU(), nn.Linear(llm_dim, llm_dim), # 5120 -> 5120 ) def forward(self, x: torch.Tensor) -> torch.Tensor: # x: [batch, n_patches, vision_dim] return self.mlp(x) # [batch, n_patches, llm_dim]
Once visual and text features are available, the model needs an explicit route for information to cross modalities. Published systems use several distinct routes:
| Mechanism | How it works | Published example |
|---|---|---|
| Visual-prefix fusion | Project visual features and concatenate them with text embeddings for a causal LLM | LLaVA |
| Gated cross-attention | Language queries attend to resampled visual keys and values in new blocks | Flamingo |
| Learned-query compression | Queries cross-attend to a visual feature map to produce a fixed-length interface | Flamingo Perceiver; Qwen-VL receptor |
| Native dynamic-resolution prefix | A vision transformer produces variable-length visual sequences for an LLM | Qwen2-VL |
Toggle between strategies to see how vision (teal) and text (orange) tokens interact.
In early fusion, the LLM's self-attention sees a sequence like [v1, v2, ..., v576, t1, t2, ..., t50]. Because it's causal attention:
Each approach makes fundamentally different engineering choices about what's frozen, what's trained, and how vision enters the LLM:
| Model | Visual interface | Frozen during reported multimodal training? | Visual outputs |
|---|---|---|---|
| LLaVA-1.5-13B | Two-layer MLP into Vicuna-13B | CLIP frozen; Vicuna tuned in Stage 2 | 576 patch features |
| Flamingo-80B | Perceiver Resampler + gated cross-attention/dense blocks | NFNet-F6 and Chinchilla-70B frozen; new blocks trained | 64 resampler outputs |
| Qwen-VL | 256-query visual receptor into Qwen-7B | Freeze policy changes across its three training stages | 256 query outputs |
Flamingo first maps a variable visual feature map to 64 outputs with a Perceiver Resampler. Its newly initialized gated cross-attention blocks are inserted between frozen language-model blocks. Identify the source of Q, K, and V.
Q comes from language hidden states. K and V come from the resampled visual outputs. All of these projections belong to the newly added cross-attention block; Q and O are not reused from the frozen language model. Exact widths, insertion frequency, and parameter counts differ across Flamingo-3B, -9B, and -80B.
Visual instruction tuning trains on image, instruction, and response examples so the model learns the response formats represented in that data.
Original LLaVA supplements image-caption alignment with conversational, detailed-description, and complex-reasoning examples. This broadens the supervised task distribution; it does not guarantee general behavior outside that distribution.
Caption alignment trains a different interface from instruction following: it rewards likely captions, not responses to arbitrary user requests. It may still acquire some reasoning capability from pretrained components, but caption data alone does not directly teach the conversational instruction-response format evaluated by LLaVA.
| Training format | Direct supervision | What it does not directly supervise |
|---|---|---|
| Image-caption pairs | Generate or match a caption for an image | Responses to varied user instructions |
| VQA pairs | Answer questions from a task dataset | Open-ended dialogue outside that format |
| Instruction-response data | Follow the included instruction distribution | Guaranteed behavior on unseen tasks |
During instruction tuning, the model receives a sequence like:
format [IMG_1] [IMG_2] ... [IMG_576] [SYS] You are a helpful assistant. [USR] What animal is in this image? [ASST] # Loss is computed ONLY on the assistant's response tokens: "This image shows a golden retriever lying on grass..." # Vision/prompt positions are excluded from direct target loss # Gradients can still flow through their contribution to response predictions # Assistant tokens: standard next-token prediction loss
See the variety of tasks a VLM must handle. Click to cycle through instruction types.
Let E contain visual-prefix embeddings followed by system, user, and assistant token embeddings. Only assistant response tokens have vocabulary targets in this objective.
Your task: Define the labels, apply the causal one-position shift, normalize over valid labels, and explain why target masking does not detach the prefix.
Full derivation:
For sequence length L, define yj = -100 at image, system, and user positions and let yj be the assistant vocabulary token ID at response positions.
Let M be the number of valid shifted labels. Then L = -(1/M) ∑i=0L-2 1[yi+1 ≠ -100] log pθ(yi+1 | E≤i).
In tensor code, use logits[:, :-1] against labels[:, 1:], ignore -100, and divide the summed loss by the valid shifted-label count.
The key insight: The mask removes direct cross-entropy targets. It does not detach visual or prompt states. Assistant-token loss can still backpropagate through attention into trainable upstream components such as the projector.
Original LLaVA (2023) connected CLIP ViT-L/14 to Vicuna with one linear projection. LLaVA-1.5 later changed the worked configuration used below: CLIP ViT-L/14@336, 576 selected patch features, and a two-layer MLP connector.
For LLaVA-1.5-13B, each 1024-wide patch feature is projected to Vicuna-13B's 5120-wide input space, concatenated with text embeddings, and processed by the causal language model.
Watch tokens flow through the architecture. Teal = vision, orange = text, green = output.
Let's trace exactly what the LLM receives. For a question like "What is in this image?":
End-to-end latency depends on hardware, precision, kernels, batch size, prompt length, and output length. Vision encoding and prompt prefill run mostly in parallel over their input positions; autoregressive decoding is sequential across generated tokens. Measure all three on the target deployment before naming a bottleneck.
Original LLaVA uses a two-stage recipe. Other VLM families use different stage counts and freeze policies:
| Stage | Data | What Trains | Purpose |
|---|---|---|---|
| 1. Pretraining alignment | 595K image-caption pairs | Projection only | Align vision ↔ language spaces |
| 2. Instruction tuning | 158K visual conversations | Projection + LLM | Teach instruction following |
| Component | Approx. params | Stage 1 | Stage 2 |
|---|---|---|---|
| CLIP ViT-L/14 | 304M | Frozen | Frozen |
| Linear projector 1024→5120 | 5.25M | Training | Training |
| Vicuna-13B | 13B | Frozen | Training |
Toggle stages to see which components are frozen (blue/frozen) vs trainable (green/active).
Grounding means connecting words to specific regions in the image. When a VLM says "the red car on the left," grounding means it can also point to where that car is. This requires the model to output spatial coordinates, not just text.
Approaches include: outputting bounding box coordinates as text tokens (e.g., "[0.2, 0.3, 0.5, 0.7]"), using special location tokens, or predicting segmentation masks. Models like Kosmos-2 and Shikra showed VLMs can be trained to both describe and locate objects.
| Level | Output | Example Task | Difficulty |
|---|---|---|---|
| Pointing | Single (x, y) coordinate | "Point to the cat's nose" | Easiest — one point |
| Bounding box | (x1, y1, x2, y2) | "Draw a box around each person" | Medium — 4 numbers per object |
| Segmentation | Pixel-level mask | "Segment the dog from background" | Hardest — needs a mask decoder |
Click on regions to see how a VLM grounds language to spatial locations. Each colored box is a detected object with its label.
Grounding formats are model-specific. Shikra emits coordinates in natural-language form without adding a vocabulary; Kosmos-2 represents boxes with dedicated location tokens; Qwen-VL normalizes box coordinates to [0,1000), tokenizes the coordinate string as text, and wraps it with special boundary tokens. The example below illustrates the Qwen-VL-style numeric format:
example output # Input: "Where is the dog in this image?" # Output: The dog is on the left side of the image. <box>(102,384),(298,571)</box> # Coordinates: (x1, y1), (x2, y2), each in [0, 1000) # Real position: top-left (10.2%, 38.4%) to bottom-right (29.8%, 57.1%)
Documents are a special challenge for VLMs: they contain dense text, tables, charts, and layouts where spatial arrangement matters. "Revenue" next to "$5M" means something different from "Revenue" in a section header.
Key innovations: high-resolution encoding (documents need more pixels than photos), OCR-free reading (the vision encoder learns to read text directly), and layout-aware attention (understanding that rows and columns create relationships).
A standard document page at 300 DPI is roughly 2,550 × 3,300 pixels. A VLM at 336×336 resolution shrinks this by 10× in each dimension — a 12-point font becomes 1-2 pixels tall. Completely unreadable. This is why document understanding requires special resolution handling:
| Approach | Mechanism | Cost characteristic |
|---|---|---|
| Global resize | Resize the full page to one encoder input | Fixed token count; small glyphs may disappear |
| Tiling / sub-image decomposition | Encode a global view plus multiple crops or tiles | Token count grows with selected tiles |
| Native dynamic resolution | Map different input sizes to different visual sequence lengths | Variable token count bounded by implementation limits |
| Token merging or pruning | Reduce encoded visual positions before the LLM | Compute/accuracy trade-off must be measured per model |
A VLM must understand that spatial layout encodes meaning. Watch how different regions are classified.
| Published system | Document-relevant mechanism | Claim scope |
|---|---|---|
| Nougat | Vision encoder-decoder OCR from scientific document images to markup | Scientific-document transcription and markup |
| Qwen-VL | 448-pixel multi-task training including OCR and document VQA data | Named text-oriented VQA benchmarks in its paper |
| Qwen2-VL | Native dynamic resolution with variable visual-token counts | DocVQA, ChartQA, InfoVQA, TextVQA, AI2D and OCRBench evaluations |
| Qwen2.5-VL | Dynamic resolution plus window attention and document omni-parsing data | Technical-report evaluations; version-specific |
Published VLM evaluations report errors on small details, object presence, counts, spatial relations, documents, and video. An observed error category does not identify one architectural cause.
| Observed failure | Plausible contributors to test | Useful control |
|---|---|---|
| Small-detail or counting error | Input resolution, preprocessing, encoder features, data, or decoding | Hold the model fixed and vary only resolution or crop policy |
| Object hallucination | Visual ambiguity, language priors, data, alignment, optimization, or decoding | Add or remove the queried object in counterfactual images |
| Spatial-relation error | Representation, supervision, prompt, or benchmark ambiguity | Use matched scenes with one relation changed |
| Long video or document failure | Sampling, visual-token budget, context length, retrieval, or compression | Report the exact preprocessing and ablate token reduction |
The examples below are dated reference points from public papers and technical reports. Capabilities and architectures vary by system and version.
| System | Published mechanism | Version scope |
|---|---|---|
| Original LLaVA | CLIP ViT-L/14 + linear projector + Vicuna | 2023 paper |
| LLaVA-1.5 | CLIP ViT-L/14@336 + two-layer MLP connector | 2023 improved-baselines paper/repo |
| Flamingo | Frozen NFNet-F6 and LM; 64-output Perceiver Resampler; new gated text-to-vision cross-attention blocks | 2022 paper |
| Qwen2-VL | Naive Dynamic Resolution, 2D-RoPE, 2×2 visual-token merge, M-RoPE | 2024 paper |
| Qwen2.5-VL | Native dynamic resolution, window attention, dynamic frame-rate sampling, absolute-time MRoPE | 2025 technical report |
Several published VLMs use tiling or variable-length visual sequences instead of one fixed square resize. The exact supported sizes, aspect ratios, token limits, and reduction methods are model-specific.
This arithmetic isolates how a plain 14-pixel patch grid grows before model-specific tiling, merging, pruning, or window attention:
| Idealized square input | 14px patch grid | Patch positions | Full-grid pair count vs 224 |
|---|---|---|---|
| 224 × 224 | 16 × 16 | 256 | 1× |
| 336 × 336 | 24 × 24 | 576 | 5.06× |
| 672 × 672 | 48 × 48 | 2,304 | 81× |
| 1344 × 1344 | 96 × 96 | 9,216 | 1,296× |
These counts measure positions and position pairs in one uncompressed grid. OCR accuracy and runtime require separate measurements for the chosen tiling, windowing, merging, or pruning implementation.
A naïve frame-by-frame count grows linearly with sampled frames. Published video systems use model-specific sampling and spatial or temporal reduction.
| Illustrative input | Frames | Raw count at 576 positions/frame | Interpretation |
|---|---|---|---|
| Single image | 1 | 576 | Before any model-specific compression |
| 4 sampled frames | 4 | 2,304 | Linear growth in this naïve count |
| 1 FPS for 30 seconds | 30 | 17,280 | Motivates temporal/spatial reduction |
| 30 FPS for 10 seconds | 300 | 172,800 | Production systems generally do not pass every raw frame this way |
VLMs connect to many other topics:
• CLIP & Contrastive Learning — Original LLaVA and LLaVA-1.5 reuse CLIP visual features; other VLM families use different encoders or joint training.
• VLAs (Vision-Language-Action) — RT-2 is one published recipe that serializes robot actions as text tokens; other VLA interfaces differ.
• Transformers — The case studies here use transformer components, including ViT and causal language models.
• Diffusion Models — Multimodal systems can connect language-conditioned representations to image generators, but the generator and interface must be named by model.
You now have a source-grounded way to compare visual interfaces, fusion patterns, training stages, and token budgets across named VLM versions.
RT-2 co-fine-tuned vision-language models on robot trajectories and web-scale vision-language tasks, serializing actions as text tokens in the training data. This demonstrates one VLA recipe; VLA systems can use other action representations and need not share one projector or fusion mechanism.
What other domains could you target by simply changing what the LLM generates? (Hint: think music notation, CAD coordinates, chemical structures...)