v9.1.1
Menu

Chapter 3: Language Model Backbone

Week 3-4

Understand the language model architectures that serve as the reasoning engine in VLMs. From decoder-only transformers to encoder-decoder models, tokenization strategies for multimodal inputs, attention mechanisms over mixed sequences, popular LLM backbones, and the scaling laws that guide model selection.

Topics
6
Videos
3
Min read
28

Chapter Overview

The language model is the reasoning engine of every Vision-Language Model. While the vision encoder perceives the world and the bridge module translates visual features, it is the LLM backbone that performs inference, generates text, follows instructions, and chains together multi-step reasoning over what the model "sees."

Modern VLMs inherit their language capabilities from pretrained LLMs---GPT-class decoder-only transformers, encoder-decoder models like Flan-T5, or mixture-of-experts architectures like Mixtral. The choice of backbone profoundly affects the VLM's ability to follow complex instructions, perform multi-turn dialogue, reason about spatial relationships, and generate accurate descriptions.

A critical design question is how to extend a text-only LLM to process visual tokens. The model must handle a mixed sequence of image tokens and text tokens under a unified attention mechanism. This requires careful tokenization, positional encoding, and attention masking strategies.

This chapter covers:

  • Decoder-Only Transformers: The dominant architecture (GPT, LLaMA, Mistral) and causal attention
  • Encoder-Decoder Models: The T5/Flan-T5 paradigm with cross-attention for VLMs
  • Tokenization for Multimodal Input: How image tokens interleave with text in the input sequence
  • Attention Mechanisms in VLMs: Causal self-attention over mixed image+text sequences
  • Popular LLM Backbones: Vicuna, LLaMA, Mistral, Qwen, Phi---why each is chosen
  • Scaling Laws & Model Selection: Parameter count vs. performance trade-offs and quantization

Chapter Roadmap

Click any topic to jump in

Explainer video
1
Decoder-Only Transformers

Autoregressive generation with causal masking — the dominant architecture behind GPT, LLaMA, and most modern VLMs.

Autoregressive GenerationCausal Attention MaskNext-Token Prediction Loss
2
Encoder-Decoder Models

Bidirectional encoding with cross-attention decoding — the T5/Flan architecture used in some VLMs like BLIP-2.

Bidirectional EncoderCross-Attention MechanismSequence-to-Sequence Formulation
How multimodal data enters the LM
3
Multimodal Tokenization

How vision features become tokens the language model can process — visual tokens, delimiters, and multi-image sequences.

Visual Token CreationSpecial Delimiter TokensMulti-Image Sequences
Mechanisms for cross-modal understanding
4
VLM Attention Mechanisms

Full causal self-attention vs gated cross-attention — how VLMs let language attend to visual information.

Full Causal Self-Attention (Decoder-Only)Gated Cross-Attention (Flamingo)Attention Sink and Visual Token Placement
Choosing and sizing your backbone

Which model and how large

5
Popular LLM Backbones

LLaMA, Mistral, Phi, Qwen — the specific models used as VLM language backbones and their tradeoffs.

LLaMA Family (Meta)Mistral / Mixtral (Mistral AI)Small Language Models (Phi, Gemma)Multilingual Backbones (Qwen, InternLM)
6
Scaling Laws & Selection

Chinchilla scaling, VLM-specific compute allocation, and quantization — choosing the right model size.

Chinchilla Scaling LawVLM-Specific ScalingQuantization for Deployment

Topics

6 topics in this chapter

Decoder-only transformers (GPT, LLaMA, Mistral, Qwen) are the dominant architecture for VLM backbones. They process a sequence of tokens autoregressively---each token can only attend to previous tokens and itself---and generate output one token at a time. This causal attention pattern is what makes them "decoder-only": there is no separate encoder; the same stack of transformer blocks handles both understanding and generation.

Key insight: In a VLM, the "prompt" to the decoder-only transformer includes both visual tokens (from the vision encoder + bridge) and text tokens. The causal mask ensures that when generating token tt, the model attends to all preceding image tokens and text tokens, but never to future tokens.

In this topic

  1. 1Autoregressive Generation
  2. 2Causal Attention Mask
  3. 3Next-Token Prediction Loss
1 of 3
Autoregressive Generation

P(y1,y2,…,yT)=∏t=1TP(yt∣y1,…,yt−1)P(y_1, y_2, \ldots, y_T) = \prod_{t=1}^{T} P(y_t \mid y_1, \ldots, y_{t-1})

A decoder-only model factorizes the joint probability of a sequence into a product of conditional probabilities. At each step, the model predicts the next token given all previous tokens. During training, all positions are computed in parallel using the causal mask. During inference, tokens are generated one at a time, each conditioned on the growing prefix.

Mathematical Intuition

The chain rule of probability gives the exact factorization P(y1:T)=∏tP(yt∣y<t)P(y_{1:T}) = \prod_t P(y_t \mid y_{<t}). Each conditional is a categorical distribution over a vocabulary of size VV, so a single forward pass produces T×VT \times V logits. The log-likelihood of the whole sequence decomposes into a sum of per-token log-probabilities, making gradient computation embarrassingly parallel across positions during training.

Example:

For the sequence "A dog sits on grass", write out the conditional factorization.

2 of 3
Causal Attention Mask

CausalAttn(Q,K,V)=softmax(QKTdk+M)V,Mij={0j≤i−∞j>i\text{CausalAttn}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}} + M\right)V, \quad M_{ij} = \begin{cases} 0 & j \leq i \\ -\infty & j > i \end{cases}

The causal mask MM is a lower-triangular matrix added to the raw attention scores before softmax. Positions where j>ij > i receive −∞-\infty, which become zero after softmax, preventing token ii from attending to any future token jj. This is implemented efficiently as a single triangular boolean mask applied once per layer, with no additional parameters.

Mathematical Intuition

Adding −∞-\infty to the upper triangle before softmax exploits the limit lim⁡z→−∞ez=0\lim_{z \to -\infty} e^z = 0, giving exact zeros in the attention matrix without any approximation. The resulting lower-triangular weight matrix AA satisfies A1=1A \mathbf{1} = \mathbf{1} (rows sum to 1), forming a row-stochastic matrix that acts as a weighted average operator over the value vectors.

Example:

In a 4-token sequence, what does the causal mask matrix look like?

3 of 3
Next-Token Prediction Loss

L=−1T∑t=1Tlog⁡Pθ(yt∣y<t)\mathcal{L} = -\frac{1}{T} \sum_{t=1}^{T} \log P_{\theta}(y_t \mid y_{<t})

Training minimizes the cross-entropy loss between the predicted distribution and the true next token at every position in the sequence. Because the causal mask prevents information leakage, all TT positions can be trained in a single forward pass (teacher forcing). This is the same objective used for pretraining the LLM; during VLM fine-tuning, the loss is typically computed only on the text generation tokens, not on the image tokens or the prompt.

Mathematical Intuition

The cross-entropy loss L=−1T∑tlog⁡Pθ(yt∣y<t)\mathcal{L} = -\frac{1}{T}\sum_t \log P_\theta(y_t \mid y_{<t}) is an unbiased estimator of the negative log-likelihood. By the Kraft inequality, minimizing this loss is equivalent to learning an optimal prefix-free code for the data: the model's perplexity 2L2^{\mathcal{L}} measures how many tokens the model is effectively "choosing between" at each step.

Example:

Why is the loss typically masked to exclude image tokens during VLM training?

Theory Exercise

Problem:

Explain why decoder-only transformers are preferred over encoder-decoder models as VLM backbones in recent architectures like LLaVA and GPT-4V. Consider computational efficiency, pretraining ecosystem, and instruction-following capability.

Hints:
  • Think about the availability of strong pretrained decoder-only models
  • Consider the simplicity of the architecture for multimodal input
  • Think about what instruction tuning provides