← Explainer Library

Interactive Explainer

Vision-Language Models, End to End

Modern VLMs are three boxes glued together (vision encoder, projector, language model) and four training stages (contrastive, image-grounded LM, instruction tuning, preference alignment). A live mini-CLIP makes the contrastive stage concrete, and we close with the calibration trap real VLMs fall into on thermal images.

Prelude

The architecture in three boxes

Every modern VLM — LLaVA, Qwen-VL, Pixtral, GPT-4o, Claude 3.5 with vision — is the same shape:

The modern VLM stack. Frozen vs trained parts vary by training stage — see Step 2.
The slogan. A VLM is a language model that has been taught to read an extra "language" — the language of patch embeddings. Most of the magic is in the encoder; most of the intelligence is in the LLM; the projector is a 60M-parameter translator between them.
Step 1

Stage 1 — Contrastive image-text alignment (CLIP)

Before a VLM can be assembled, the vision encoder usually needs to be aligned with text. The standard recipe is contrastive: train an image encoder $f_I$ and a text encoder $f_T$ so that matched (image, caption) pairs are near in cosine similarity, and unmatched pairs are far.

$\tau$ is a learnable temperature. The loss is symmetric (image-to-text + text-to-image cross-entropy, then averaged). With 400M+ image-text pairs scraped from the web, this learns a remarkably general visual vocabulary — CLIP can zero-shot classify ImageNet at 76% top-1 without ever seeing a labelled ImageNet image during training.

A mini-CLIP, live

Below: 4 toy "image" types (coloured shapes) and 4 textual "captions". A tiny image encoder and tiny text encoder trained jointly with the InfoNCE loss. The 4×4 similarity matrix should pull the diagonal (matched pairs) to high values and push the off-diagonal entries low.

step 0 contrastive loss
Toy data: 4 image types × 4 captions
Cosine similarity matrix (image × text)
Loss curve
What to watch for. Within ~50 steps the diagonal of the similarity matrix should start to glow brighter than the off-diagonal. Drop τ very low (e.g. 0.05) and training becomes unstable (gradients explode); push τ very high (e.g. 1) and the loss never separates pairs (saturates near $\log K$). Real CLIP uses a learnable τ initialised at $0.07$.
Step 1 ½

The image-language interface — projector designs

Once the vision encoder is aligned, every patch becomes a ~1024-dim feature vector. A 224×224 image at patch 14 has 256 such tokens; the LLM might want them in 4096-dim hidden space and may not want all 256. The projector is the small network between the encoder and the LLM that does both jobs. Four designs dominate practice:

The choice has measurable consequences:

DesignImage tokensTrainable paramsStrengthsTrade-offs
Linear / MLP= patch count (256–576)~10MSimplest; preserves spatial infoLong context bill
Q-Former / Resampler32–64 (fixed)~100MConstant cost; trains in a separate stageLossy compression; needs its own pretrain
Cross-attentionhandled in-LLM~1BRichest interaction; LLM sees full token setNeed to modify LLM; expensive train
Tile packing (AnyRes)k × tile-tokens~10MHigh-res; OCR; chartsLarge context; positional encoding tricks
Step 2

Stage 2 — Image-grounded language pretraining

With the encoder aligned, you bolt on the language model. The projector is randomly initialised; the encoder and LLM are loaded pretrained.

Training data: image-caption pairs. Loss: standard next-token cross-entropy on the caption, with image tokens as a prefix context. Encoder and LLM are frozen; only the projector trains. This is cheap (60M params), runs on a handful of GPUs, and produces a model that can describe an image but can't follow much instruction.

Why freeze the LLM here. The projector starts random; if you let gradients flow into the LLM at this stage, the LLM's existing language competence collapses (catastrophic forgetting). Stage 2 gets the projector into the LLM's hidden-state distribution first.
Step 3

Stage 3 — Instruction tuning

Now the model can describe images but can't answer questions about them or follow instructions. Stage 3 fixes that with a curated dataset of triples $(\text{image}, \text{instruction}, \text{response})$. Examples: "Count the people in this photo." "What's the temperature reading on this thermometer?" "Write Python that plots the chart in this image."

Loss: cross-entropy on the response tokens only (the image and instruction tokens are masked out). The projector continues to train; the LLM is now also trained, but with a low learning rate (LoRA on top of the LLM is the most common implementation).

What changes with scale. Frontier VLMs (Gemini, GPT-4o, Claude) bake stages 1-3 together at trillion-token scale, with the encoder, projector and LLM all trained jointly from early in training. The frozen-stage recipe above is the academic-budget LLaVA flavour; it's still the right starting point for any domain-specific VLM you'd build in a lab.
Step 4

Stage 4 — Preference alignment (RLHF / DPO)

The instruction-tuned model still says wrong things, hedges, or refuses unhelpfully. Stage 4 collects preference pairs (human, or from a stronger model) of "this answer is better than that one" and aligns the model to those preferences.

Step 4 ½

Fine-tuning a VLM — recipes that actually work

Most labs don't train a VLM; they fine-tune one. The options form a ladder of cost vs flexibility:

Practical recipe (single-GPU lab fine-tune)

Step 4 ¾

Evaluation — what each benchmark actually measures

A trained VLM number means nothing without knowing the eval. The 2024-2026 standards:

BenchmarkWhat it testsFormatWatch out for
VQAv2 / GQA / OK-VQAOpen-ended visual QA1-word / short phraseTemplated prompts; saturated
MMBench / MMVetBroad capability suiteMulti-choice + free-formEval is itself a (judge) LLM call
MMMUCollege-level multi-discipline reasoningMulti-choiceHeavy on diagram/chart understanding
POPE / HallusionBenchHallucination on objects + scenesYes/no, free-formPolarity bias; need balanced "no" cases
ChartQA / DocVQACharts and document understandingNumeric / extractiveReads OCR; high-res tile packing helps
MathVista / MathVerseVisual mathNumericCalibration on numbers; tool-use wins
MMMU-Pro / Reason-BenchReasoning under image perturbationMulti-choiceRobustness to crop / rotation / colour
RefCOCO / GroundedVQAVisual grounding (output a box)CoordinatesCoordinate format varies wildly
BLINK / Video-MMEVision-only and video tasksMulti-choiceVideo models inherit different biases

Pick 2 broad benchmarks (MMBench + MMMU) and 1 hallucination probe (POPE) as the lab's house metrics; report all three on every checkpoint. The most common deception: "we beat GPT-4 on VQAv2" — VQAv2 has been saturated since 2022 and almost nothing publishes there anymore.

Step 4 ⅞

Image-text retrieval — recall@K, live

The CLIP-aligned encoders also give you free retrieval: take a text query, embed it, find the nearest image embeddings. Recall@K is the fraction of test queries whose true image appears in the top-K retrieved. Watch the live mini-CLIP from Step 1 produce its own retrieval matrix.

Image → text retrieval rank list (live)
Recall@K vs training step
What good retrieval looks like. With four toy categories, the CLIP demo should hit 100% recall@1 within ~80 steps. Real CLIP at scale: ~75–80% recall@1 on Flickr30k with the largest backbones. The drop tells you most of the difficulty is just having more distractors and longer-tailed concepts.
Step 5

The thermal-image trap (and the tool-use fix)

Real VLMs fail spectacularly on thermal imagery. The reason is calibration: a thermal sensor outputs raw temperature per pixel, which is then mapped to a colour-map for human viewing. Two thermal images that look identical to a VLM (same false-colour palette) can correspond to wildly different absolute temperatures — the VLM only sees colours, not the metadata.

The fix isn't a bigger VLM. It's a tool-use loop:

  1. VLM looks at the image.
  2. VLM emits a tool call: "give me the temperature at pixel (i, j)".
  3. Tool reads the raw radiometric TIFF and returns a number in Kelvin.
  4. VLM reasons over numbers, not colours.

This is exactly the line of research behind tool-augmented thermal VLMs and the thermal-VLM benchmarking benchmark — concrete demonstration that the dominant VLMs (GPT-4, Claude, Gemini) fail on tasks where a tool-augmented smaller model succeeds. The lesson generalises: any modality whose pixels-look-the-same-but-mean-different-things (thermal, hyperspectral, depth, audio spectrograms) wants a tool layer.

Final takeaway. A VLM is a language model that learned to read pixel tokens. The training stack is well-understood; the open problems are alignment, hallucination on numbers, and modality-specific calibration. For work, the modality-specific calibration is where most of the research payoff lives.