TL;DR
Chameleon is a family of models, with 7 billion and 34 billion parameters, that treats images and text as one stream of discrete tokens. A single transformer is trained from scratch on interleaved text, images and code, so it can read and write documents in which pictures and words appear in any order. At 34 billion parameters it is competitive with much larger text models and beats several image-and-text models on captioning and visual question answering.
Builds on: Transformer, Vector Quantization, Instruction Tuning · Leads to: Vision-Language Model, Autoregressive Model
Why it mattered
Most multimodal systems before 2024 used a separate encoder for images and a separate decoder for generating them, joined to a language model at some point in the pipeline. Chameleon showed that one token-based transformer could handle both understanding and generation of mixed documents, with no modality-specific parts beyond the tokenizer. This made "a document with pictures in it" a native input and output rather than a special case.
The approach is now a common reference point for unified multimodal models. Its public results are the main evidence that early fusion (mixing modalities from the first layer, rather than attaching an image module to a finished language model) can reach strong benchmark numbers. Its training notes on stability are often cited by people who train large models, because they describe a divergence that the usual recipe does not catch.
The problem
Before Chameleon, the standard recipe for images and text was late fusion: a vision encoder produced features that were inserted into a language model, which then generated text. Images went in, but images did not come out, and interleaved documents with several images were awkward.
Using a single model for both directions raised three problems:
- An image has to become a sequence of discrete symbols, the way a word does, so that the same transformer can read it (Vector Quantization and Subword Tokenization are the two ingredients).
- The shared weights see text and image tokens with very different statistics. Training then became unstable: the softmax is invariant to adding a constant to all logits, so the two modalities compete by slowly raising the output norms, and the runs diverged late in training. The stability section below covers the fixes.
- Generation of a mixed document needs decoding rules that depend on which modality the model is producing, which affects how fast inference can run.
Chameleon addresses each of these in turn.
How it works
Follow one example from input to output. Suppose the input is a 512 by 512 pixel photo followed by the question "What is in the picture?".
flowchart LR A[512 x 512 photo] --> B[Image tokenizer: 1024 codes] C[Question text] --> D[Text BPE tokens] B --> E[One token sequence] D --> E E --> F[Single transformer predicts next token] F --> G[Text answer tokens]
-
Turn the image into tokens. The image is cut into a grid. The paper's image tokenizer, based on the approach of Gafni et al. (2022), encodes a 512 by 512 image into 1024 discrete tokens. Each token is an index into a learned codebook of 8192 entries. The grid has 32 by 32 positions, so each token covers one 16 by 16 block of pixels, and tokens. Check: , and . The image has pixels, which is pixels per token times tokens.
-
Turn the text into tokens. The question is split by a byte-pair style tokenizer (Subword Tokenization) into a short sequence of text tokens. The vocabulary has 65,536 entries. The 8192 image codes are part of that vocabulary, so both kinds of token live in one table. Check: a text token and an image token are both just integers in the same range, so the transformer does not need to know which is which at the input layer.
-
Put them in one sequence. The image tokens are placed in order with the text, between special markers that say "image starts here" and "image ends here". The model then sees a single list of integers, with no separate image branch. Check: the sequence is ordered exactly as in the document, so a picture that appears between two sentences sits between those sentences in the input.
-
Predict the next token. The transformer is trained to predict the next token given all tokens before it. This is the same objective used by text-only language models, applied to a sequence that happens to contain image codes (Autoregressive Model). Check: at generation time, the model can produce text tokens or, after an image-start marker, image tokens. Image tokens are decoded back into pixels by the image tokenizer.
-
Generate the answer. The model writes the answer as text tokens. If the user had asked for a picture, the model would emit an image-start marker and then 1024 image tokens, which the tokenizer decodes into an image. Check: the same weights handle both directions. The only change is which tokens the decoder is allowed to produce, which the inference section handles with masking.
The math
A multimodal model in which every input modality is converted into tokens from one shared vocabulary and then processed by the same transformer from the first layer onward.
Step 1 in symbols
The image tokenizer assigns each image patch to its nearest codebook vector :
Here are the codebook vectors, and is the index of the chosen one. This index is the image token. The image as a whole becomes indices, one per patch.
Step 2 in symbols
The vocabulary has entries in total, and the image codes are among them. So the input is a sequence of indices drawn from one table, where the image codes occupy a fixed block of of those entries. Text and image tokens share one embedding matrix and one output softmax.
Step 3 in symbols
Training minimises the standard next-token loss over the mixed sequence:
Here is the transformer's predicted probability of the true token, given the tokens before it, and denotes all the weights. Summing over every position covers text and image tokens alike.
Step 4 in symbols
Each attention layer computes its softmax over the query and key vectors. Chameleon applies layer normalization to both before the product, which is the query-key normalization (QK-Norm) described in the paper:
Here is the head dimension and is layer normalization (Layer Normalization). Normalizing the inputs to the softmax keeps the attention logits from growing without bound.
Step 5 in symbols
The output softmax over the vocabulary uses partition function . The paper adds a regularizer, called z-loss in the paper, that penalises a large :
The term is zero when and grows as the output logits drift.
Results
The paper reports two main numbers for each claim. The table values below are the paper's, for the 34 billion parameter model unless noted.
Text-only tasks. On the MATH benchmark, Chameleon-34B reaches 22.5 with a single greedy sample (maj@1), against 13.5 for Llama-2 70B. On GSM8k it reaches 61.4 against 56.8 for Llama-2 70B, both with one sample. On MMLU it reaches 65.8, against 70.6 for Mixtral 8x7B and 71.8 for Gemini Pro. The paper says the 34B model outperforms Llama-2 70B on five of eight commonsense and reading tasks. The 7B model is competitive with Llama-2 7B on those same tasks.
Image captioning (COCO, CIDEr). Chameleon-34B with 2 in-context examples scores 120.2, above Flamingo: a Visual Language Model for Few-Shot Learning at 113.8 and IDEFICS at 116.6, which both use 32 examples. The supervised fine-tuned version reaches 140.8 with no examples.
Visual question answering (VQAv2). The pre-trained 34B model with 2 examples scores 66.0, which is close to the 32-example Flamingo-80B score of 67.6. The multitask fine-tuned model reaches 69.6. LLaVA-1.5 (Improved Baselines with Visual Instruction Tuning) beats Chameleon on VQAv2, which the paper attributes to its extra fine-tuning on conversation and region-level VQA data.
Human evaluation on mixed-modal prompts. The authors built 1,048 prompts, of which 441 are mixed-modal. In pairwise comparisons, Chameleon-34B wins 60.4 percent against Gemini Pro and 51.6 percent against GPT-4V, where both baselines are the versions whose text replies were augmented with generated images (Gemini+ and GPT-4V+).
Limits. The paper says the image tokenizer reconstructs images with a lot of text poorly, which caps the model on heavy OCR tasks. On MMLU and GSM8k the model trails the best closed systems. The human evaluation uses the authors' own prompt set and their own annotators, so it measures a specific setting, not general quality.
Reading guide
- Section 1 (Introduction): the case for mixed-modal documents as the goal. Needs Transformer and Vision-Language Model.
- Section 2.1 (Tokenization): the image codebook of 8192 entries and the 65,536-entry text vocabulary. Needs Vector Quantization and Subword Tokenization.
- Section 2.2 (Pre-training data): the two-stage data mix and the 50/50 caption ordering. Needs Autoregressive Model.
- Section 2.3 (Stability): QK-Norm, dropout, norm reordering and z-loss. Needs Softmax, Layer Normalization, RMS Normalization, Dropout and Attention Mechanism.
- Section 2.4 (Inference): masking, streaming and fixed-size image blocks. Needs Attention Mechanism.
- Section 3 (Alignment): supervised fine-tuning on mixed-modal data. Needs Instruction Tuning.
- Section 4 (Human evaluation and safety): the prompt set and win rates.
- Section 5 (Benchmarks): the tables. Needs Image Captioning and VQA: Visual Question Answering for the task definitions.
Check yourself
QuestionRecall: what is early fusion, and how does Chameleon apply it?Show answer
Early fusion converts every modality into tokens from one shared vocabulary and processes them with the same transformer from the first layer. Chameleon tokenizes images into 1024 discrete codes from an 8192-entry codebook, adds them to the 65,536-entry text vocabulary, and trains a single transformer on the interleaved sequence.
QuestionComputation: an image is 256 by 256 pixels. If the tokenizer uses one token per 16 by 16 block, how many image tokens does it produce?Show answer
The grid has positions along each side, so tokens. Check: the image has pixels, and each token covers of them, so tokens.
QuestionWhy: the paper adds QK-Norm and z-loss. What problem do they address, and why is the first one not enough?Show answer
Both address norm growth that eventually causes training to diverge. QK-Norm controls growth inside the attention softmax. But the output softmax over the vocabulary also drifts, because the partition function can grow. Z-loss penalises a large directly, so it is needed as well. For the 34B model the paper found z-loss and norm reordering were required, and dropout was dropped.
QuestionApplied: a team wants a model that writes a short report with several charts placed between paragraphs. Which part of Chameleon's design makes this natural, and what would they still need to check?Show answer
The design treats charts and text as one token sequence, so a chart can appear between paragraphs in both input and output, with image-start and image-end markers marking its place. The team would still need to check how well the image tokenizer reconstructs their charts, since the paper says text-heavy images are a known weakness, and they would need to evaluate chart reading on their own data.