PIXELBANKv8.2.1
Menu
Back to Concepts
Multimodal2023

LLaVA: Visual Instruction Tuning

Large Language-and-Vision Assistant

Haotian Liu, Chunyuan Li, Qingyang Wu, Yong Jae Lee

Read the Paper on arXiv

Paper Overview

LLaVA (Large Language-and-Vision Assistant) introduced a surprisingly simple yet powerful recipe for building multimodal AI: connect a pre-trained vision encoder (CLIP ViT-L/14) to a large language model (Vicuna/LLaMA) through a lightweight projection layer, then train in two stages — first align visual and language representations, then instruction-tune for general-purpose visual understanding.

The core insight: You don't need complex cross-attention modules, Q-Formers, or perceiver architectures to build a strong vision-language model. A simple linear projection (LLaVA 1.0) or 2-layer MLP (LLaVA 1.5) connecting frozen CLIP features to the LLM's embedding space is sufficient — when combined with high-quality instruction-following data.

A second key contribution: Using language-only GPT-4 to generate multimodal instruction-following data from image captions and bounding boxes. This produced 158K high-quality training samples (conversations, detailed descriptions, complex reasoning) without any human annotation of visual instruction data.

LLaVA 1.5 improved on the original with three targeted changes — an MLP projection, higher-resolution CLIP (336px), and academic VQA data — achieving state-of-the-art on 11 benchmarks while training on a single 8-A100 node in ~1 day.

Model configurations:

LLaVA 1.0 (13B)LLaVA 1.5 (13B)
Vision EncoderCLIP ViT-L/14 (224px)CLIP ViT-L/14 (336px)
Visual Tokens16 x 16 = 25624 x 24 = 576
ProjectionLinear (1024 to 5120)2-layer MLP (1024 to 5120)
LLMVicuna-13B v1.3Vicuna-13B v1.5
Stage 1 Data595K CC3M filtered558K LAION-CC-SBU
Stage 2 Data158K LLaVA-Instruct665K mixed
Training8x A100, ~14 hours8x A100, ~26 hours

LLaVA demonstrated that the data and training recipe matter more than architectural complexity — a lesson that influenced subsequent multimodal models including LLaVA-NeXT, InternVL, and Qwen-VL.

Chapter Roadmap

Click any topic to jump in

1
Visual Tokenization

CLIP ViT-L/14 encodes a 336-px image into 576 visual tokens — the raw substrate for multimodal reasoning.

feeds projected tokens to
2
Vision-Language Projection

A single MLP maps 1024-d CLIP features into the 4096-d LLM embedding space, the sole bridge between modalities.

3
Multimodal Input

Projected visual tokens are concatenated with text tokens — no architectural change to the transformer.

powered by
4
GPT-4 Instruction Data

GPT-4 distills captions and bounding boxes into 158K multimodal conversations, descriptions, and reasoning samples.

5
Two-Stage Training

Stage 1 aligns the projector on captions; Stage 2 jointly tunes projector + LLM on instruction data.

unlocked by data + projector
6
LLaVA 1.5

Higher resolution (336²), MLP projector, and VQA data push LLaVA to SOTA on 11 benchmarks with ~1.2M samples.

7
Benchmarks & Ablations

85.1% relative GPT-4 score shows data quality and a minimal architecture beat raw scale.

LLaVA converts images into a sequence of visual tokens using a frozen CLIP vision encoder. These tokens are then projected into the language model's embedding space, allowing the LLM to "see" images as naturally as it reads text.

The Problem

Large language models process sequences of discrete text tokens, but images are continuous 2D grids of pixels. To build a multimodal model, we need to convert images into a format the LLM can process:

  • Images are high-dimensional: A 336x336 RGB image has 336×336×3=338,688336 \times 336 \times 3 = 338,688 values — far too many to feed directly into an LLM
  • Semantic gap: Raw pixels don't carry semantic meaning. The color value at pixel (100, 200) tells the LLM nothing about objects, scenes, or concepts in the image
  • Training from scratch is prohibitive: Learning visual representations from image-text pairs requires billions of training examples (CLIP was trained on 400M pairs) and massive compute

Previous approaches used complex bridging architectures:

  • Flamingo: Gated cross-attention layers interleaved with LLM layers — expensive and tightly coupled
  • BLIP-2: Q-Former with 32 learned queries + cross-attention to frozen vision features — complex, requires pre-training the Q-Former itself
  • These approaches add significant architectural complexity and training overhead, and their cross-attention mechanisms make them harder to scale

The Solution

LLaVA's approach is radically simple: use CLIP ViT-L/14 as a frozen feature extractor, take the grid features (not the [CLS] token), and project them into the LLM's word embedding space.

Step 1: Image to patches

The image is divided into non-overlapping patches:

  • LLaVA 1.0: Input 224×224224 \times 224 image, patch size 14×1414 \times 14 pixels

    • Grid: 224/14=16224/14 = 16 patches per side
    • Total: 16×16=25616 \times 16 = 256 visual tokens
    • Each patch covers 14×14=19614 \times 14 = 196 pixels
  • LLaVA 1.5: Input 336×336336 \times 336 image, patch size 14×1414 \times 14 pixels

    • Grid: 336/14=24336/14 = 24 patches per side
    • Total: 24×24=57624 \times 24 = 576 visual tokens
    • 2.25x more visual tokens = finer spatial detail

Step 2: Patch embedding

Each 14×14×314 \times 14 \times 3 patch is linearly embedded into a dclip=1024d_{clip} = 1024-dimensional vector:

zi=Linear(flatten(patchi))+PEiwhere ziR1024z_i = \text{Linear}(\text{flatten}(\text{patch}_i)) + PE_i \quad \text{where } z_i \in \mathbb{R}^{1024}

A learnable [CLS] token is prepended, and positional embeddings are added.

Step 3: ViT Transformer processing

The patch tokens pass through 24 Transformer layers (ViT-L has 24 layers, 16 heads, d=1024d = 1024):

Zout=ViT(z1,z2,...,zn)R(n+1)×1024Z_{out} = \text{ViT}(z_1, z_2, ..., z_n) \in \mathbb{R}^{(n+1) \times 1024}

Critical choice: LLaVA uses features from the second-to-last layer (layer 23 of 24), not the final layer. The final layer of CLIP is trained with a contrastive loss that produces abstract, global features optimized for image-text matching. The penultimate layer retains more localized, spatial information — individual objects, textures, spatial relationships — which is more useful for visual question answering.

Step 4: Grid features output

The [CLS] token is discarded. The remaining grid features become the visual token sequence:

  • LLaVA 1.0: ZvR256×1024Z_v \in \mathbb{R}^{256 \times 1024} (256 tokens, each 1024-dim)
  • LLaVA 1.5: ZvR576×1024Z_v \in \mathbb{R}^{576 \times 1024} (576 tokens, each 1024-dim)

These visual tokens are now ready for projection into the LLM's embedding space. Each token represents a 14×1414 \times 14 pixel region of the image and carries rich semantic features learned from CLIP's 400M image-text training pairs.

Why CLIP specifically?

CLIP's vision encoder is trained with a contrastive language-image objective, so its features are already aligned with language semantics. A dog patch produces features that are close (in CLIP space) to the word "dog" — this makes the projection layer's job much easier than starting from a vision-only encoder like ImageNet-trained ViTs.

Key Points

1

CLIP ViT-L/14 is kept completely frozen during both training stages — no gradients flow back to the vision encoder. This preserves CLIP's robust visual representations learned from 400M image-text pairs

2

Grid features, not [CLS]: LLaVA uses all nn spatial tokens (256256 or 576576), discarding the global [CLS] token. This preserves spatial layout — the LLM knows where things are, not just what the image contains

3

Penultimate layer features (layer 23/24) retain localized spatial properties. The final layer is too abstract (optimized for global contrastive matching) — ablations showed a 0.96% accuracy drop using final-layer features on ScienceQA

4

Resolution matters: Moving from 224px (256 tokens) to 336px (576 tokens) in LLaVA 1.5 improved performance across all benchmarks by capturing finer details — especially for text-heavy and detail-oriented visual questions

5

Each visual token represents a 14×1414 \times 14 pixel patch (\approx 4-6% of image width) — roughly the granularity of a single word in text. This makes the image-as-tokens metaphor surprisingly apt

Mathematical Formulation

Patch Embedding

zi=Weflatten(xpi)+Eposiwhere WeR1024×588,  xpiR14×14×3z_i = W_e \cdot \text{flatten}(x_p^i) + E_{pos}^i \quad \text{where } W_e \in \mathbb{R}^{1024 \times 588}, \; x_p^i \in \mathbb{R}^{14 \times 14 \times 3}

Each 14×14×3 = 588-dimensional flattened patch is projected to 1024 dimensions. Positional embedding E_pos is added to encode spatial location in the grid.

Visual Feature Extraction

Zv=ViTL1(ximg)Rn×1024where n=(H/14)2Z_v = \text{ViT}_{L-1}(x_{img}) \in \mathbb{R}^{n \times 1024} \quad \text{where } n = (H/14)^2

ViT_{L-1} denotes the penultimate layer output. For 224px: n=256, for 336px: n=576. These 1024-dim features carry both semantic and spatial information from CLIP pre-training.

Mathematical Intuition

A 224×224224\times 224 image is cut into 14×14=19614\times 14 = 196 non-overlapping 16×1616\times 16 patches. Each patch is flattened to a vector in R768\mathbb{R}^{768} and linearly projected, yielding a grid of visual tokens that the frozen CLIP ViT-L/14 encoder refines into rich semantic features ZvR196×1024\mathbf{Z}_v \in \mathbb{R}^{196 \times 1024}.