DL0134 Interleaved Vision-Language Architectures

Explain Interleaved Vision-Language Architectures. How do models pre-trained on mixed sequences of raw image tokens and text tokens differ from cross-attention models?

Answer

An interleaved vision-language architecture flattens a document into one sequence that alternates text spans and images, projects each image’s patch features into the language model’s embedding space, and trains a single decoder with ordinary next-token prediction over the mixed stream. This is early fusion: visual tokens occupy real sequence positions, so they are keys and values for every text token in every layer, and text tokens are keys and values for the image. The alternative family, cross-attention conditioning (Flamingo, Idefics1), keeps vision outside the text sequence: a frozen ViT plus a Perceiver resampler compresses each image to a fixed R = 64 latents, and newly inserted gated cross-attention layers let the frozen LM read those latents without ever lengthening its own sequence. The consequences are structural rather than cosmetic. Early fusion makes cost quadratic in the joint length L = N_t + M N_v and demands full multimodal pre-training, but it gives uniform bidirectional-within-causal mixing, unlimited image ordering, and (with discrete VQ image tokens) the ability to generate images from the same head. Cross-attention decouples image count from the text sequence and protects a strong frozen LLM, at the price of a hand-designed conditioning path, per-image attention masks that weaken multi-image relational reasoning, and no route to image output.

(1) Where Fusion Happens: early fusion concatenates projected patch embeddings into the token stream, so mixing occurs in every self-attention layer; cross-attention confines mixing to a handful of inserted layers reading a fixed latent set.
(2) Sequence Length Is The Cost Model: a ViT-L/14 at 336 px yields N_v = 576 tokens per image, so eight images add 4608 positions and roughly 100\times the attention cost of a text-only forward pass.
(3) Attention Pattern And Multi-Image Reasoning: Flamingo masks each text token to cross-attend only to the most recent preceding image, while early fusion lets any token attend to all earlier images and their surrounding text.
(4) Parameter Budget And Text Regression: cross-attention adds new trainable blocks around a frozen LM and preserves text-only quality by construction; early fusion updates the whole backbone and risks catastrophic forgetting unless text data is replayed.
(5) Generation Symmetry: only the interleaved token-in-sequence form can emit images, because image outputs must live in the same vocabulary the head predicts (Chameleon, Emu3).
(6) Data Requirement: both families need interleaved web corpora such as M3W or OBELICS rather than caption pairs, since few-shot in-context learning is what interleaving buys.

Two-panel architecture diagram: left panel shows interleaved early fusion where text token groups and 576-token image groups alternate in one row feeding a single causal self-attention stack and a joint-vocabulary next-token head; right panel shows cross-attention conditioning where an image passes through a frozen ViT and a Perceiver resampler producing 64 latents that are read by gated cross-attention layers inserted between frozen language model blocks

Figure 1: The two conditioning paths. In early fusion the image becomes sequence positions inside the shared stack, so every layer mixes modalities and the sequence grows with each image. In cross-attention conditioning the image stays outside the text sequence as a fixed set of R latents, read through gated layers whose gate starts at zero so the frozen LM is initially unchanged.

Practice has converged on early fusion, and the reason is mostly negative: the cross-attention path is an extra design surface with its own hyperparameters (how many layers to insert, resampler depth, latent count, gate schedule) and it caps the visual information at R latents regardless of image resolution, which destroys dense OCR and chart reading. Ablations in MM1 found the interleaved token-in-sequence recipe matched or beat cross-attention at equal scale while being simpler, and the lineage of the same lab’s open models makes the shift explicit: Idefics1 (Flamingo-style cross-attention) → Idefics2 (early fusion with pooled visual tokens). Early fusion then imports the cross-attention family’s one real advantage, token compression, without its plumbing: Idefics3 pixel-shuffles 2 \times 2 patch blocks into one token, Qwen2-VL merges adjacent patches in the projector, and both keep the compressed tokens in the main sequence. What remains genuinely hard in early fusion is positional encoding for a 2D object embedded in a 1D stream, handled by explicit row-separator tokens in Fuyu or by multimodal rotary embeddings that give an image token separate height, width, and time indices.

Mathematical Formulation:
N_v = (H/P)\,(W/P)
L = N_t + M\,N_v
C_{\mathrm{self}} = O(L^2 d)
Z = \mathrm{Resampler}(\mathrm{ViT}(I)) \in \mathbb{R}^{R \times d}
C_{\mathrm{cross}} = O(N_t\, M R\, d)
y_\ell = h_\ell + \tanh(\alpha_\ell)\,\mathrm{XAttn}(h_\ell, Z)

Where:

  • H, W are the image height and width and P the patch size, so N_v is the visual tokens per image: at 336/14 this is 24 \times 24 = 576.
  • N_t is the number of text tokens, M the number of images in the document, and L the joint sequence length the early-fusion decoder actually processes; d is the model width.
  • C_{\mathrm{self}} is the self-attention cost, quadratic in L, so each added image contributes both its own N_v^2 block and cross terms with all existing tokens.
  • I is the raw image, Z the resampled latents, and R \ll N_v the latent count (R = 64 in Flamingo), which is why C_{\mathrm{cross}} is linear in M and leaves the LM’s own O(N_t^2 d) untouched.
  • h_\ell are the frozen LM hidden states at layer \ell and \alpha_\ell a learned scalar gate initialized to zero, so \tanh(\alpha_\ell) = 0 makes the inserted block an identity at step 0 and training degrades the language model gradually rather than abruptly.
Line chart of attention cost normalized to a text-only forward pass versus the number of images from one to eight, with three curves: early fusion at 576 tokens per image rising quadratically to about one hundred times, early fusion with four-times pooling at 144 tokens per image rising to about ten times, and cross-attention with 64 latents per image rising linearly to about two times

Figure 2: Why token count dominates the choice. Early fusion pays O(L^2) in the joint sequence, so eight full-resolution images cost roughly 100\times a text-only pass, while cross-attention stays near 2\times because its cost is linear in M R. Patch pooling recovers most of the gap without leaving the sequence, which is the modern compromise.

PropertyInterleaved early fusionCross-attention conditioning
Image positionReal sequence positions inside the decoderOutside the sequence, as fixed keys and values
Cost in image countQuadratic through the joint length LLinear, and only in the inserted layers
Trainable surfaceProjector plus the whole backbone, usually full pre-trainingResampler and gated cross-attention only, LM frozen
Visual detail ceilingScales with resolution; supports OCR and dense chartsCapped at R latents regardless of resolution
Multi-image reasoningAll prior images visible to every tokenTypically masked to the most recent image per text token
Image generationPossible with discrete VQ image tokens in one vocabularyNot possible; the path is input-only
Representative modelsFuyu-8B, Chameleon, Idefics2/3, MM1, Qwen2-VL, Emu3Flamingo, OpenFlamingo, Idefics1, Llama 3.2 Vision

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *