Chapter 3: Language Model Backbone
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
- 6
- Min read
- 42
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
Decoder-Only Transformers
Autoregressive generation with causal masking — the dominant architecture behind GPT, LLaMA, and most modern VLMs.
Encoder-Decoder Models
Bidirectional encoding with cross-attention decoding — the T5/Flan architecture used in some VLMs like BLIP-2.
Multimodal Tokenization
How vision features become tokens the language model can process — visual tokens, delimiters, and multi-image sequences.
VLM Attention Mechanisms
Full causal self-attention vs gated cross-attention — how VLMs let language attend to visual information.
Which model and how large
Popular LLM Backbones
LLaMA, Mistral, Phi, Qwen — the specific models used as VLM language backbones and their tradeoffs.
Scaling Laws & Selection
Chinchilla scaling, VLM-specific compute allocation, and quantization — choosing the right model size.
Topics
6 topics in this chapter
A vision encoder hands you a few hundred patch vectors, but vectors do not answer questions. Something has to read them alongside the user's prompt and produce fluent text, one word at a time, without peeking at words it has not written yet. The previous chapter ended with those patch features; this chapter is about the language model that consumes them. Nearly every open VLM since 2023 (LLaVA, Qwen-VL, Idefics2, InternVL) uses a decoder-only transformer for that job: a single stack of blocks in which every position may attend only to itself and earlier positions. That one constraint, the causal mask, is what lets the same network train on all positions in parallel and then generate autoregressively at inference. In a VLM the prefix simply contains image tokens before the text, so each generated word can look back at every patch. The arc has three steps: the chain-rule factorization that defines generation, the triangular mask that enforces it inside attention, and the next-token loss, including why VLM training masks the loss on image and prompt positions so only answer tokens are graded.
Definition
A decoder-only transformer is a stack of identical self-attention and feed-forward blocks with a causal mask, so position attends only to positions . It models a sequence as , is trained with next-token cross-entropy on every position in one parallel pass, and generates by sampling one token at a time and appending it to the prefix.
In this topic
- 1Autoregressive Generation
- 2Causal Attention Mask
- 3Next-Token Prediction Loss
Autoregressive Generation
Why factorize at all? A joint distribution over every possible caption is far too large to write down, but the chain rule splits it exactly into one next-token distribution per position, . Here is the token at step , the prefix before it, and the sequence length. Training computes all conditionals in one parallel pass because the targets are already known. Inference cannot: token must be sampled before token can be conditioned on it, so generation costs sequential forward passes, made cheaper by caching keys and values. The failure mode is exposure bias: an early wrong token is never revised, because every later step conditions on it.
The chain rule of probability gives the exact factorization . Each conditional is a categorical distribution over a vocabulary of size , so a single forward pass produces 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.
For the sequence "A dog sits on grass", write out the conditional factorization.
Causal Attention Mask
How does one parallel pass avoid cheating? Without a mask, position could read the very token it is supposed to predict. The causal mask adds 0 where and where to the scaled scores , where , and are the query, key and value matrices and is the key width. Since , future positions get exactly zero weight and every row still sums to 1. The mask has no parameters and is shared by every layer and head. A classic bug is an off-by-one mask that also hides the diagonal: the first row becomes all and its softmax returns NaN.
Adding to the upper triangle before softmax exploits the limit , giving exact zeros in the attention matrix without any approximation. The resulting lower-triangular weight matrix satisfies (rows sum to 1), forming a row-stochastic matrix that acts as a weighted average operator over the value vectors.
In a 4-token sequence, what does the causal mask matrix look like?
Next-Token Prediction Loss
What exactly is graded? The loss averages over the target positions, where denotes the model weights. With the causal mask every position trains in the same pass, a scheme called teacher forcing because the true prefix is fed in rather than the model's own samples. Perplexity is when the log is natural. In VLM fine-tuning the loss is masked: image positions hold continuous embeddings with no vocabulary entry to predict, and prompt tokens come from the user, so only answer tokens count. Forgetting the prompt mask wastes gradient on teaching the model to imitate the user's question instead of answering it.
Cross-entropy in nats is the expected code length the model would need to encode the data, so minimizing it minimizes compression cost; the gap above the true entropy is the KL divergence from the data distribution to the model. Perplexity is for natural logs ( only when is measured in bits) and reads as an effective branching factor: GPT-2 small at 4.87 nats per token on a plain sentence has perplexity 131. Masking image and prompt positions simply removes terms from the sum, so the average runs over answer tokens only.
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
Related Problems on PixelBank
Decoder-only models read the image and the text through the same causal stack, which means an image patch early in the sequence never gets to look at a patch that comes after it. Is that a problem? The encoder-decoder transformer from the original 2017 paper avoids it by splitting the work: an encoder reads the whole input with bidirectional attention, and a separate decoder writes the output causally while consulting the encoder through cross-attention. T5 and Flan-T5 are the best-known text examples. In vision-language work the pattern appears in PaLI, which pairs a ViT with the 13B mT5-XXL encoder-decoder, and in BLIP-2's FlanT5 variants. The previous topic built the decoder-only side; this one covers the alternative in three steps: the bidirectional encoder, the cross-attention bridge, and the full sequence-to-sequence factorization, with an honest look at the compute claims. With a key-value cache, per-token decoding cost is similar in both designs, so the real trade-offs are bidirectional context, how parameters are split, and which pretrained checkpoints exist.
Definition
An encoder-decoder transformer has two stacks. The encoder applies unmasked self-attention to the full input once; the decoder applies causal self-attention over the output prefix plus cross-attention whose keys and values come from the encoder output. Together they model , separating input understanding from output generation.
In this topic
- 1Bidirectional Encoder
- 2Cross-Attention Mechanism
- 3Sequence-to-Sequence Formulation
Bidirectional Encoder
Why let every token see every other? In a causal stack the first patch of an image is encoded without any knowledge of the rest, and only later positions get global context. The encoder drops the mask, so each output is an attention-weighted mix of all inputs within a single layer. For images this matches the data: patches have no natural reading order, and a sky patch at the top can use a water patch at the bottom to recognize a reflection. The costs are that an encoder cannot generate text on its own, and its full score matrix holds about twice the entries of a causal lower triangle.
With no mask, is row-stochastic: each row sums to 1, but columns need not, so it is not doubly stochastic. Each output is a convex combination of all value vectors, so one layer already gives a global receptive field. A causal layer also reaches every earlier token in one layer; what it lacks is access to the later ones. The price is scores per head per layer, 65,536 at , versus under a causal mask.
Why might bidirectional encoding of image patches be advantageous over causal encoding?
Cross-Attention Mechanism
How does a decoder consult an encoder it does not share a sequence with? Cross-attention takes queries from the decoder's current hidden states and keys and values from the encoder output, scaled by as usual. Each decoder position therefore forms a probability distribution over encoder positions and reads a weighted average of their values. Nothing is masked, because the whole input is already known. With output and input tokens the score matrix is , and the encoder keys and values are computed once and reused at every decoding step. If the weights spread evenly over all positions, the output carries no grounding at all.
Cross-attention factorizes as , where queries come from a different distribution than keys. This computes a soft retrieval: for each decoder token, the dot product measures relevance, and softmax converts scores into a probability distribution over encoder positions. The output is the expected value under this retrieval distribution.
In a VLM using T5, when the decoder generates the word "red", which encoder representations might receive high cross-attention weight?
Sequence-to-Sequence Formulation
What does the split buy? The encoder runs once over and produces ; the decoder then generates , each token conditioned on its prefix through causal self-attention and on the encoder output through cross-attention. For a VLM, holds the image features plus the prompt and is the response. Parameters divide between understanding and generation, so a model can pair a large encoder with a smaller decoder. The common claim that this saves decoding compute is mostly outdated: a decoder-only model caches the image tokens' keys and values after one prefill, so each new token reads cached image keys, the same count a cross-attention layer reads.
Count attention reads per generated token with a KV cache. Decoder-only: step reads cached keys per layer. Encoder-decoder: self-attention keys plus cross-attention keys per decoder layer, again . The designs differ in prefill: decoder-only prefill sends all visual tokens through every LLM layer, while the encoder-decoder sends them through the encoder only. The often-quoted cost for decoder-only generation assumes no cache, which no production system uses.
What is the computational advantage of the encoder-decoder split for VLMs?
Theory Exercise
Problem:
Compare the attention patterns in a decoder-only VLM vs an encoder-decoder VLM for the task of image captioning. For a 256-token image and a 50-token caption, calculate the number of attention operations in the self-attention layers of each architecture.
Hints:
- Decoder-only: all 306 tokens in one sequence with causal attention
- Encoder-decoder: encoder processes 256 tokens bidirectionally, decoder processes 50 tokens causally + cross-attends to 256
- Count Q*K^T operations per layer
The language model was pretrained on integer token ids looked up in an embedding table, while a vision encoder emits real-valued vectors. How do you hand both to one transformer as a single sequence, and how does the model know where the picture starts and stops? The previous topics described the backbones; this one is about the input format they consume. The usual answer has three parts. First, a bridge projects each patch feature into the LLM's embedding width, so a visual token is a continuous vector living in the same space as word embeddings but never matching any vocabulary row. Second, special delimiter tokens mark the image span. Real templates use model-specific strings: Qwen2-VL's tokenizer contains vision_start, image_pad and vision_end entries, and LLaVA's processor expands one image placeholder into hundreds of feature slots. Third, multiple images are inserted at their positions in the conversation, and the sequence grows by every image's token count. We will build each part, count the tokens, and see why sequence length, not parameter count, often decides what a VLM can afford.
Definition
Multimodal tokenization turns an image-plus-text input into one embedding sequence for the LLM. Text is tokenized and embedded from the vocabulary; each visual feature is projected by a bridge into the same -dimensional space; and learned special tokens mark where each image's span begins and ends, so the model can tell modalities apart and refer to images by position.
In this topic
- 1Visual Token Creation
- 2Special Delimiter Tokens
- 3Multi-Image Sequences
Visual Token Creation
A visual token is not an id but a vector , where is the -th patch feature and is the language model's hidden width. Text tokens are rows of the embedding table; visual tokens are points the bridge computes fresh for each image, and the LLM's layers apply the same weights to both. Because they never coincide with vocabulary rows, the model cannot output an image token, which is why the loss skips those positions. The usual failures are a width mismatch between bridge and LLM, or a bridge trained so briefly that its outputs land far from anything the LLM learned to read.
The bridge is a learned map . A linear bridge's outputs lie in an affine subspace of at most dimensions, 1,024 of the 4,096 available when CLIP ViT-L feeds a 7B LLM, so visual tokens never fill the embedding space. Training does not make them look like word embeddings either: contrastive models already show a persistent modality gap between image and text embeddings (Liang et al. 2022). What matters is that the LLM's layers can read them, not that they resemble words.
A ViT-L/14 encoder produces 256 patch features of dimension 1024. The LLM uses dimension 4096. What is the projection matrix shape?
Special Delimiter Tokens
How does the model know where the picture ends? Special tokens such as and (generic names; each model defines its own) are added to the vocabulary, given new embedding rows, and placed around the visual span. Their embeddings are learned during fine-tuning, and because they appear in the chat template on every example, they signal when the modality switches. In practice the processor inserts one placeholder per visual feature and the model swaps those placeholder embeddings for the projected vectors. Qwen2-VL's tokenizer, for example, contains vision_start, image_pad and vision_end. A template mismatch between training and inference quietly degrades answers without raising any error.
A delimiter embedding is one more learned row , 4,096 parameters each in a 7B model, so adding a few is free. Their job is bookkeeping: with rotary positions, attention scores depend on relative offsets, so a fixed marker at each span boundary gives every text token a stable reference point for where the image ended. Whether attention forms clean block structure inside the span is empirical and model-dependent; FastV found that after layer 2 of LLaVA-1.5, image tokens receive only 0.21 percent of the attention the system prompt gets.
A VLM receives an image and the prompt "Describe this image in detail." Construct the full input token sequence.
Multi-Image Sequences
What changes with two or more pictures? Each image is encoded independently, its visual span is inserted where it appears in the conversation, and text can refer to 'the first image' because order is preserved. Image-index tokens such as make those references explicit in some templates. Sequence length grows by per image, where is that image's visual token count and 2 counts its delimiters, so five 576-token images already need 2,890 positions before any text. Flamingo took a different route: each text token cross-attends only to the most recent preceding image, enforced by masking, so the language sequence does not grow with image count.
With images of tokens each and text tokens, the total sequence length is (including delimiters). Self-attention cost scales as , so doubling the number of images approximately quadruples the attention cost. This quadratic scaling motivates token compression methods that reduce each while preserving information.
A user sends two images with the prompt: "Compare these two buildings." Each image produces 144 visual tokens. What is the total sequence length?
Theory Exercise
Problem:
A VLM uses a ViT-L/14 at 224×224 resolution, which yields a 16×16 grid of 256 patch tokens. The user uploads a 1024×1024 image. An "anyres"-style strategy tiles the image into 4 sub-images plus 1 downscaled global view, each encoded at 224×224. Calculate the total number of visual tokens.
Hints:
- Each 224×224 pass gives $(224/14)^2$ patch tokens
- 4 tiles + 1 global view = 5 forward passes
- Total visual tokens = tokens per pass × number of passes
Once image and text tokens share a sequence, which token is allowed to look at which? That single question separates the main VLM designs more than the choice of backbone does. The previous topic built the mixed sequence; this one examines how attention moves information across it. Three patterns matter. LLaVA, Qwen-VL and Idefics2 apply the LLM's ordinary causal self-attention to the whole sequence, so text tokens read image tokens, but image tokens placed first never read the text. Flamingo instead keeps the language model frozen and inserts new gated cross-attention layers (every fourth block in Flamingo-9B) whose tanh gates start at zero, so the model initially behaves exactly like the text-only LLM. The third is a side effect rather than a design: attention sinks, where early positions soak up attention regardless of content, which matters because the image usually sits right after the start token. FastV measured that after layer 2 of LLaVA-1.5, image tokens receive on average only 0.21 percent of the attention given to the system prompt. These patterns explain why token pruning works and why tiny details get lost.
Definition
In a VLM, the attention pattern fixes which positions each query may read: causal self-attention over the concatenated image and text sequence (decoder-only), cross-attention from text queries to visual keys and values (encoder-decoder or adapter designs), or gated cross-attention, where a learned scalar gate scales the visual contribution added to a frozen LLM's residual stream.
In this topic
- 1Full Causal Self-Attention (Decoder-Only)
- 2Gated Cross-Attention (Flamingo)
- 3Attention Sink and Visual Token Placement
Full Causal Self-Attention (Decoder-Only)
The simplest design changes nothing inside the LLM. Image tokens and text tokens are concatenated into one sequence , and each position attends to positions 1 through only. Every text token can read every earlier image token, so grounding is learned entirely through pretrained attention plus fine-tuning. The asymmetry matters: image tokens placed before the prompt are computed without knowing the question, so the same visual states must serve every possible question about that image. The cost is quadratic in ; with 576 image tokens and a 50-token prompt, over 99 percent of the causal attention entries involve an image token.
For a mixed sequence of image and text tokens, the causal attention matrix has non-zero entries. Text token attends to all image tokens plus preceding text tokens, so its attention entropy is . As grows large relative to , image tokens dominate each text token's attention budget.
In a decoder-only VLM with 256 image tokens and 50 text tokens, how many attention pairs involve image-to-text interaction?
Gated Cross-Attention (Flamingo)
How do you add vision to a frozen LLM without wrecking it on day one? Flamingo inserts new cross-attention layers between frozen LM blocks and scales each one's output by , where is a learnable scalar per layer initialized to 0. The residual form gives exactly at initialization, so text behaviour is unchanged. As moves away from zero, visual information flows in. The Flamingo ablation reports a 4.2 percent drop in overall score without this gating, and the authors saw training instabilities when it was disabled, which is the measured reason for the trick.
The gated residual preserves the Jacobian at initialization (when ), ensuring stable gradient flow through the pretrained LLM layers. As is learned, acts as a smooth interpolation coefficient, and peaks at , so the gate is most sensitive to gradient updates early in training.
Why is the gate initialized to rather than ?
Attention Sink and Visual Token Placement
Softmax forces each query's weights to be positive and sum to 1, so when no key is relevant the mass must go somewhere, and models park it on early positions, especially the start token. Xiao et al. named these attention sinks and showed that evicting the first tokens' keys and values collapses a sliding-window LLM. In a local GPT-2 probe, the last five positions of a 19-token sentence put 0.41 to 0.74 of their attention on token 0 in layers 4 to 12, against a uniform share of 0.053. In VLMs the image follows the start token.
Attention sinks arise because softmax normalization forces all weights to be positive and sum to 1. Early tokens accumulate high attention not because they are semantically important, but because the model uses them as a "no-op" sink when no token is strongly relevant — the residual stream's skip connection ensures useful information still propagates even when attention is diffuse.
A VLM places 256 image tokens at the start of the sequence. A user asks about a tiny detail in the image. Why might this detail get lost?
Theory Exercise
Problem:
Design an attention masking strategy for a VLM that needs to process 2 images interleaved with text, where each image should ONLY attend to its own patches (not the other image's patches), but text tokens should attend to both images. Write out the mask matrix structure.
Hints:
- Consider a block-diagonal mask for the image tokens
- Text tokens need full causal access to everything before them
- Image tokens from image 1 should not see image 2's tokens
Related Problems on PixelBank
A VLM inherits most of its reasoning, knowledge and language coverage from the language model it is built on; the vision side mostly decides what it can see. So which backbone should you pick? The previous topics treated the backbone as a generic decoder; this one looks at the families real VLMs chose and what each choice cost. LLaVA started on Vicuna, a LLaMA fine-tune, because it had open weights and strong instruction following. Mistral 7B added sliding-window and grouped-query attention and beat Llama 2 13B on every benchmark its authors reported. Phi-3-mini showed that a 3.8B model trained on 3.3T heavily filtered tokens could rival much larger ones, which made phone-sized VLMs plausible. Qwen2 shipped a 151,646-entry vocabulary that tokenizes Chinese far more compactly than LLaMA's 32,000. We will go family by family and check the specific claims, because several often-quoted ones are wrong; for example, Llama 2 13B does not use grouped-query attention (only the 34B and 70B models do).
Definition
An LLM backbone is the pretrained decoder-only language model a VLM reuses for reasoning and text generation. Backbone families differ in parameter count, tokenizer vocabulary, attention variant (multi-head, grouped-query, sliding-window), context length, training data and license, and those properties set the VLM's language quality, its sequence budget for visual tokens, and its inference cost.
In this topic
- 1LLaMA Family (Meta)
- 2Mistral / Mixtral (Mistral AI)
- 3Small Language Models (Phi, Gemma)
- 4Multilingual Backbones (Qwen, InternLM)
LLaMA Family (Meta)
Why did open VLMs converge on LLaMA? LLaMA 1 released 7B to 65B weights trained on up to 1.4T tokens, with RoPE positions, RMSNorm, SwiGLU feed-forward layers and no bias terms. Llama 2 trained on 2T tokens (40 percent more), doubled the context to 4,096, and added grouped-query attention, but only in its 34B and 70B models; the 7B and 13B keep full multi-head attention. Llama 3 moved to a 128K vocabulary and 15T tokens. Vicuna, a LLaMA fine-tune on ShareGPT conversations, was LLaVA's default language model. The risk of inheriting a backbone is inheriting its limits: a 4,096-token context caps how many visual tokens fit in one prompt.
RoPE encodes position by rotating query-key pairs: where is a block-diagonal rotation matrix. The inner product depends only on relative position , providing translation invariance. GQA reduces the KV cache from to with KV heads.
Why did LLaVA-1.5 switch from Vicuna-13B (LLaMA 1) to Vicuna-v1.5-13B (LLaMA 2)?
Mistral / Mixtral (Mistral AI)
Can a smaller model beat a bigger one through architecture and data? Mistral 7B combines grouped-query attention with sliding-window attention: each layer attends only to the previous positions, so per-layer cost grows linearly with length, while stacked layers still carry information forward by up to tokens after layers. Its paper reports beating Llama 2 13B on every benchmark tested. Mixtral 8x7B replaces each feed-forward layer with 8 experts and routes every token to 2, so it holds about 47B parameters but uses about 13B per token. Memory, however, scales with all 47B, and that is what VLM deployment must budget for.
Sliding-window attention restricts each token to a window of , cutting per-layer attention from to ; after layers information can travel up to positions. Mixtral's router picks of experts per token, so only those two expert FFNs run: about 13B of 47B parameters are active. Attention and embeddings are shared, which is why that is more than of 47B. Quality tracks total parameters more than active ones: the Mixtral paper reports beating Llama 2 70B on most benchmarks with 5x fewer active parameters.
How does Sliding Window Attention benefit a VLM processing a long image token sequence?
Small Language Models (Phi, Gemma)
Does a VLM need a 7B language model? Phi-3-mini has 3.8B parameters trained on 3.3T tokens of heavily filtered web and synthetic data, and its report says it rivals Mixtral 8x7B and GPT-3.5, scoring 69 percent on MMLU. Phi-3.5-Vision is a 4.2B model built from the same family plus an image encoder. Gemma 2 comes in 2B, 9B and 27B sizes. Small backbones roughly halve memory and per-token compute relative to 7B models, which is what makes on-device VLMs possible. The trade-off is stored knowledge: a smaller model simply holds fewer facts, so it answers fewer factual questions however well its training data was curated.
Data quality scaling suggests an alternative to Chinchilla: where is the effective dataset size after quality filtering. Phi demonstrates that aggressive data curation () can shift the Pareto frontier, achieving at a fraction of the inference cost.
Phi-3-mini (3.8B) vs LLaMA-2-7B: compare the inference cost for a VLM processing 256 image + 100 text tokens.
Multilingual Backbones (Qwen, InternLM)
How much does the tokenizer matter for a VLM? Qwen2 uses a vocabulary of 151,646 tokens (151,643 regular plus 3 control tokens), InternLM2 is likewise built for Chinese and English, while LLaMA 1 and 2 use 32,000 entries. With a larger vocabulary, more Chinese characters and common words become single tokens, so text sequences are shorter and more of the context window is left for visual tokens. The costs are a bigger embedding table and output layer: at width 4,096, a 152K vocabulary needs about 621M parameters per matrix versus 131M for 32K. Qwen-VL and InternVL build on these backbones for multilingual image understanding and text reading.
Vocabulary size sets the embedding and output matrices at parameters each, about 621M at and , and the output softmax costs per generated token. In exchange, fewer tokens per sentence shrink every other cost, since attention is quadratic and the FFN linear in length. In a local probe a Chinese sentence took 35 LLaMA tokens versus 14 Qwen2.5 tokens (2.5x), while English was nearly equal (15 versus 14). The right vocabulary therefore depends on the languages in your traffic.
Why does Qwen use a 152K vocabulary vs LLaMA's 32K? What impact does this have on VLMs?
Theory Exercise
Problem:
You are designing a VLM for a mobile health application that needs to: (1) run on a smartphone GPU, (2) process medical images at 512×512 resolution, (3) support English and Spanish, (4) generate structured reports of 200+ tokens. Which LLM backbone would you choose and why?
Hints:
- Mobile GPU = strong memory constraint (4-8GB)
- Medical images need fine-grained detail = many visual tokens
- Bilingual = need adequate vocabulary coverage
- Consider quantized model sizes
Bigger backbones score higher, but a 13B VLM costs about twice the compute per token of a 7B one, needs twice the memory, and may not fit the GPU you deploy on. How should you choose? Scaling laws turn the question into arithmetic. Kaplan et al. (2020) and then Hoffmann et al. (2022, Chinchilla) fit loss as a function of parameters and training tokens; Chinchilla's fit says a compute-optimal model sees about 20 tokens per parameter. Modern backbones ignore that on purpose: Llama 3 8B saw 15T tokens, about 94 times the Chinchilla amount, because serving, not training, dominates lifetime cost. The previous topic compared backbone families; this one supplies the numbers to pick a size. For a VLM, three costs stack: the LLM's parameters, the number of visual tokens it must process per image, and the memory for weights and KV cache at deployment. We will work through the Chinchilla rule, a FLOP model of VLM inference showing how model size and visual token count multiply, and the quantization arithmetic that decides whether a 13B model fits on a 24 GB card.
Definition
Scaling laws are empirical fits of a model's loss as a smooth function of parameter count , training tokens and training compute . Chinchilla's fit, , implies that compute-optimal training uses roughly 20 tokens per parameter; model selection then weighs that training optimum against inference and memory cost.
In this topic
- 1Chinchilla Scaling Law
- 2VLM-Specific Scaling
- 3Quantization for Deployment
Chinchilla Scaling Law
Given a fixed training budget , should you train a bigger model briefly or a smaller one for longer? Hoffmann et al. found both should grow together, and , which works out to about 20 tokens per parameter: a compute-optimal 7B model sees about 140B tokens. That optimum ignores inference. A model served to millions of users is cheaper overall if it is smaller and over-trained, which is why Llama 3 8B was trained on 15T tokens. The fitted constants are also uncertain: Epoch AI's replication found that the paper's parametric fit did not match its own data well, although the corrected fit still supports about 20 tokens per parameter.
Minimizing subject to gives and ; with the fitted and that is and , close to the equal split of the headline rule. Over-training moves along a fixed : Llama 3 8B's 94x extra data lowers the fit's predicted loss only from 2.164 to 1.949, but every inference call stays at 8B cost, which is the point.
LLaMA 3 8B was trained on 15T tokens. The Chinchilla-optimal data for 8B parameters is ~160B tokens. By what factor is LLaMA 3 over-trained?
VLM-Specific Scaling
VLM inference cost is dominated by the LLM backbone processing the concatenated visual + text tokens. The vision encoder adds a fixed overhead per image. Scaling the LLM backbone from 7B to 70B increases inference cost by ~10x for the same input. Scaling from 256 to 576 visual tokens increases cost by ~2.25x (quadratic in attention, but linear in the FFN which dominates). This creates a two-dimensional scaling problem: model size vs. visual token count.
Prefill costs about FLOPs for the dense layers, where is the LLM's parameter count and , are the visual and text token counts, plus an attention term that grows with per layer and matters only when the sequence is long relative to model width. Each generated token then costs about plus attention over the cached prefix. The vision encoder adds a per-image constant, roughly 0.35 TFLOP for a 304M-parameter ViT-L over 577 tokens. So visual tokens multiply prefill cost, while model size multiplies every step.
Compare the approximate LLM inference FLOPs for: (A) 7B model, 256 visual + 100 text tokens vs (B) 13B model, 576 visual + 100 text tokens.
Quantization for Deployment
Quantization reduces the precision of model weights from 16-bit floats to lower bit-widths. A 7B model at FP16 requires ~14GB; at 4-bit (GPTQ/AWQ), only ~3.5GB. This is critical for deploying VLMs on consumer GPUs or edge devices. Modern 4-bit quantization (GPTQ, AWQ, GGUF) loses minimal accuracy on language benchmarks, but the impact on visual understanding tasks is less studied. The KV cache for long visual token sequences also benefits from quantization.
Quantization maps floating-point weights to a discrete grid: where is the scale factor. The quantization error grows as bit-width decreases, but outlier-aware methods (AWQ) weight the error by activation magnitude: , preserving the channels that matter most for the output distribution.
A VLM with a 13B LLM backbone needs to run on an RTX 4090 (24GB VRAM). The ViT encoder uses 430MB. What quantization level is needed?
Theory Exercise
Problem:
You have a training budget of 10,000 dollars on cloud GPUs (A100-80GB at 2 dollars per GPU-hour). Design the optimal VLM configuration: choose the LLM backbone size, vision encoder, and visual token count. Justify using scaling law reasoning.
Hints:
- 10,000 / 2 = 5,000 A100 GPU-hours
- An A100 peaks at 312 TFLOP/s in BF16; real training reaches roughly 40 percent of that
- Consider both training and the resulting inference cost
- Compare the budget with what published VLM recipes actually used