Skip to main content
Open In Colab Vision Language Models (VLMs) extend the reasoning abilities of large language models to visual inputs, images, charts, documents, and video. Among the open-source VLMs, the LLaVA (Large Language-and-Vision Assistant) family stands out for its elegant architecture, reproducible training recipe, and influence on dozens of follow-up works. This tutorial walks through the full LLaVA lineage: the architecture that connects a frozen vision encoder to an LLM via a lightweight projector, the two-stage training procedure, the key improvements introduced in LLaVA-1.5, and the multi-modal extensions in LLaVA-OneVision. We conclude with a hands-on fine-tuning section using LoRA on a custom dataset.

Prerequisites

You should be comfortable with transformer architectures, attention mechanisms, and the basics of LLM fine-tuning (LoRA, DeepSpeed). Familiarity with CLIP and contrastive learning is helpful but not required.
All code in this tutorial runs on a single GPU with ≥24 GB VRAM (e.g. RTX 4090, A5000) in float16. The full-precision 13B model requires 8×A100.

Connecting an image encoder to a language model

The image encoder returns a sequence of patch features, and the language model reads a sequence of token embeddings. Every vision language model needs a connector between the two, and three designs are common. VLM architectures comparison, Q-Former, Linear/MLP, Perceiver Resampler, Native Fusion Editable Mermaid source: images/vlm-architectures.mermaid.md

MLP projector (LLaVA)

A small MLP maps each patch feature to a vector of the size of the language model’s token embeddings. Every patch becomes one token, and the language model’s own self-attention relates the image tokens to the text. Nothing is discarded between the encoder and the language model, but the number of tokens grows with the number of patches: one image costs 576 tokens in LLaVA-1.5. SmolVLM merges neighboring patches (pixel shuffle) before the projection to reduce that number by a factor of 16.

Q-Former (BLIP-2)

BLIP-2 keeps both the image encoder and the language model frozen and trains only a small transformer between them, the Querying Transformer or Q-Former (Li et al., 2023). Its input is a set of 32 learned query vectors. In every block the queries attend to each other, then read the frozen image features through cross-attention, the mechanism shown on the cross-attention page. The 32 outputs pass through a linear layer and are placed before the text as 32 extra tokens, whatever the resolution of the image. BLIP-2 trains the Q-Former in two stages. The first stage does not use the language model. On image and caption pairs, the queries learn to extract the visual features that relate to text, under three losses: an image-text contrastive loss as in CLIP, an image-text matching loss that classifies a pair as matched or not, and a captioning loss that generates the caption from the query outputs. The second stage connects the Q-Former to the frozen language model and trains it so that the language model continues the 32 query tokens with the caption. The fixed number of query tokens keeps the language model’s input short. The cost is a bottleneck: whatever the language model learns about the image must fit in 32 vectors, and in BLIP-2 they are computed before the model sees the question. InstructBLIP later passed the instruction to the Q-Former as well, so that the queries can depend on it.

Cross-attention layers (Flamingo)

Flamingo inserts new cross-attention layers between the frozen blocks of the language model (Alayrac et al., 2022). The text tokens attend to the visual features inside these layers, instead of reading image tokens at the input. A Perceiver Resampler, which works like the Q-Former, first reduces the features of each image to 64 vectors. Each new layer is gated by tanh⁡(α)\tanh(\alpha) with α\alpha initialized to zero, so at the start of training the language model behaves exactly as before.

The design most models use

LLaVA takes the first route. Since LLaVA-1.5, which matched or exceeded Q-Former models such as InstructBLIP on most of the benchmarks it reported, with an MLP projector and a better mix of instruction data (Liu et al., 2023), most open models have used an MLP projector, adding pooling or pixel shuffle when the number of image tokens grows too large.

LLaVA Architecture

The architecture has three components: a vision encoder, a projection module, and a language model. The vision encoder and LLM are initialized from powerful pre-trained checkpoints and the projector is the bridge trained to translate between their representation spaces.

Vision Encoder, CLIP ViT

LLaVA uses OpenAI’s CLIP ViT-L/14 as its visual backbone. CLIP was trained via contrastive learning on 400M image-text pairs, so its patch embeddings already carry rich semantic information aligned (at a coarse level) with natural language. The original LLaVA uses ViT-L/14 at 224×224 resolution, producing a 16×16 grid of patch tokens (256 tokens, each 1024-dim). LLaVA-1.5 upgrades to the 336×336 variant, yielding a 24×24 grid (576 tokens), a 2.25× increase in visual tokens that meaningfully improves fine-grained understanding.
The vision encoder is kept frozen throughout both training stages. Its pre-trained representations are treated as a fixed visual vocabulary.

Projection Module

This is where the key innovation lies. The original LLaVA uses a single linear projection W∈Rdv×dlW \in \mathbb{R}^{d_v \times d_l} that maps each CLIP patch embedding from the vision dimension dv=1024d_v = 1024 into the LLM’s embedding dimension dld_l (4096 for Vicuna-7B, 5120 for Vicuna-13B): hivis=W⋅ziCLIP,i=1,…,Npatches\mathbf{h}_i^{\text{vis}} = W \cdot \mathbf{z}_i^{\text{CLIP}}, \quad i = 1, \ldots, N_{\text{patches}} LLaVA-1.5 replaces this with a two-layer MLP with GELU activation, providing a non-linear transformation that significantly improves cross-modal alignment: hivis=W2⋅GELU(W1⋅ziCLIP+b1)+b2\mathbf{h}_i^{\text{vis}} = W_2 \cdot \text{GELU}(W_1 \cdot \mathbf{z}_i^{\text{CLIP}} + \mathbf{b}_1) + \mathbf{b}_2 This seemingly small change, from a linear layer to a two-layer MLP, produced substantial benchmark improvements. The insight echoes findings from self-supervised learning (SimCLR, BYOL) where MLP projection heads consistently outperform linear ones for representation alignment.

Language Model, Vicuna / LLaMA

The LLM consumes a mixed sequence of visual tokens [h1vis,…,hNvis][\mathbf{h}_1^{\text{vis}}, \ldots, \mathbf{h}_N^{\text{vis}}] interleaved with text token embeddings. From the LLM’s perspective, the projected visual tokens are indistinguishable from word embeddings, they share the same dimensionality and occupy positions in the same sequence. The original LLaVA uses Vicuna (a chat-tuned LLaMA). LLaVA-1.5 scales to Vicuna-13B. Later variants swap in LLaMA-3, Qwen-2, and other stronger base models, showing the architecture’s modularity. LLaVA data flow, image through CLIP ViT, MLP projector, concatenation with text tokens, into LLM Editable Mermaid source: images/llava-data-flow.mermaid.md

Two-Stage Training

LLaVA’s training is efficient and conceptually clean: Stage 1 learns the projector in isolation, Stage 2 fine-tunes the full model for instruction following.

Stage 1, Feature Alignment Pre-training

Goal: Teach the MLP projector to translate CLIP patch embeddings into the LLM’s representation space. Data: 558K image-caption pairs filtered from CC3M (LCS-558K). Each sample is a simple (image, caption) pair, no complex instructions yet. What is trained: Only the MLP projector. Both the CLIP encoder and the LLM remain frozen. Intuition: This is a “language grounding” stage. The projector learns that a certain pattern of CLIP activations (e.g., a dog on grass) should map to token embeddings that the LLM would associate with text like “a golden retriever sitting on a lawn.” Cost: Approximately 3.5 hours for the 7B model or 5.5 hours for 13B on a single 8×A100 node.

Stage 2, Visual Instruction Tuning

Goal: Turn the system into a conversational visual assistant that follows multi-turn instructions. Data (LLaVA): 158K GPT-4-generated visual instruction-following samples built from COCO images, 58K conversations, 23K detailed descriptions, 77K complex reasoning chains. Data (LLaVA-1.5): A richer 665K mixture that adds academic VQA datasets (VQAv2, GQA, OKVQA, A-OKVQA, OCR-VQA, TextCaps), ShareGPT conversations, and region-level perception data. What is trained: The MLP projector and the full LLM are fine-tuned jointly. The CLIP encoder stays frozen. Cost: Approximately 10 hours for 7B or 20 hours for 13B on 8×A100.
A common mistake is to unfreeze the vision encoder during Stage 2. This is counterproductive, the pre-trained CLIP representations are high-quality and stable. Unfreezing them risks catastrophic forgetting of visual features while gaining little in task performance.

Instruction Data Generation

A distinctive contribution of the original LLaVA paper is the method for generating visual instruction data. Since GPT-4 (at the time) could not process images, the authors fed it COCO image captions and bounding box annotations as text, then prompted it to generate three types of instruction-following conversations:
  1. Multi-turn conversation, A user asks about the image; the assistant responds naturally, and the conversation continues.
  2. Detailed description, A thorough account of the image content.
  3. Complex reasoning, Questions that require inference beyond what is literally visible (e.g., “Why might the person be wearing a raincoat?”).
This approach, using a language-only model to bootstrap multimodal instruction data, was influential and widely adopted. The result was released as LLaVA-Instruct-150K, about 158,000 conversations on COCO train2014 images, stored as an image file name and a list of turns between a human and the assistant.

Key Improvements in LLaVA-1.5

LLaVA-1.5 achieved state-of-the-art on 11 of 12 benchmarks with minimal architectural changes. The gains came from three targeted modifications:

Higher Resolution

Switching from CLIP ViT-L/14 at 224px to the 336px variant increases the visual token count from 256 to 576. This is critical for tasks requiring fine-grained perception: reading small text, counting objects, understanding spatial relationships.

MLP Projector

As discussed, replacing the linear layer with a two-layer MLP with GELU activation yielded consistent improvements across all benchmarks. The learning rate for pre-training was halved (from 2e-3 to 1e-3) to stabilize MLP training.

Academic VQA Data

Adding task-oriented VQA datasets (with response format prompts like “Answer with the option’s letter from the given choices directly”) taught the model to produce both short factual answers and long conversational responses, a capability the original LLaVA lacked.

Scaling to High Resolution, LLaVA-1.5-HD

A fixed 336×336 input discards detail in high-resolution images. LLaVA-1.5-HD introduces AnyRes (Any Resolution) processing:
  1. Slice the input image into a grid of patches, each 336×336 (matching the encoder’s native input).
  2. Encode each patch independently through the frozen CLIP ViT.
  3. Encode a downsampled version of the full image for global context.
  4. Concatenate all local patch features with the global features.
  5. Project the combined features through the MLP into the LLM.
This supports resolutions up to 672×672 (2×2 grid) without any positional embedding interpolation. LLaVA-OneVision extends this further to up to 2304×2304 with a configurable maximum grid size.

The LLaVA-NeXT and OneVision Lineage

After LLaVA-1.5, the project evolved rapidly: LLaVA-NeXT (January 2024) scaled AnyRes to 4× more pixels and swapped in stronger LLMs (LLaMA-3-8B, Qwen-1.5-72B/110B), yielding models that outperformed Gemini Pro on some benchmarks. LLaVA-NeXT-Video (May 2024) showed that image-only-trained LLaVA-NeXT transferred surprisingly well to video understanding with zero-shot modality transfer, plus DPO training with AI feedback on videos. LLaVA-OneVision (August 2024) unified single-image, multi-image, and video understanding in one model. It uses SigLIP-SO400M as the vision encoder, Qwen2 as the LLM, and a multi-stage training curriculum:
  • Stage 1: LCS-558K, projector only
  • Stage 1.5: 4.7M high-quality synthetic data, full model
  • Stage 2 (Single-Image): 3.6M instruction-following samples
  • Stage 3 (OneVision): 1.6M single-image + multi-image + video samples
Available in 0.5B, 7B, and 72B parameter configurations. LLaVA-OneVision-1.5 (September 2025) retains the ViT-MLP-LLM paradigm but introduces a region-aware vision encoder with 2D rotary positional encoding, native-resolution image processing, and a Megatron-LM training framework with MoE and FP8 support. The 8B model outperforms Qwen2.5-VL-7B on 18 of 27 benchmarks, with total training cost around $16,000 on A100 GPUs.

Hands-On: Running LLaVA-1.5 Inference

Let’s load LLaVA-1.5-7B and run visual question answering on a sample image.

Hands-On: Running LLaVA-OneVision

For the latest multi-modal capabilities, use LLaVA-OneVision with the Hugging Face transformers pipeline:

Fine-Tuning LLaVA with LoRA

For domain-specific tasks (medical imaging, remote sensing, industrial inspection), you can fine-tune LLaVA efficiently using LoRA. It adds low-rank updates to the attention and MLP projections of the language model, and keeps the vision encoder, the projector and every original weight frozen.

Preparing Your Dataset

LLaVA expects instruction-following data in a specific JSON format:
Each sample contains an image path and a multi-turn conversation where <image> is a placeholder token replaced by projected visual features at runtime.

LoRA Configuration

The vision encoder (CLIP) also has layers named q_proj, k_proj and v_proj. A plain list of names would put adapters on those layers too, because LoRA matches each name against the end of the module path. A pattern that starts with language_model keeps the adapters on the language model only.

Training Script

The official LLaVA repository provides training scripts compatible with DeepSpeed:
Keep per_device_train_batch_size × gradient_accumulation_steps × num_gpus consistent with the original training recipe for best reproducibility. The official 7B LoRA config uses a global batch size of 128.

Merging and Deploying

After training, merge the LoRA checkpoint that the training script wrote back into the base model. The repository provides a script for this, which reads the checkpoint in the format its training script saved:

Architecture Comparison Table

Design principles the LLaVA line established

The LLaVA family demonstrates several principles that extend beyond this specific model: Simplicity wins. A direct projection from vision features to LLM token space outperforms more complex cross-modal fusion mechanisms (Q-Former, Perceiver) when combined with high-quality instruction data. Data quality over architecture. The jump from LLaVA to LLaVA-1.5 came primarily from better data mixing (academic VQA tasks, response format prompts) rather than fundamental architectural changes. Modularity enables rapid iteration. Because the vision encoder, projector, and LLM are cleanly separated, each can be upgraded independently. Swapping Vicuna for LLaMA-3 or Qwen2 requires no architectural changes. Visual instruction tuning is more impactful than large-scale pre-training. The LLaVA-1.5 paper showed that a model using only 1.2M publicly available data samples and completing training in one day on a single 8×A100 node could match or exceed models trained on orders of magnitude more data.

References

  • Alayrac, J., Donahue, J., Luc, P., Miech, A., Barr, I., et al. (2022). Flamingo: a Visual Language Model for Few-Shot Learning. arXiv [cs.CV]. Link
  • Li, J., Li, D., Savarese, S., Hoi, S. (2023). BLIP-2: Bootstrapping language-image pre-training with frozen image encoders and large language models. arXiv [cs.CV]. Link
  • Liu, H., Li, C., Li, Y., Lee, Y. (2023). Improved baselines with visual instruction tuning. arXiv [cs.CV]. DOI

Found an error on this page? Report an issue.