Skip to main content

BLIP-2: Efficient Vision-Language Pre-training

BLIP-2 leverages frozen image encoders and LLMs for efficient vision-language pre-training, achieving state-of-the-art multimodal performance.

TL;DR

BLIP-2 demonstrates that you do not need to train a vision-language model end-to-end from scratch. Instead, freeze a pre-trained image encoder (ViT) and a pre-trained large language model (OPT or FlanT5), then train a Querying Transformer (Q-Former) and its task-specific heads or projection to bridge them. The Q-Former uses 32 learnable query tokens and cross-attention to compress visual information into a fixed-length representation the LLM can consume. The result: BLIP-2 matches or exceeds models with far more trainable parameters (54x more, in the case of Flamingo-80B) on VQA, image captioning, and image-text retrieval — the paper reports 188M parameters for the Q-Former.

The Compute Problem

Training large vision-language models is expensive. CoCa trains all 2.1B of its parameters end-to-end from scratch on billions of images, PaLI-17B keeps its 4B-parameter ViT-e frozen for most of pre-training but still updates its 13B-parameter language model on 1.6B examples, and even Flamingo, which keeps its vision encoder and 70B language model frozen, trains about 10.2B new parameters in its 80B version. This means billions of parameters are updated at every gradient step, demanding thousands of GPU hours and proprietary datasets. Flamingo's training on billions of image-text pairs (1.8B from ALIGN and 312M from its own LTIP) with a model of that scale is simply out of reach for most research labs.

The cost compounds because both the vision and language components are large. A ViT-g image encoder has ~1B parameters. An LLM like OPT-6.7B has 6.7B. Training both together means back-propagating through ~8B parameters at every step, with the memory and compute costs that implies. And if a better LLM comes along next month, the entire training process must be repeated.

BLIP-2 asks a different question: can we reuse the capabilities already learned by frozen unimodal models and just learn to connect them? The image encoder already understands visual features. The LLM already understands language. The missing piece is a translation layer that solves the vision-language alignment problem between the two modalities — and that layer can be small.

This modular approach reduces trainable parameters by an order of magnitude. Where Flamingo-80B trains about 10.2B parameters (its Perceiver Resampler and gated cross-attention layers, with the vision encoder and 70B language model frozen), BLIP-2 trains ~188M (the Q-Former) while keeping the image encoder (~1B ViT-g) and LLM (~3–11B) frozen. On a single machine with 16 A100 GPUs, the largest model (ViT-g with FlanT5XXL) needs less than 6 days for the first stage and less than 3 days for the second — a fraction of what end-to-end training demands.

The Q-Former Architecture

The Q-Former is the core contribution. It is a lightweight transformer that sits between the frozen image encoder and the frozen LLM, responsible for extracting task-relevant visual information and projecting it into a form the language model can process.

The architecture consists of two transformer submodules that share self-attention layers:

  1. Image transformer — interacts with the frozen image encoder through cross-attention layers. The cross-attention queries are a set of 32 learnable embedding vectors (the "query tokens"), each of dimension 768. These queries attend to the image encoder's output features to extract visual information.

  2. Text transformer — functions as both a text encoder and text decoder depending on the pre-training task. It shares self-attention parameters with the image transformer but does not share cross-attention layers (the text side has no cross-attention to image features directly).

The 32 query tokens are the key mechanism. Each query learns to attend to different aspects of the image through cross-attention:

\text{CrossAttn}(Q, K, V) = \text{softmax}\!\left(\frac{Q_{\text{query}} \cdot K_{\text{image}}^\top}{\sqrt{d}}\right) V_{\text{image}}

where Q_{\text{query}} \in \mathbb{R}^{32 \times 768} are the learnable queries and K_{\text{image}}, V_{\text{image}} come from the frozen image encoder's output. The queries interact with each other through shared self-attention layers, allowing them to coordinate what visual information each one extracts.

The output is a fixed set of 32 vectors of dimension 768 — regardless of the image encoder's output size. This creates a fixed-length bottleneck that compresses the visual representation before it reaches the LLM.

The paper uses 32 queries as its fixed bottleneck; it does not report a 16/32/64-query ablation. This fixes the visual prefix length passed to the LLM. It does not make total inference cost independent of image resolution: the image encoder still processes the image patches, and query-to-image cross-attention still reads all of their features. See §3.1 and Figure 2.

The Q-Former is initialized from BERTbase weights. The cross-attention layers (which do not exist in BERT) are randomly initialized. This initialization gives the Q-Former a strong language understanding prior from the start, which helps with the text-side objectives during stage 1 pre-training.

Two-Stage Pre-training

BLIP-2 trains the Q-Former in two stages, each with the image encoder frozen but with different objectives and different modules frozen.

Stage 1: Vision-Language Representation Learning. The Q-Former learns to extract visual representations aligned with text. The image backbone is frozen; the Q-Former and its contrastive, matching and generation heads are trained. The released implementation also trains the visual feature normalization outside the frozen backbone. Three losses are applied jointly:

  • Image-Text Contrastive Loss (ITC) — aligns the query output with the text embedding by maximizing the cosine similarity of matched image-text pairs and minimizing it for unmatched pairs. The highest-similarity query output is used as the image representation. Crucially, a unimodal self-attention mask prevents queries from seeing text tokens and vice versa, forcing each modality to form independent representations before comparison.

  • Image-Text Matching Loss (ITM) — a binary classification task predicting whether an image-text pair is matched or unmatched. This uses a bidirectional self-attention mask so queries and text tokens can attend to each other, enabling fine-grained alignment. The released implementation samples unmatched pairs from similarity-weighted distributions, giving more confusing negatives higher probability.

  • Image-Grounded Text Generation Loss (ITG) — trains the Q-Former to generate text conditioned on the image. The text transformer operates as a causal decoder: queries can attend to each other and to the image features, but text tokens can only attend to previous text tokens and to the query outputs. This forces the queries to capture all visual information needed for text generation.

The three objectives use different self-attention masking strategies (unimodal, bidirectional, causal) to extract complementary visual representations from the shared architecture. This design is inspired by BLIP's Multimodal Mixture of Encoder-Decoder (MED) but adapted to work with learnable queries rather than direct image features.

Stage 1 trains on 129M image-text pairs (COCO, Visual Genome, CC3M, CC12M, SBU, and LAION-400M filtered subset) for 250K steps, with a batch size of 2320 for ViT-L and 1680 for ViT-g.

Stage 2: Vision-to-Language Generative Learning. The Q-Former's output is connected to the frozen LLM through a linear projection layer that maps the 32 query outputs from dimension 768 to the LLM's input dimension:

\mathbf{h}_{\text{LLM}} = W_{\text{proj}} \cdot \mathbf{z}_{\text{query}} + \mathbf{b}, \quad W_{\text{proj}} \in \mathbb{R}^{d_{\text{LLM}} \times 768}

The projected queries are prepended to the text input embeddings as soft visual prompts. For decoder-only LLMs (OPT), the visual prompts are prepended and the model is trained with a language modeling loss to generate text conditioned on them. For encoder-decoder LLMs (FlanT5), the visual prompts are given to the encoder and the decoder generates the output via a prefix language modeling loss. The Q-Former, projection and released visual feature normalization are trained; the image backbone and LLM remain frozen. Freezing the LLM weights still allows gradients through its operations back into the visual prompts. For FlanT5, the text is split: its prefix joins the visual queries at the encoder, and its suffix is the decoder target.

BLIP Architecture Comparison

Visual comparison of BLIP and BLIP-2 neural network architectures

Key Improvements in BLIP-2

Larger vision encoder - ViT-L/14 with 304M parameters (vs. ViT-B/16 with 86M)
Q-Former bridge - Query-based transformer to connect vision and language models
Frozen LLM integration - Using pre-trained language models without fine-tuning
Parameter efficiency - Freezing pre-trained models to reduce training costs

BLIP

Bootstrapping Language-Image Pre-training

~220M parameters
3×224×224
196×768
Patch → Embedding
Text Tokens
77×768
Text Tokens → Embedding
Separate processing paths
86M
196×768
196×768
ViT-B/16
Image features
Self-attention
110M
77×768 + 196×768
77×768
BERT (12 layers)
24M
77×768
77×768
MED & CapFilt
768
Text/Class
ITC / ITM / LM

BLIP-2

Bootstrapping Language-Image Pre-training with Frozen Models

Frozen backbones plus a 188M Q-Former
3×224×224
257×1024
Patch → Embedding
304M
257×1024
257×1024
ViT-L/14
Frozen weights
188M
257×1024
32×768
Query-based Bridge
Projection to LM width
3M
32×768
32×4096
Dimension Adapter
Frozen weights
2.7B–11B
32×4096
N×4096
OPT / FlanT5
N×4096
Text/Class
Generative Output
Note: Component sizes are approximated. Yellow-highlighted components indicate key improvements in BLIP-2 architecture.

Implementation

The two stages share a query extractor, but they do not share one universal attention mask or one loss shift. The executable reference below follows that boundary from image patches through the three alignment losses, then through a frozen causal language model. Its small random modules let us inspect the training mechanics on CPU; the paper's pretrained results follow in the next section.

Run both training stages with native PyTorch on CPU. The reference uses random weights, four queries, a patch convolution and a tiny causal LM. It checks information flow and gradients; it does not load released BLIP-2 checkpoints or produce pretrained captions.

The full LAVIS release requires additional model libraries and weights. This standalone program uses no tokenizer, BERT initialization, distributed negatives or T5 path. Its pre-normalized blocks omit dropout; cyclic negatives and unsmoothed losses make the small example deterministic. Query and text feed-forward networks remain separate.

Download the Python reference · Pinned requirements · Pinned LAVIS source

python blip2_training.py --smoke

1. Freeze the backbones, keep the connector trainable

Original paper

Paper excerpt · PDF p. 2§3.1 · frozen image features

The released model freezes its visual backbone while learning queries and their transformer. Its visual normalization sits outside that frozen backbone.

Math and tensor shapes

F=E_{\mathrm{frozen}}(I)
F\in\mathbb{R}^{B\times P\times d_q}

Here a frozen random 4×4 patch convolution stands in for the pretrained ViT, without a separate visual normalization. Only this image path can run under no_grad. The frozen language model must later retain an input-gradient path. Neither toy backbone has learned visual or language semantics.

Smoke: [3, 3, 16, 16] → [3, 16, 24]

Corresponding official code

Python implementation

1. Freeze the backbones, keep the connector trainable
python
def freeze_backbones(self):
    self.vision.requires_grad_(False)
    self.lm.requires_grad_(False)
    self.vision.eval()
    self.lm.eval()

def encode_image(self, images):
    if (
        images.ndim != 4
        or images.shape[1] != 3
        or min(images.shape[-2:]) < 4
        or any(size % 4 for size in images.shape[-2:])
        or images.shape[0] == 0
        or not images.is_floating_point()
    ):
        raise ValueError("images must be floating [B>0, 3, 4h, 4w]")
    with torch.no_grad():
        return self.vision(images).flatten(2).transpose(1, 2)

2. Let queries read the image in alternating blocks

Original paper

Paper excerpt · PDF p. 3Figure 2 · shared attention and query-only cross-attention

Q-Former shares self-attention between query and text streams. Image cross-attention is inserted every other block and applies only to the query positions.

Math and tensor shapes

A=\operatorname{softmax}(QK^\top d_h^{-1/2})V
Z\in\mathbb{R}^{B\times N\times d_q}

Slice queries after the shared self-attention update; only they cross-attend to image keys and values. Query and text then use separate feed-forward networks, as in LAVIS. The native model uses pre-normalization and random weights, unlike the released BERT-initialized Q-Former. Cross-attention work still grows with P, the image feature count.

Smoke: 4 blocks, 4 heads, N = 4, d_q = 24; paper: N = 32, d_q = 768

Corresponding official code

Python implementation

2. Let queries read the image in alternating blocks
python
def forward(self, hidden, image, queries, allowed, padding):
    normalized = self.norm(hidden)
    update = self.attention(
        normalized,
        normalized,
        normalized,
        attn_mask=~allowed,
        key_padding_mask=padding,
        need_weights=False,
    )[0]
    hidden = hidden + update
    query, text = hidden[:, :queries], hidden[:, queries:]
    if self.cross is not None:
        query = (
            query
            + self.cross(
                self.cross_norm(query), image, image, need_weights=False
            )[0]
        )
    query = query + self.query_ffn(query)
    text = text + self.text_ffn(text)
    return torch.cat([query, text], dim=1)

3. Change visibility without changing attention weights

Original paper

Paper excerpt · PDF p. 3Figure 2 · the three stage-1 masks

The objective determines which modalities may exchange information. ITC isolates them, ITM joins them, and ITG allows only a one-way query-to-text information path.

Math and tensor shapes

M_{\mathrm{ITC}}=\begin{bmatrix}1&0\\0&1\end{bmatrix}
M_{\mathrm{ITM}}=\begin{bmatrix}1&1\\1&1\end{bmatrix}
M_{\mathrm{ITG}}=\begin{bmatrix}1&0\\1&C\end{bmatrix}
C_{ij}=\mathbf{1}[j\leq i]

Each 1 denotes a whole visible block, not an identity matrix. ITG queries see each other bidirectionally; text sees all queries and only its own current and earlier text positions. Padding removes key columns separately. LAVIS reuses cached query keys and values for ITG; this program recomputes the equivalent full masked sequence without a cache.

Rows read columns; query block first, text block second. 1 = visible.

Corresponding official code

Python implementation

3. Change visibility without changing attention weights
python
def visibility(mode, queries, text, device=None):
    """Return allowed attention edges; rows read columns (True = visible)."""
    if mode not in {"itc", "itm", "itg"} or queries < 1 or text < 0:
        raise ValueError(
            "expected itc/itm/itg, positive queries, nonnegative text"
        )
    allowed = torch.ones(
        queries + text, queries + text, dtype=torch.bool, device=device
    )
    if mode == "itc":
        allowed[:queries, queries:] = False
        allowed[queries:, :queries] = False
    elif mode == "itg":
        allowed[:queries, queries:] = False
        allowed[queries:, queries:] = torch.ones(
            text, text, dtype=torch.bool, device=device
        ).tril()
    return allowed

4. Compare each text with the best matching query

Original paper

Paper excerpt · PDF p. 3§3.2 · image-text contrastive learning

The image-text score takes the largest normalized query-to-text similarity for each pair. The text representation comes from its CLS position.

Math and tensor shapes

s_{ij}=\max_k\langle\hat z_{ik},\hat t_j\rangle/\tau
L_{\mathrm{ITC}}=\tfrac12[\mathrm{CE}(S,y)+\mathrm{CE}(S^\top,y)]
y_i=i

The maximizing query can differ for every candidate text. Compute cross-entropy in both retrieval directions, using the matching diagonal as the target. This single-process batch replaces distributed gathering. The temperature is learned; the native loss omits the released 0.1 label smoothing.

[B, N, d_q] × [B, d_q] → [B, B, N] → [B, B]

Corresponding official code

Python implementation

4. Compare each text with the best matching query
python
def contrastive_loss(self, image, tokens):
    hidden = self.qformer(image, tokens, mode="itc")
    query = F.normalize(
        self.image_head(hidden[:, : self.query_count]), dim=-1
    )
    text = F.normalize(
        self.text_head(hidden[:, self.query_count]), dim=-1
    )  # CLS position
    scores = torch.einsum("bqd,cd->bcq", query, text).amax(-1)
    scores = scores / self.temperature.clamp(0.001, 0.5)
    targets = torch.arange(image.shape[0], device=image.device)
    loss = (
        F.cross_entropy(scores, targets)
        + F.cross_entropy(scores.T, targets)
    ) / 2
    return loss, scores

5. Classify matched pairs using fused query outputs

Original paper

Paper excerpt · PDF p. 3§3.2 · image-text matching

The matching head reads query outputs after bidirectional fusion, then averages the two-class logits across queries. Released negatives are sampled using contrastive similarity weights.

Math and tensor shapes

\ell_i=N^{-1}\sum_k(W_m z_{ik}+b_m)
L_{\mathrm{ITM}}=\mathrm{CE}(\ell,y_{\mathrm{match}})

The executable uses a deterministic cyclic shift of the batch to form the two negative groups. Its input pairs must therefore be distinct. This is an explicit simplification of similarity-weighted hard-negative sampling, not a reproduction of that sampling policy.

B matched + B wrong-image + B wrong-text pairs → [3B, 2] logits

Corresponding official code

Python implementation

5. Classify matched pairs using fused query outputs
python
def matching_loss(self, image, tokens):
    batch = image.shape[0]
    if batch < 2:
        raise ValueError("ITM needs at least two distinct paired examples")
    # Deterministic cyclic negatives replace author hard-negative sampling.
    paired_images = torch.cat([image, image.roll(1, 0), image], 0)
    paired_text = torch.cat([tokens, tokens, tokens.roll(1, 0)], 0)
    hidden = self.qformer(paired_images, paired_text, mode="itm")
    logits = self.match_head(hidden[:, : self.query_count]).mean(1)
    labels = torch.cat(
        [
            torch.ones(batch, dtype=torch.long),
            torch.zeros(2 * batch, dtype=torch.long),
        ]
    ).to(image.device)
    return F.cross_entropy(logits, labels)

6. Generate text through the visual query bottleneck

Original paper

Paper excerpt · PDF p. 3§3.2 · image-grounded text generation

A decoding marker replaces CLS. Text receives visual information through query self-attention rather than direct attention to image features.

Math and tensor shapes

L_{\mathrm{ITG}}=-\operatorname{mean}_{t\geq1}\log p(x_t\mid x_{<t},I)

Apply the generation head only to text positions. Shift those text logits to predict the next text token; DEC itself is not a stage-1 target. Query outputs cannot read the answer text. The test changes future tokens and checks that earlier outputs are unchanged. The native loss also omits the released ITG label smoothing.

Text logits [B, T, V]; position 0 contains DEC; padding targets ignored

Corresponding official code

Python implementation

6. Generate text through the visual query bottleneck
python
def grounded_loss(self, image, tokens):
    decoder_tokens = tokens.clone()
    decoder_tokens[:, 0] = DEC  # Replace CLS with the decoding marker.
    hidden = self.qformer(image, decoder_tokens, mode="itg")
    # Queries are a bidirectional prefix, never predicted as text here.
    logits = self.generation_head(hidden[:, self.query_count :])
    labels = decoder_tokens.masked_fill(decoder_tokens.eq(PAD), -100)
    return shifted_loss(logits, labels)

7. Project visual queries into the frozen language model

Original paper

Paper excerpt · PDF p. 4Figure 3 (top) · decoder-only stage 2

The OPT branch prepends projected visual queries to text embeddings. Its frozen language model evaluates the text-conditioned loss while the connector learns.

Math and tensor shapes

U=ZW_p+b_p
X=[U;E_{\mathrm{text}}(x)]

Run Q-Former with queries only, then project into the LM width. Unlike ITG, the LM uses causal attention across the entire concatenated sequence, including its visual prefix. Frozen weights do not mean detached inputs: autograd must traverse the LM to update the projection and Q-Former. The separate FlanT5 encoder-decoder path is outside this reference.

Smoke: [B, 4, 24] → [B, 4, 32]; prefix + text = [B, 9, 32]

Corresponding official code

Python implementation

7. Project visual queries into the frozen language model
python
def stage_two(self, images, tokens):
    validate_tokens(tokens, self.vocabulary, images.shape[0])
    image = self.encode_image(images)
    query = self.qformer(image)  # No text input to Q-Former in this stage.
    prefix = self.projection(query)
    inputs = torch.cat([prefix, self.lm.embedding(tokens)], dim=1)
    prefix_padding = torch.zeros(
        prefix.shape[:2], dtype=torch.bool, device=tokens.device
    )
    padding = torch.cat([prefix_padding, tokens.eq(PAD)], dim=1)
    ignored = torch.full(
        prefix.shape[:2], -100, dtype=torch.long, device=tokens.device
    )
    labels = torch.cat(
        [ignored, tokens.masked_fill(tokens.eq(PAD), -100)], 1
    )
    # Do NOT use no_grad here: the frozen LM must backpropagate to prefix.
    logits = self.lm(inputs, padding)
    return {
        "loss": shifted_loss(logits, labels),
        "logits": logits,
        "labels": labels,
        "prefix": prefix,
    }

8. Shift the complete sequence before ignoring labels

Original paper

Paper excerpt · PDF p. 4§3.3 · language modeling with ignored visual-prefix labels

The official OPT wrapper concatenates ignored prefix labels with text labels before invoking the causal language-model loss. Padding and any configured prompt labels are ignored too.

Math and tensor shapes

a_i=-100,\quad 0\leq i<N
y=[a;x]
L_{\mathrm{LM}}=\mathrm{CE}(\ell_{0:S-1},y_{1:S})

Slice logits and labels once over all N+T positions. Cutting off the prefix logits first would silently lose supervision for the first text token. This example has no extra textual prompt to mask. Stage-1 ITG differs: it shifts text-only logits because DEC starts its text decoder. Tests verify both boundaries and reject an all-ignored loss.

Last prefix logit predicts first supervised text token; -100 = ignore

Corresponding official code

Python implementation

8. Shift the complete sequence before ignoring labels
python
def shifted_loss(logits, labels):
    """Shift the complete sequence, ignoring -100 targets after shifting."""
    if logits.ndim != 3 or labels.shape != logits.shape[:2]:
        raise ValueError("logits [B, S, V] and labels [B, S] must align")
    if labels.dtype != torch.long:
        raise ValueError("labels must have dtype torch.long")
    valid = labels.ne(-100)
    if ((labels[valid] < 0) | (labels[valid] >= logits.shape[-1])).any():
        raise ValueError("labels must be vocabulary IDs or -100")
    targets = labels[:, 1:]
    if not targets.ne(-100).any():
        raise ValueError("at least one shifted target must be supervised")
    return F.cross_entropy(
        logits[:, :-1].reshape(-1, logits.shape[-1]),
        targets.reshape(-1),
        ignore_index=-100,
    )

9. Continue a sequence using the visual prefix

Original paper

Paper excerpt · PDF p. 6§4.1 · image-to-text inference

The released model conditions language generation on projected query features. Its useful captions depend on pretrained encoders, language models and learned alignment.

Math and tensor shapes

x_{t+1}=\arg\max_v\ell_{t,v}

The native greedy loop starts from DEC, excludes non-generative control IDs, appends each predicted ID and stops at EOS or a short limit. It recomputes the prefix instead of caching LM keys and values. These random-weight token IDs demonstrate decoding mechanics; they are not captions and do not measure visual understanding.

Smoke vocabulary: 32 IDs; DEC = 2, EOS = 3, PAD = 0

Corresponding official code

Python implementation

9. Continue a sequence using the visual prefix
python
@torch.no_grad()
def generate_ids(self, images, max_new_tokens=4):
    """Greedily continue DEC; random small-vocabulary IDs are not captions."""
    if not 1 <= max_new_tokens < 128 - self.query_count:
        raise ValueError("generation length must fit the 128-position LM")
    prefix = self.projection(self.qformer(self.encode_image(images)))
    ids = torch.full(
        (images.shape[0], 1), DEC, dtype=torch.long, device=images.device
    )
    finished = torch.zeros(
        images.shape[0], dtype=torch.bool, device=images.device
    )
    for _ in range(max_new_tokens):
        inputs = torch.cat([prefix, self.lm.embedding(ids)], dim=1)
        padding = torch.cat(
            [
                torch.zeros(
                    prefix.shape[:2], dtype=torch.bool, device=images.device
                ),
                ids.eq(PAD),
            ],
            1,
        )
        logits = self.lm(inputs, padding)[:, -1].clone()
        logits[:, [PAD, CLS, DEC]] = -torch.inf
        next_id = logits.argmax(-1).masked_fill(finished, PAD)
        ids = torch.cat([ids, next_id[:, None]], dim=1)
        finished = finished | next_id.eq(EOS)
        if finished.all():
            break
    return ids

Inspect one executed training step per stage

Seed 17, 3 synthetic images, four queries and a 32-ID vocabulary. Stage 2 starts after one stage-1 update. The exported values below come from the downloadable program under Python 3.13.13 and PyTorch 2.12.0+cpu on CPU.

Stage 1: ITC / ITM / ITG
1.1585 / 0.6441 / 3.8969
Stage 2: language-model loss
3.7004
Gradient norm at the frozen LM input prefix
0.085193
Gradient norm at the stage-2 Q-Former
2.607574
Gradient norm at the stage-2 projection
0.702955
Frozen backbone parameters received gradients
No
First example: labels and generated IDs
json
{
  "stage_two_labels": [
    -100,
    -100,
    -100,
    -100,
    2,
    4,
    5,
    3,
    -100
  ],
  "generated_token_ids": [
    2,
    16,
    14,
    25,
    30
  ]
}

Four ignored prefix labels precede the text labels. The last prefix position predicts ID 2; the final padding target is ignored. All three random images produced the same short ID sequence in this run. That is useful evidence of a working loop, not visual caption quality.

Download the complete trace and source SHA-256

Key Results

Visual Question Answering. On VQAv2, BLIP-2 with FlanT5XXL achieves 65.0% accuracy (test-dev) in a zero-shot setting — outperforming Flamingo-80B (56.3%) by 8.7 points while using 54x fewer trainable parameters (188M versus 10.2B; most of Flamingo's 80B parameters are frozen). With OPT6.7B, the zero-shot score is 52.6%. Fine-tuned on VQAv2, BLIP-2 achieves a test-dev accuracy of 82.2%. BLIP-2 also sets the zero-shot state of the art on GQA (44.7%), but on OK-VQA it comes second to Flamingo-80B (45.9% versus 50.6%), which the paper attributes to the greater world knowledge of Flamingo's 70B Chinchilla language model.

Image Captioning. On COCO Captions (Karpathy test split), fine-tuned BLIP-2 reaches a CIDEr score of 145.8 with OPT2.7B and 144.5 with FlanT5XL. Transferred zero-shot to NoCaps validation, the COCO-fine-tuned FlanT5XL model scores an overall CIDEr of 121.6, demonstrating strong generalization to novel object categories outside the training distribution.

Image-Text Retrieval. On COCO retrieval, fine-tuned BLIP-2 (ViT-g) achieves 85.4% Recall@1 for image-to-text and 68.3% for text-to-image. Transferred zero-shot to Flickr30K, the same model achieves 97.6% TR@1 and 89.7% IR@1, the best zero-shot results among the methods the paper compares. The stage-1 Q-Former alone handles retrieval tasks, demonstrating that the learned queries capture sufficient visual-semantic alignment.

Scaling Behavior. The paper reports consistent improvements when scaling both the image encoder (ViT-L to ViT-g) and the LLM (OPT-2.7B to OPT-6.7B, FlanT5-XL to FlanT5-XXL). This suggests that BLIP-2 can continue to benefit from improvements in either unimodal component without architectural changes.

Critical Analysis

Strengths:

  • Parameter efficiency. The 188M-parameter Q-Former greatly reduces the trainable parameter count relative to updating both large backbones. Frozen weights save optimizer and parameter-gradient storage, although stage 2 still back-propagates through the LLM to train its input prompts. The reported training setup still uses 16 A100 GPUs; parameter counts alone do not establish an equal reduction in FLOPs.

  • Modularity. The frozen-component design means the image encoder and LLM can be swapped independently. The paper demonstrates this by pairing the same Q-Former training procedure with OPT (decoder-only) and FlanT5 (encoder-decoder) LLMs, and with ViT-L versus ViT-g image encoders.

  • Adaptable language interface. Soft visual prompts can connect to language models that accept token embeddings. The paper demonstrates OPT and FlanT5; a new language model still needs a compatible projection, objective and alignment training. This is an architectural recipe, not a guarantee that an existing connector transfers unchanged.

Limitations:

  • Information bottleneck. Compressing all visual information into 32 fixed-length query vectors is a deliberate trade-off. For tasks requiring fine-grained spatial reasoning — counting objects, understanding spatial relationships, reading small text — this bottleneck can lose critical detail. Later work (InstructBLIP, LLaVA) has experimented with increasing the number of visual tokens or passing image features directly.

  • Q-Former complexity. The three-objective training procedure with different self-attention masking strategies (unimodal, bidirectional, causal) adds architectural complexity. Each loss requires a different attention mask configuration in the same transformer, making the training pipeline harder to reproduce and debug than simpler alternatives like linear projection (as in LLaVA).

  • Two-stage training. The bootstrapping approach requires sequential training: stage 1 must complete before stage 2 begins. Single-stage alternatives are simpler to implement and tune.

  • Hallucination. Like other vision-language models that rely on frozen LLMs, BLIP-2 can generate text that is fluent but not grounded in the image content. The frozen LLM's language priors can override visual evidence, producing plausible-sounding but incorrect descriptions. The LLM weights cannot adapt directly, but the Q-Former and projection can still learn prompts that influence its attention and outputs. That indirect control does not eliminate hallucination.

  • Frozen LLM ceiling. The quality of generated text is bounded by the frozen LLM's capabilities. If the LLM cannot reason about a particular type of question or follow a particular instruction format, no amount of Q-Former training will compensate. This became clearer as instruction-tuned LLMs improved rapidly after BLIP-2's release.

Impact and Legacy

BLIP-2 popularized a recipe that many later multimodal LLMs build on: freeze pre-trained unimodal models and train a lightweight connector. Not every follow-up kept both models frozen: LLaVA, for example, fine-tunes its LLM in its second training stage.

InstructBLIP (Dai et al. 2023) extended BLIP-2 by adding instruction tuning to the Q-Former, enabling instruction-following capabilities across diverse vision-language tasks without task-specific fine-tuning. LLaVA (Liu et al. 2023) simplified the connector further, replacing the Q-Former with a single linear projection layer and showing that visual instruction tuning could achieve strong results with an even simpler architecture. The tension between Q-Former-style compression and direct projection (LLaVA-style) remains an active area of research.

The broader impact is architectural: BLIP-2 demonstrated that vision-language capability is not about training the largest model end-to-end, but about efficiently bridging modalities. This insight shaped many of the open multimodal models that followed, though not every production system took the same route: Google's Gemini models are natively multimodal, trained jointly across text, image, audio and video from the beginning.

The Q-Former's learnable query mechanism also influenced work beyond vision-language models. The idea of using a small set of learned tokens to extract task-relevant information from a larger representation has appeared in video understanding (Video-LLaMA), audio-language models, and 3D vision systems. BLIP-2's demonstration that 32 query vectors can compress the visual world into a form an LLM can reason about remains one of the more surprising empirical findings in multimodal learning.

  • BLIP — the original BLIP that BLIP-2 succeeds: introduces the unified encoder-decoder and the CapFilt data bootstrapping that BLIP-2 inherits
  • Flamingo — the gated cross-attention VLM that pioneered bridging a frozen vision encoder and a frozen LLM, the lineage BLIP-2 refines with its Q-Former
  • CoCa — unifies contrastive alignment and captioning in a single image-text model, a different route to the multimodal pre-training BLIP-2 targets
  • CLIP: Learning Transferable Visual Models From Natural Language Supervision — the contrastive pre-training framework whose frozen ViT encoders serve as BLIP-2's visual backbone
  • Attention Is All You Need — the transformer architecture underlying both the Q-Former and the frozen LLMs
  • Vision Transformer — the ViT architecture used as the frozen image encoder in BLIP-2
  • DETR: End-to-End Object Detection with Transformers — shares the concept of learnable queries that attend to visual features via cross-attention
  • Segment Anything (SAM) — another modular vision foundation model that separates the encoder from the task-specific decoder
  • Vision-Language Alignment — compares BLIP-2’s Q-Former with CLIP, LLaVA and Flamingo, and what each trains or freezes in each stage

If you found this paper review helpful, consider sharing it with others.

Mastodon