Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
LLaVA,
explained.
Flamingo bridged vision and language with a careful resampler and gated cross-attention. LLaVA asked: what's the least you can get away with? Its answer was almost cheeky — one linear layer to project image features into the language model's vocabulary space, drop those image "words" at the front of the prompt, and let ordinary attention do the rest. Add instruction-tuning data that a text-only GPT-4 wrote for you, and you have a capable visual chat assistant trained on a shoestring. Here's the minimal connector, and the synthetic data that taught it to see.
What changes against Flamingo: the connector is one linear layer
Rung 2's bridge is a resampler and a set of gated cross-attention layers. This rung's change is to ask how much of that is necessary, and the answer is: almost none of it. Take the vision encoder's output patch features, pass them through a single linear projection into the language model's token embedding space, and prepend them to the text tokens. The image becomes, literally, some tokens at the front of the prompt. No cross-attention, no resampler, no gating — the language model's ordinary self-attention reads the visual tokens because they are in the sequence.
The second half is the data, and it is as economical as the architecture. Visual instruction data — conversations about images — did not exist at scale, so it is generated by a strong text-only model that is shown an image's captions and object boxes, never the image, and asked to write questions, answers and descriptions. Textual descriptions stand in for sight on the teacher's side, and the student learns to do it from pixels. That is the bootstrapping recipe from the post-training ladder, pointed at a modality.
Training is two short stages — align the projection first with everything else frozen, then instruction-tune. Stated against rung 2's units: far less machinery, a training run within reach of an academic budget, and competitive conversational ability about images. This is the rung where a capable vision-language model stopped requiring a frontier lab.
The simplest bridge
The multimodal problem is the same as Flamingo's: you have a strong vision encoder (CLIP) and a strong language model, and you want them to work together. Flamingo's answer was architecturally involved — compress vision with a resampler, inject it through new gated cross-attention layers. LLaVA's bet was that a language model, being a general sequence processor, doesn't need special machinery to read images. It just needs the images turned into tokens it can attend to like any other.
So LLaVA does the minimal thing: a single linear projection from image features to the language model's embedding space, and then treats the projected features as ordinary tokens at the start of the prompt. No new attention layers, no resampler. The language model's own self-attention fuses vision and text. It's the kind of simplification that seems too easy to work — and the paper's contribution is showing that, with the right training data, it does.
Project image features into the LLM's token space with one linear layer, prepend them to the prompt, and instruction-tune on data GPT-4 generated — a minimal, effective visual assistant.
Project and prepend
Concretely: the vision encoder produces feature vectors for an image (one per patch). A trainable projection matrix W maps each feature into the language model's word-embedding dimension, turning it into an "image token." Those image tokens are then simply placed in front of the text tokens, and the whole sequence goes into the language model:
The connector is one matrix — a few million parameters, a tiny fraction (well under 0.1%) of the billions in the language model. Because the image tokens live in the same space as word embeddings and sit in the same sequence, the LLM attends across text and vision with its ordinary self-attention; nothing else changes. The runnable version below shows the projection mapping CLIP's 1024-dim features to a 4096-dim LLM space and the tiny parameter cost. (Later LLaVA versions swap the single linear layer for a small MLP, but the idea is identical.)
Instruction data from GPT-4
A connector alone gives a model that can see but not converse about what it sees. To teach visual instruction-following, you need instruction data — and high-quality multimodal instruction data was scarce. LLaVA's clever move was to synthesize it with a text-only GPT-4. It took images that already had text annotations (captions and object bounding boxes), fed those text descriptions (not the pixels) to GPT-4, and asked it to produce rich instruction-following examples:
The elegance is using a language model's text understanding to bootstrap a vision model's instruction-following, entirely from existing annotations — no human labeling of the multimodal examples. That "generate instruction data with a strong LLM" pattern, which LLaVA brought to the multimodal setting, is now a standard way to build capable assistants cheaply.
Two-stage training
Training has two stages, cheap by design. Stage 1 — feature alignment: freeze both the vision encoder and the language model, and train only the projection on image-caption pairs, so the projected image tokens land in a place the LLM understands. Since only the small connector learns, this is fast. Stage 2 — instruction tuning: keep the vision encoder frozen but now fine-tune the projection and the language model together on the GPT-4-generated instruction data, teaching the assistant to follow visual instructions.
The split is efficient: stage 1 does the easy alignment with almost no trainable parameters, and stage 2 spends the real training on teaching behavior. The vision encoder stays frozen throughout — its features are already good. The whole thing was trainable in about a day on modest hardware, which is a large part of why LLaVA was so widely reproduced and extended.
How LLaVA was built and trained, step by step
LLaVA joins a frozen CLIP image encoder to Vicuna, an open chat model, through one trainable matrix. The architecture fits in a sentence; the method is in the data recipe and the two training stages.
- Encode the image. CLIP ViT-L/14 at 224 pixels cuts the image into a 16 × 16 grid of 14-pixel patches and returns one 1,024-dimensional feature per patch: 256 vectors. LLaVA takes them from the layer before CLIP's last Transformer layer, which scored better than the last layer in the paper's ablation.
- Project. A trainable matrix W maps each feature into the language model's word-embedding space, 5,120 dimensions for Vicuna-13B, the main model: about 5 million weights. The 256 results are the image tokens.
- Format a conversation. A system message, then alternating human and assistant turns. The image tokens go either before or after the first question, chosen at random, and every assistant turn ends with a stop sequence. The loss is computed only on the assistant's answers and stop sequences.
- Write the instruction data. For COCO images, the text-only GPT-4 was given two symbolic descriptions: the human-written captions, and the object bounding boxes with their categories. A few hand-written seed examples per data type, the only human annotation in the pipeline, served as in-context examples. The result, LLaVA-Instruct-158K, holds 58K multi-turn conversations, 23K detailed descriptions and 77K complex-reasoning answers. In early tests GPT-4 wrote better data than ChatGPT, notably for spatial reasoning.
- Stage 1: align the features. CC3M was filtered to 595K image–caption pairs. Each becomes a one-turn exchange: a randomly chosen request for a brief description, answered by the original caption. CLIP and Vicuna stay frozen and only W trains, for one epoch at learning rate 2×10^−3 with batch size 128, in under 4 hours on 8 A100 GPUs.
- Stage 2: instruction-tune. CLIP stays frozen; W and all of Vicuna train on the 158K examples for three epochs at learning rate 2×10^−5 with batch size 32, in under 10 hours on the same 8 GPUs. A separate model is fine-tuned on ScienceQA, generating its reasoning before its answer.
- Answer. At inference the model reads the image tokens and the question and generates its reply like any chat model.
What LLaVA-1.5 and LLaVA-NeXT changed
LLaVA-1.5, a follow-up paper by the same group, replaced W with a two-layer MLP, moved to CLIP at 336 pixels (a 24 × 24 grid, so 576 tokens), switched to Vicuna v1.5, and mixed academic VQA datasets into a 665K-example instruction set, using format prompts such as "Answer the question using a single word or phrase." for short answers. The whole run took about a day on one node of 8 A100 GPUs. LLaVA-NeXT later split higher-resolution images into several 336-pixel tiles plus a downscaled overview, encoding each, which multiplies the tokens per image.
LLaVA's projection and answer-only loss
Xv— the image;g— the frozen CLIP ViT-L/14, read at its second-to-last layer;Zv— 256 features of 1,024 dimensionsW— the trainable projection;Hv— 256 vectors in the language model's embedding spaceXinstruct— the human turns;Xa— the assistant's answers;xi— the i-th answer token, so the product and its loss cover answer tokens onlyφ— Vicuna's own weights
Training minimizes −log of that probability. At the extremes: with W = 0 every image token is the zero vector and the model becomes a text-only chatbot that sees 256 blank positions. Skipping stage 1 means the later fine-tune starts from a random W, and on ScienceQA that cost about 5 points (90.92% down to 85.81%). And if the loss also covered the human turns, the model would learn to write the questions as well, spending gradient on text the user always supplies.
How LLaVA was measured, and what it scored
LLaVA was measured two ways. LLaVA-Bench uses GPT-4 as a judge: a text-only GPT-4 first writes a reference answer from a textual description of the image, then rates the reference and LLaVA's answer from 1 to 10 for helpfulness, relevance, accuracy and detail, and LLaVA's score is reported relative to the reference. The COCO version has 30 images and 90 questions, three types per image; the In-the-Wild version has 24 more varied images and 60 questions. ScienceQA, a multiple-choice science benchmark, is scored by plain accuracy.
| Benchmark | Model or training data | Score |
|---|---|---|
| LLaVA-Bench (COCO), relative score | all 158K instruction examples | 85.1% |
| LLaVA-Bench (COCO), relative score | conversation data only | 73.8% |
| LLaVA-Bench (COCO), relative score | no instruction tuning | 21.5% |
| LLaVA-Bench (In-the-Wild) | OpenFlamingo / BLIP-2 / LLaVA | 19.1 / 38.1 / 67.3 |
| ScienceQA accuracy | GPT-4, text only | 82.69% |
| ScienceQA accuracy | previous best (MM-CoT Large) | 91.68% |
| ScienceQA accuracy | LLaVA | 90.92% |
| ScienceQA accuracy | LLaVA with GPT-4 as judge | 92.53% |
The last row combines two models: when LLaVA and GPT-4 disagree, GPT-4 is asked again with both answers and gives a final one, which set a new ScienceQA record. The ScienceQA ablations isolate the design choices: skipping stage 1 gave 85.81%, reading CLIP's last layer instead of the one before it 89.96%, and the 7B model instead of 13B 89.84%.
The paper also shows the family's characteristic failure. Asked whether a fridge held strawberry-flavored yogurt, LLaVA said yes when the photo showed yogurt and, separately, strawberries; the authors read this as the model sometimes treating an image as a bag of patches.
What the authors admit, and what happened next
The cost of prepending rather than resampling is context: every visual token occupies a position in the sequence, so an image costs hundreds of tokens, and higher resolution or several images multiply that directly. Rung 2's fixed-size compression was solving a real problem, and this rung gives that up in exchange for simplicity — which is why the later work in this family is largely about tiling high-resolution images and then compressing the resulting tokens again.
The synthetic data has the failure mode its construction predicts. A teacher writing about an image it cannot see, from captions and boxes, will occasionally describe things that are not there — so the student is trained on some confidently wrong visual assertions, and models of this family are known for fluent descriptions of absent details. Evaluation also leaned on model-as-judge comparisons, which carry documented biases toward length and style.
How it held up: projection-plus-prepend is the dominant architecture. Nearly every open vision-language model is this shape, with a better vision encoder, a better language model and more data. The lesson is one the site keeps finding: the elaborate connector was solving a problem that mostly dissolved once the language model was strong enough to handle visual tokens in its ordinary input, and the simplest bridge that fits in the existing interface won.
One projection, image tokens up front
LLaVA's connector is just a matrix multiply. This projects a 1024-dim CLIP feature into a 4096-dim LLM embedding (the projection is linear, so it distributes over addition), prepends the resulting image tokens to the text so the sequence simply grows (576 image tokens as in LLaVA-1.5, whose 336-pixel encoder gives a 24 by 24 grid; the original LLaVA uses 256; 576 image + 100 text = 676), and prices the connector: ~4 million parameters, under 0.1% of a 7B language model. And stage-1 training tunes only that projection while the vision encoder and LLM stay frozen. Change the dimensions or token counts and watch the tiny footprint hold.
Write the body of trainable_stage1. Everything else in the file is
already written; this is the function the paper is about. Press ▶ Run to check it against
the 5 assertions below — they start red.
- The projection outputs the LLM embedding dimension
- The projection is linear (additive)
- Prepended vision tokens grow the sequence
- The connector is a tiny fraction of the parameters
- Stage 1 trains only the projection (LLM+vision frozen)
The recipe that spread
LLaVA's "projection + prepend + instruction-tune" recipe became the default template for open visual language models. Its two ideas each had outsized influence: the minimal connector (a projection or small MLP, not heavy cross-attention) is now the common way to graft vision onto an LLM, and synthetic instruction data from a strong model is a standard tool for teaching new capabilities cheaply.
The deeper lesson is about where the intelligence already is. A pretrained LLM is a remarkably general processor; LLaVA showed you often don't need to build elaborate new machinery to give it a new modality — you mostly need to speak to it in its own token language and show it examples of the behavior you want. That "align cheaply, then instruction-tune" pattern, and the bias toward minimal connectors, shaped how the field builds multimodal systems today.
Because the image tokens sit in the ordinary sequence, the number of vision tokens directly costs context length and compute — which is why later work (and Flamingo's resampler) cares about compressing how many tokens an image becomes.
Questions people ask about LLaVA
What data was LLaVA trained on?
Two sets, one per stage. Stage 1 used 595K image–caption pairs filtered from Conceptual Captions (CC3M), each turned into a one-line request for a brief description answered by the caption. Stage 2 used LLaVA-Instruct-158K, written by a text-only GPT-4 about COCO images it never saw: it was given the human captions and the object bounding boxes as text, plus a few hand-written seed examples, and produced 58K conversations, 23K detailed descriptions and 77K complex-reasoning answers. The seed examples were the only part written by people. LLaVA-1.5 later replaced this with a 665K-example mix that adds academic visual question answering datasets.
What changed from LLaVA to LLaVA-1.5?
Four things, in a follow-up paper by the same group. The single linear projection became a two-layer MLP. The vision encoder moved from CLIP ViT-L/14 at 224 pixels to the 336-pixel version, raising an image from 256 to 576 tokens. The language model became Vicuna v1.5. And the instruction data grew into a 665K-example mix that includes academic visual question answering sets, with short format prompts such as asking for a single word or phrase, so the model could give brief benchmark answers without losing its long conversational ones. Training used about 1.2 million public examples and took roughly a day on one node of 8 A100 GPUs, and the paper reports state-of-the-art results across 11 benchmarks at release.
How is LLaVA evaluated, and what is LLaVA-Bench?
LLaVA-Bench measures open-ended visual chat with GPT-4 as the judge. For each question, a text-only GPT-4 first writes a reference answer from a textual description of the image; then GPT-4 rates both the reference and the candidate from 1 to 10 for helpfulness, relevance, accuracy and level of detail, and the candidate's score is reported relative to the reference. The COCO version has 30 images with 90 questions; the In-the-Wild version has 24 more varied images with 60 questions, where LLaVA scored 67.3 against 38.1 for BLIP-2 and 19.1 for OpenFlamingo. Model judges can favor longer, more fluent answers, so these scores are best read alongside accuracy benchmarks like ScienceQA.
Why does LLaVA train in two stages instead of one?
Stage 1 teaches the projection where to put image features so that the frozen language model can read them; it trains only that matrix, on 595K captioned images, in under 4 hours on 8 A100 GPUs. Stage 2 then fine-tunes the projection and the whole language model on the 158K instruction examples to teach conversational behavior. The split matters: in the ScienceQA ablation, skipping stage 1 dropped accuracy from 90.92% to 85.81%. Starting the fine-tune from an aligned projection means the language model is not forced to cope with what are effectively noise vectors while it is also learning the task.
Which CLIP layer does LLaVA use, and why?
LLaVA reads CLIP ViT-L/14's patch features from the layer before the last Transformer layer, not from the final one. In the ScienceQA ablation the last layer scored 89.96% against 90.92% for the layer before it. The authors' explanation is that CLIP's final layer is shaped by its contrastive objective, which matches whole images to whole captions, so it tends to carry global and abstract properties, while the layer before it keeps more localized detail that helps when answering questions about specific parts of an image. LLaVA-1.5 kept the same choice.
How many tokens does an image take in LLaVA?
In the original LLaVA, 256. CLIP ViT-L/14 at 224 pixels splits the image into 14-pixel patches, a 16 by 16 grid, and each patch becomes one token after the projection. LLaVA-1.5 uses the 336-pixel encoder, a 24 by 24 grid, so 576 tokens. LLaVA-NeXT goes further by splitting a high-resolution image into several 336-pixel tiles plus a downscaled copy and encoding each, so a single image can cost a few thousand tokens. Because image tokens sit in the ordinary input sequence, every one of them uses context length and attention compute, the cost that Flamingo's fixed 64-token resampler avoided.
4 questions to test what you just read
Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.
How many weights does LLaVA's projection from 1,024-dimensional CLIP features into Vicuna-13B's 5,120-dimensional embeddings have, and what share of a 13-billion-parameter model is that?
Show answer
1,024 × 5,120 = 5,242,880 weights, plus 5,120 biases: about 5.2 million, roughly 0.04% of 13 billion. Stage 1 trains only these weights, which is a large part of why it finishes in under 4 hours.
Where do 256 and 576 image tokens come from, and how much of a 2,048-token context is left for text in each case?
Show answer
224 ÷ 14 = 16 patches per side, 16² = 256, leaving 1,792 tokens; 336 ÷ 14 = 24 per side, 24² = 576, leaving 1,472. Raising the resolution by 1.5× in each direction costs 2.25× the tokens, because tokens grow with area.
In stage 2, a three-turn conversation is one training example. Which tokens produce gradient, and why not the human turns?
Show answer
Only the assistant's three answers and their stop sequences. The image tokens and the human questions are conditioning: the model must read them but never has to produce them. Training on them would teach the model to write the user's side of the conversation too, spending gradient on text it will always be given.
Skipping stage 1 cost about 5 points on ScienceQA (90.92% to 85.81%). What does stage 1 give the later fine-tune that it struggles to learn on its own?
Show answer
Stage 1 trains W, with everything else frozen, until the image tokens land where the frozen language model can read them. Without it, fine-tuning begins with a random W: the language model's visual inputs are effectively noise, and its own weights are updated to cope with that noise at the same time as they learn the task.
One model, many senses
Joining text to images, audio, video and finally to a robot arm. Starts with the contrastive objective the whole field standardised on.
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Paper Breakdowns
- Attention Is All You NeedThe paper that introduced the Transformer — the architecture underneath GPT, BERT, Claude, and Gemini. Self-attention, Query/Key/Value, multi-head attention, positional encoding, and the real BLEU results, explained in depth with analogies and animated visuals, not just equations.Read →
- Word2VecHow words became math. Dense word vectors learned from the company a word keeps, so king − man + woman lands near queen. Skip-gram, CBOW, the distributional hypothesis, and the origin of every embedding model powering search and RAG.Read →
- ResNetThe skip connection that made deep learning deep. Why stacking layers made networks worse, and how residual learning let them reach 150+ layers and win ImageNet — the identity shortcut every Transformer still uses inside every block.Read →
- Vision Transformer (ViT)When an image became 16×16 words. Cut a picture into patches, treat each patch as a token, and feed them to a plain Transformer — no convolutions. Patch embeddings, the class token, and why data scale lets attention beat the CNNs that ruled computer vision for a decade.Read →
- Latent DiffusionThe paper behind Stable Diffusion. Compress an image into a small latent space with a VAE, run the diffusion denoising there instead of on pixels for a tens-of-times efficiency win, and steer it with text via cross-attention. The architecture that put text-to-image generation on consumer GPUs.Read →
- DDPMThe original denoising diffusion math — the paper that made diffusion work. A fixed forward process adds Gaussian noise over many steps; a U-Net learns the reverse. The masterstroke: train the network to simply predict the added noise with a plain MSE loss. The foundation under every modern image generator.Read →