Python · cell 1
Training a vision-language model means deciding, stage by stage, which of its parts may change and what data they learn from. These choices decide what the finished model can do as much as its architecture does. Getting them wrong can quietly cost the model skills it already had.
A vision-language model (VLM) is a language model that can also read images. The kind this chapter builds has three parts. A pretrained vision encoder turns an image into a grid of vectors. A small new connector maps those vectors into the language model's input space. A pretrained large language model (LLM) reads them alongside the text and writes the answer. A part is frozen during a stage when its weights are held fixed, and trained when they may change.
One controlled experiment shows how much these choices matter. In a study called VILA, Lin et al. (2023) took one vision encoder and the Llama-2-7B language model. They pretrained the pair on 25 million images from web pages in which images and paragraphs alternate. In one run the language model was frozen and only the connector trained. In a second run the language model trained too. Both were then fine-tuned on the same instructions, with the language model unfrozen.
With no examples in the prompt, the two models scored the same, 66.8 on average over two captioning and two question-answering benchmarks. With four solved examples in the prompt, the frozen-LM model fell to 57.6 while the other rose to 68.8. Freezing the language model during pretraining had removed in-context learning, the ability to pick up a task from examples placed in the prompt (§6.8).
A third run kept the language model trainable but swapped the web pages for 25 million images with short web captions. Its score on MMLU, a text-only multiple-choice exam of knowledge in 57 subjects, fell from 46.0 to 28.8 percent. Training on short captions had cost it more than a third of its score on a test that has nothing to do with images. The encoder and the language model were the same in every run. Only what was trained, and on what data, changed.
The earlier sections of this chapter decided where the picture enters the language model and how many vectors it becomes. §31.1 maps each image patch's feature to a vector the size of a word embedding and places those vectors in the input sequence. §31.2 keeps the language model frozen and lets it look at a compressed image through new cross-attention layers. §31.3 compresses the image into 32 vectors with learned queries. This section takes the wiring as given and asks how to train it. At each stage, what is trained, on what data, and what stays frozen?
We will count the memory each stage needs and read the controlled studies on freezing and data. We will prove why a little text-only data protects text skills, and build the data that teaches a model to read, count, and point. Then we adapt preference tuning and reinforcement learning to images, and end with the published recipes side by side.
The order of training follows from one mismatch. The encoder and the language model are pretrained and know a great deal. The new connector between them starts random and knows nothing. So training proceeds in stages, each fixing one problem.
Two terms recur throughout. An interleaved document is a web page or PDF kept in its original order, with images among paragraphs, as opposed to a single image with its caption. LoRA keeps a weight matrix frozen and trains a small correction added to it, the product of two thin matrices, so the correction has low rank (§14.5).
For models that put image vectors into the token sequence, the first three stages all minimize the same loss. It is the masked next-token loss of §14.3. The model predicts each trained token from everything before it, and the image's slots and the user's tokens are never prediction targets (§31.1). What changes from stage to stage is the data, and the data always come as a mixture of sources.
In plain words, each stage chooses which parameters may move and how often each kind of data is shown. For example, a stage that draws 45 percent of its examples from interleaved pages, 45 percent from captions, and 10 percent from text has . A batch of 256 examples then holds about 115, 115, and 26 of each. Everything else in this section is evidence about those two choices, the trainable set and the weights .
Freezing is first a memory decision. Recall the count from §10.1. Training one parameter with Adam in mixed precision costs 16 bytes. That is 2 for its weight in bf16 (16-bit floating point), 2 for its bf16 gradient, 4 for a master copy of the weight in fp32 (32-bit floating point), and 8 for Adam's two fp32 moment estimates. A frozen parameter needs only its bf16 weight, 2 bytes, because it has no gradient and no optimizer state.
LoRA sits between the two. Its base weights are frozen at 2 bytes each. Each adapted matrix, mapping inputs to outputs, gains new parameters at rank , and those train at 16 bytes. Here model states means weights, gradients, and optimizer state together, everything except the activations.
Activations are a separate bill, and freezing does not remove it. Activations are the outputs of every layer that the backward pass needs. In stage 1 the projector sits below the whole language model. Its gradient is built from the gradient of the loss with respect to the language model's input, and backpropagation reaches that input only by passing back through every layer above it (§31.1 derives this gradient). So every layer's activations are still stored.
What freezing does save is weight gradients, optimizer state, and about a third of the compute. A forward pass costs about FLOPs per token for parameters, and a full backward pass about , half for activation gradients and half for weight gradients. A frozen language model skips the weight half, so a step through it costs about instead of . Only a module that no gradient has to cross, such as a frozen encoder at the bottom, can skip storing activations. Its features can even be computed once and saved to disk.
The planner below does the same accounting for several published recipes, stage by stage. Pick a model and a stage, switch a module between frozen, train, and LoRA, and watch the bill move. The bar's full length is what training every parameter would cost.
Here are the answers to check against. Flamingo-80B's trained 13 percent take more than half of its model-state memory, about 163 GB of 304 GB, because each trained parameter costs eight times a frozen one. For Idefics2-8B at rank 64, the language model's line grows from about 17 GB to about 116 GB, roughly sevenfold. The interview version of this is a question you should answer in under a minute. Given a recipe, how much memory do its model states need, and which module dominates?
Write the memory planner for any recipe. A model is a dict modules that maps each module name to a pair (n_params, shapes). Here shapes lists the (d_in, d_out) of every matrix LoRA would adapt in that module. A stage is a dict plan that maps module names to "full", "frozen", or ("lora", r), and any module missing from plan is frozen.
Implement lora_count(shapes, r), the number of LoRA parameters for those matrices at rank r. Then implement stage_memory(modules, plan, bytes_frozen=2, bytes_trained=16), which returns (n_trainable, total_bytes) as Python ints. A LoRA module keeps all its base parameters frozen and trains only its adapters. The setup defines LLAVA13, the LLaVA-1.5-13B model with its language model's LoRA shapes.
Alignment trains the new connector alone, on images with captions, so that its outputs become vectors the frozen language model can read. LLaVA-1.5 (Liu et al. 2023b) aligns its MLP projector on 558K captioned images with both large models frozen. It trains for one epoch at a learning rate of and batch size 256. Instruction tuning then runs at with batch size 128. The first learning rate is fifty times higher, and that is safe because only the random projector moves, so nothing pretrained can be damaged. Alignment takes about 6 of the recipe's 26 hours on 8 A100s.
Why not skip alignment and train everything at once? The danger is the first few hundred steps. A random connector produces vectors unrelated to anything the language model has seen. The loss on the caption tokens is large, and its gradient flows into pretrained weights that cost a great deal of compute to learn. Stage 1 keeps that large early gradient away from them. The original LLaVA (Liu et al. 2023a) tested this on ScienceQA, a benchmark of multiple-choice science questions, many with diagrams. Skipping alignment and training directly on ScienceQA lost 5.11 points of accuracy (§31.1).
Other recipes protect the pretrained weights in other ways.
All three follow one principle. A new module must start producing sensible outputs before the pretrained modules around it are allowed to move fast. Freezing is the bluntest way to enforce it, and separate learning rates with warmups are the most flexible. In an interview, expect to be asked why alignment uses a learning rate fifty times higher than instruction tuning. The answer is that only the random connector moves, so a large step cannot damage anything pretrained.
Alignment teaches the connector to describe single images in the language model's input space. It does not teach the system to read several images in one context, to use an image as evidence in a long argument, or to keep its text skills while doing so. Those come from a second, much larger stage, multimodal pretraining. The controlled studies agree on four things it needs.
Unfreeze the language model. In VILA's Table 1, the model whose language model stayed frozen during pretraining matched the unfrozen one with no examples in the prompt (66.8 against 66.8). With four examples it lost 11 points (57.6 against 68.8). The authors measured why. With the language model frozen, image and text embeddings became similar only in the first layers. Unfreezing it aligned them deep in the network too. They call this the deep embedding alignment hypothesis, and it is an empirical finding about their models, not a theorem.
Use interleaved documents, not only captions. A caption is short. It averages about 23 tokens per image in the COYO caption dataset, against 122.5 in the MMC4 dataset of interleaved web pages. A language model trained only on captions drifts toward writing short captions. In VILA's Table 3, pretraining on COYO dropped MMLU from 46.0 to 28.8 percent and made four-shot accuracy worse than zero-shot (50.3 against 51.1). Interleaved MMC4 dropped MMLU only to 40.7 and lifted four-shot accuracy to 70.9.
The authors then cut each MMC4 document into separate image-text pairs, keeping exactly the same text, and the benefit vanished (MMLU 32.4, four-shot 44.5). So the interleaved structure itself, several images among long paragraphs, is what teaches multi-image reading, not merely the longer text. §31.2 showed that a cross-attention model needs such data by design. Here a decoder-only model turns out to need it too.
Mix all three kinds. The MM1 study of multimodal pretraining (McKinzie et al. 2024) varied the mixture of interleaved documents, captions, and text with everything else fixed. It stated four lessons.
Its final mixture is 45 percent interleaved documents, 45 percent captioned images, and 10 percent text. It trains every module for about 400B tokens, with up to 16 images per sequence.
Watch the stability. The two pretrained models, the vision encoder and the language model, are often called the backbones. The team behind Idefics2 (Laurençon et al. 2024a) could not train with both backbones unfrozen. The loss diverged even after aggressive learning-rate cuts and gradual unfreezing. LoRA on the backbones, with the new connector trained in full, was stable. It lifted their average score from 60.3 with frozen backbones to 69.5.
Idefics2 then pretrained on about 1.5 billion images and 225 billion text tokens in two phases. The first ran at up to 384 pixels with 70 percent interleaved documents from the OBELICS dataset and 30 percent image-text pairs. The second ran at up to 980 pixels with 45 percent OBELICS documents, 35 percent pairs, and 20 percent PDF pages, which need the resolution to be legible.
At the largest scale these choices merge into continued pretraining of the whole system, and the frontier mixes vision in from the very start. Kimi Team (2026) asked how to spend a fixed budget of vision and text tokens in Kimi K2.5. The usual answer is to add vision late at a high ratio, and they found it worse. Holding the totals fixed, they compared three schedules.
| when vision enters | vision share of tokens | vision reasoning | text knowledge |
|---|---|---|---|
| from the start | 10 percent | 43.8 | 45.5 |
| halfway through | 20 percent | 40.7 | 43.9 |
| at 80 percent of training | 50 percent | 39.0 | 43.1 |
Early, low-ratio mixing won on vision and on text alike. When vision arrived halfway through or later, text performance first dipped and then recovered only slowly. Early mixing avoided the dip. Kimi K2.5 itself continued from the Kimi K2 language model with about 15 trillion more tokens of joint vision and text pretraining.
VILA and MM1 both found that a small share of text-only data protects text skills. VILA's authors put it as the skills being "temporarily hidden, but not forgotten". Adding 1M text instructions back during SFT recovered the whole MMLU loss, 51.4 percent against 51.2 for the same language model fine-tuned on text alone. Why should a small share be enough?
Take two losses, a text loss and a multimodal loss . Training on a mixture with text weight minimizes . The question is where the minimum of lies.
Proof. For every , and . With and , adding the weighted inequalities gives
with equality exactly when both inequalities are equalities. The parameter attains this bound, so the bound is the minimum of . A parameter is therefore a minimizer if and only if it attains the bound, that is, if and only if it minimizes both losses. For the text term has weight zero, so cannot tell apart two parameters with equal multimodal loss and different text losses. ∎
In plain words, if one model can be good at both tasks, then any positive share of text data, however small, makes "good at both" the only optimum. The share changes how fast training gets there, not where it ends.
The theorem says where training ends, not what happens on the way. On the way, the text loss rises whenever the multimodal gradient pushes the weights in a direction the text loss cares about. A small text share acts like a spring that pulls the weights back in exactly those directions, with a stiffness proportional to . A weak spring still wins in the end, but slowly. The derivation below makes this precise.
Start from a language model at a minimum of the text loss, so and its Hessian is positive semidefinite, . Move it by . A second-order Taylor expansion gives
The quadratic term is positive whenever has a component outside the null space of , that is, in any direction the text loss cares about.
With , every step follows , which does not depend on the text loss at all. The displacement accumulates, and so does the damage. With , the gradient also contains . That is a restoring force proportional to the displacement, acting in exactly the directions where the text loss has grown, like a spring of stiffness . The same mechanism makes replay of old data work against catastrophic forgetting (§14.4).
The theorem's assumption is the part to doubt. It holds when the model has the capacity to be good at both tasks. VILA's full recovery suggests that is true for a 7B model and a modest visual curriculum. When capacity is short, no common minimizer exists, and the weight sets a trade-off instead.
The two cells below show both regimes in a toy. The model is a parameter vector . The text task and the image task are each a set of linear equations in , and the loss is squared error. It is a toy that illustrates the mechanism and nothing more. The evidence that it applies to VLMs is VILA's and MM1's.
Now take away capacity. With 50 parameters for 60 equations, no parameter vector solves both tasks, and the weight sets the compromise.
The first few percent of text data buy the most. Moving from 0 to 0.05 cuts the text loss from 16.66 to 4.04 at a cost of 0.025 on images. Moving it on from 0.05 to 0.5 buys a further 3.2 of text loss for 1.0 of image loss. The trade-off curve is steepest at the start. That is the logic behind MM1's 10 percent and VILA's joint SFT. A small text share is nearly free when capacity suffices, and the cheapest protection available when it does not.
After architecture and freezing, data decides what a VLM can do, and each kind of data teaches something specific. The table lists the main kinds, what each is for, and where open recipes got it. OCR, optical character recognition, means reading printed text from an image. Grounding means tying a phrase to a place in the image, as a box or a point. VQA, visual question answering, is the task of answering a short question about an image.
| data type | examples | what it teaches | notes |
|---|---|---|---|
| captions | LAION, COYO, CC3M, recaptioned web images | naming what is in an image, zero-shot description | short and noisy unless recaptioned (§30.5) |
| dense captions | ShareGPT4V, PixMo-Cap | detail, attributes, spatial layout | a strong lever against hallucination |
| interleaved documents | MMC4, OBELICS | several images in one context, few-shot learning, text retention | weak image-text correspondence per sentence |
| OCR and documents | PDFA, rendered text, Docmatix | reading printed text, layout | needs high resolution (§31.5) |
| charts, tables, diagrams | ChartQA, PixMo-Docs, AI2D | extracting numbers, reasoning over figures | often synthesized from code |
| screenshots and UIs | screenshot-to-HTML parsing (Pix2Struct), WebSight | web pages, apps, GUI elements | feeds computer-use agents (§24.5) |
| grounding | RefCOCO, Visual Genome, PixMo-Points | boxes and points for named things, counting | needs an output format (see below) |
| academic VQA | VQAv2, GQA, OKVQA, A-OKVQA | short factual answers | makes models terse without format prompts |
| text-only instructions | ShareGPT, FLAN, math and code sets | keeping text skills, instruction following | 10 percent or so (see above) |
| video | captioned clips, video QA | time, motion, events | a frame and token budget (§31.5) |
Reading text in images needs data of its own, because captions rarely contain the text an image shows. Idefics2 added PDF pages and rendered text in its second pretraining phase. Its ablation measured DocVQA after a short fine-tune. Raising the resolution from 384 to 768 pixels lifted the score from 22.6 to 42.9, and adding the text-reading data lifted it further to 49.9. The authors saw no loss on other benchmarks.
For the next model, Idefics3, the same team built Docmatix, 2.4 million images and 9.5 million question-answer pairs from 1.3 million PDFs. The pipeline ran OCR on each page and asked a text-only language model to write questions and answers from the transcription. Idefics3 scored 13.7 points higher than Idefics2 on DocVQA, a benchmark of questions about scanned documents (Laurençon et al. 2024b). Pix2Struct (Lee et al. 2022) went further. It pretrained a model to turn screenshots of web pages, with parts masked out, into simplified HTML. That single objective covers OCR, layout, and captioning at once.
Instruction tuning then turns all of this into a chat model. LLaVA-1.5's 665K mixture is the reference point that most open recipes still resemble.
Later recipes kept the idea and grew the mixture. MM1's SFT used about 1.45M examples, including detailed captions and document and chart sets, with text-only instructions to keep text skills. Molmo replaced format prompts with short style tags. It prefixes VQAv2 questions with vqa2:, for example, so the model writes benchmark-style answers only when asked for them. Idefics2 assembled 50 datasets into a collection called The Cauldron and removed any example that overlapped the evaluation sets, a step worth copying (§22.3).
A language model outputs a bounding box by writing its coordinates as ordinary text tokens in an agreed format. This is the simplest answer, and the one most VLMs use. Nothing about the architecture changes. The model needs only training data in that format.
In plain words, a box is a short sentence of digits, and training teaches the model to say the right digits after the right phrase. Scaling to gives the same object the same coordinates whatever the image's pixel size. The price is a fixed precision of a thousandth of a side. A predicted box usually counts as correct when its intersection over union (IoU) with the true box is at least 0.5. IoU is the area the two boxes share divided by the area they cover together (§27.6).
The cell turns box annotations into the grounded question-answer strings a data pipeline would emit, in both conventions.
Build four pieces of a grounding-data pipeline. Boxes are tuples (label, x1, y1, x2, y2) in pixels, for an image of width W and height H.
normalize_box(box, W, H) takes (x1, y1, x2, y2) and returns a tuple of four Python ints by this book's Qwen-VL convention. That is for the coordinates and the same with for the coordinates, clipped below at 0.box_string(label, nbox) returns <ref>label</ref><box>(X1,Y1),(X2,Y2)</box> with no spaces.count_objects(boxes, noun) counts the boxes whose label equals noun, or whose label plus "s" or plus "es" equals noun. So "dogs" counts "dog" boxes and "buses" counts "bus" boxes.which_is_left(boxes, a, b) compares the horizontal pixel centers of the first box labeled a and the first box labeled b. It returns whichever label is strictly further left, or "neither" if the centers are equal. Compare in pixels, never after normalizing.When the first open VLMs appeared in 2023, almost no visual instruction data existed, and paying people to write hundreds of thousands of conversations about images is slow and expensive. So every open recipe generates most of it with models. This follows the pattern for text, where a strong model writes instructions and answers for a weaker one, called distillation (§14.2). The three main approaches differ in who sees the image.
A text-only teacher. LLaVA (Liu et al. 2023a) gave a text-only GPT-4 each COCO image's five human captions and its object boxes, plus a few hand-written examples. It asked for three kinds of output, conversations, detailed descriptions, and complex reasoning questions. That produced a 158K set (58K, 23K, and 77K) that both LLaVA and LLaVA-1.5 train on. It is cheap, and its spatial facts are exact because they come from boxes. But the teacher never sees the image. Everything it writes beyond the captions and boxes is an inference that may be false, and the student is trained to say it as if it saw it.
A multimodal teacher. ShareGPT4V (Chen et al. 2023) asked GPT-4V, which does see the image, for 100K detailed captions averaging 942 characters, with prompts adapted to each image source. The authors fine-tuned a captioning model on those and used it to caption 1.2 million more images (826 characters on average). Replacing only the 23K detailed descriptions in LLaVA-1.5's 665K mixture with captions from the 100K set, 3.5 percent of the data, improved LLaVA-1.5 on their benchmarks. Pretraining on the 1.2M captions, with the latter half of the vision encoder's layers unfrozen, helped further.
Dense, accurate captions are among the most effective levers against hallucination in these studies. The price is dependence on a proprietary model. Its terms of use may forbid training competing models, and the student inherits its errors.
People describing images aloud. Molmo's authors (Deitke et al. 2024) wanted open data made without any VLM, in a collection they call PixMo. They asked annotators to describe each image aloud for 60 to 90 seconds, transcribed the speech, and had a text-only language model clean up or merge the transcripts. Talking is faster than typing, and a minimum duration keeps descriptions long. The result was 712K images with captions averaging 196 words, against 11 for COCO's captions.
Other PixMo sets generate data from an exact description, as Docmatix does. For charts, tables, and documents, a language model wrote code that renders an image, 255K images in all. It then wrote 2.3 million question-answer pairs from the code itself, never seeing the pixels. PixMo-Points has 2.3 million pointing annotations on 223K images, which let the model count by pointing at each object in turn.
One principle sits behind all three. The data generator works from a symbolic description of the image (captions, boxes, OCR text, rendering code, a spoken description), and the student sees only pixels. The data are right exactly where the description is complete and the pixels show what it says. If the description mentions something the student cannot see, perhaps because the image will be shrunk to 336 pixels, the student learns to state things it cannot see. Hallucination is exactly that, a confident statement about something the image does not show.
Two observations fit this reading. LLaVA-1.5 found that higher resolution reduced hallucination. RLHF-V (Yu et al. 2023) found the same effect from the other side. Random-crop augmentation can cut away an object that the caption still names, and removing cropping from their augmentation made the model more trustworthy.
| approach | who sees the image | strength | weakness | example |
|---|---|---|---|---|
| text-only teacher | nobody | cheap, exact spatial facts from boxes | invents unseen details, limited to annotated objects | LLaVA-Instruct 158K |
| multimodal teacher | a proprietary VLM | dense and accurate descriptions | licensing, inherits the teacher's errors and blind spots | ShareGPT4V |
| spoken human descriptions | people | open, detailed, no distillation | cost of annotation, varies by annotator | PixMo-Cap |
| generation from an exact source | nobody, the source is exact | exact answers at scale | only as broad as the renderer or OCR | Docmatix, PixMo-Docs |
Synthetic data also carry the risks §8.4 describes for text. They lose diversity, and when a model trains on its own outputs over several generations, quality can collapse. The defenses are the same. Keep real data in the mixture, filter by quality, and verify a sample of generated answers against the images, with a strong VLM or a person.
One practical detail of instruction tuning saves real compute. Text conversations such as ShareGPT's are often much longer than visual ones. A batch is a rectangle, so every short sequence in it is padded with empty tokens to the length of the longest, and the padding wastes compute. LLaVA-1.5 therefore draws every batch from one modality only. That sped training up by 25 percent without changing the result.
Its released sampler goes one step further, with mega-batches. A mega-batch is one batch for every GPU at once, the number of GPUs times the per-GPU batch size.
Sorting inside a mega-batch reduces padding, because the GPUs' batches are then cut from neighbors of similar length. Shuffling outside keeps the order random. Sorting the whole dataset would minimize padding but destroy randomness. Every batch would contain the same neighbors every epoch, and the gradient would sweep from all-short to all-long sequences.
Implement modality_length_batches(lengths, is_mm, batch_size, megabatch, rng). It takes n samples with token counts lengths, a boolean array is_mm that marks the multimodal samples, and a NumPy rng. Raise ValueError unless megabatch is a multiple of batch_size. Then do the following.
rng.permutation, and cut the result into full mega-batches of exactly megabatch samples. Set the leftover tail (fewer than megabatch) aside.rng.permutation.batch_size (the final group's last batch may be smaller), and return the list of batches, each a list of Python ints.The block below builds a tiny VLM and runs one optimizer step of each of LLaVA's two stages, alignment and instruction tuning. The "encoder" is a frozen random linear layer, the projector is a two-layer MLP, and the language model is a two-layer causal Transformer. Freezing takes two lines, requires_grad_(False) on what must not move and an optimizer built only from what may. Separate learning rates are parameter groups. The prints confirm that stage 1 leaves the language model bit-for-bit unchanged and that the memory bill follows the 16-and-2 rule.
With a real model the same logic is a loop over parameter names. The sketch below uses the Hugging Face LLaVA class and the PEFT library for LoRA, so it is shown rather than run. Freezing by "vision_tower" not in name works whether the language model's head lives under language_model or at the top level, which changed between library versions.
Instruction tuning teaches a model to imitate good answers. It does not teach the model which of its own answers are wrong. The most common wrong answer of a VLM is a hallucination, a confident statement about something the image does not contain. Preference tuning trains on pairs of answers where one is marked better (Chapter 16), so it is the natural fix. Two early systems adapted it to images, and each ran into a weakness of its own.
The first, LLaVA-RLHF (Sun et al. 2023), trained a reward model on human preferences, a network that scores answers. It found the reward model too weak to catch hallucinations until it was also shown the image's human-written captions. The second, RLHF-V (Yu et al. 2023), asked annotators to correct the false parts of an answer instead of ranking whole answers, and got more out of far fewer labels. The box below has their details. Then a later study found a deeper problem with DPO itself, the subject of the rest of this part.
Plain DPO on image pairs has a deeper problem, which a careful experiment exposed. Recall the DPO loss of §17.2. It raises the probability of the chosen response relative to a frozen reference model and lowers that of the rejected one. With the image added to the context it reads
where is the prompt and and are the chosen and rejected responses. The model being trained is , and is the frozen SFT model. The KL coefficient sets how far the model may move from the reference, and is the logistic function.
The study that proposed the fix below (Wang et al. 2024b) trained one model with this loss and another with the image removed from every preference pair. MMHal-Bench is a set of 96 image questions written to provoke hallucination (Sun et al. 2023). On it, the model that never saw the images did as well, or slightly better. The pairs could be told apart from the text alone, so DPO had learned a preference that did not depend on the image. The authors call this unconditional preference.
Why can that happen? The two responses in a pair share and , and the loss depends only on the difference of their log-probabilities. Suppose the chosen response is better for reasons visible in the text, such as being more hedged, more fluent, or free of an implausible object. Then the model can raise that difference without consulting the image at all. Nothing in the objective rewards using the picture.
The three terms do different jobs. The first is the usual comparison of two responses, and the other two close shortcuts that plain DPO leaves open.
Each term has the form , whose derivative is . The reference log-probabilities are constants, so , , , , and , with all other partial derivatives zero. Multiplying and summing gives the three formulas. ∎
In plain words, the chosen response under the true image is pushed up three times, by the response comparison, by the image comparison, and by the anchor. The rejected response is pushed down once. The chosen response under the corrupted image is also pushed down once, which teaches the model that is a good answer only when the picture supports it. Each push is weighted by how wrong the model still is on that comparison, , which goes to zero once the margin is large.
The cell makes the claim concrete. It scores two policies that separate the responses equally well, one image-blind and one that uses the image.
Implement two functions. seq_logp(token_logp, mask) turns per-token log-probabilities of shape (B, T) and a 0 or 1 mask of trained response tokens into sequence log-probabilities of shape (B,), summed over the masked tokens.
mdpo_loss(lw, ll, lwc, rw, rl, rwc, beta=0.1, delta=0.0, copo=True, anchor=True) takes six arrays of shape (B,). The first three are sequence log-probabilities under the policy, , , and (the chosen response with the corrupted image). The last three, rw, rl, and rwc, are the same under the reference. Return (loss, g_w, g_l, g_wc), the batch mean of the per-example sum of the enabled terms and its gradients with respect to lw, ll, and lwc. With copo=False and anchor=False it must reduce to DPO. Compute stably, so that margins of give finite results.
Does mDPO work? The authors trained with the same 10K preference pairs (the LLaVA-Instruct subset of the Silkie dataset), LoRA, and , and mDPO beat DPO on both models they tried. MMHal-Bench's score is a judge model's rating of each answer, and higher is better. Its hallucination rate is the share of answers judged to contain a hallucination. Object HalBench reports the percent of responses that mention an object not in the image. For both rates, lower is better.
| model | MMHal-Bench score | MMHal hallucination rate | Object HalBench, responses with a hallucinated object (percent) |
|---|---|---|---|
| Bunny-v1.0-3B | 2.11 | 0.58 | 43.0 |
| plus DPO | 2.28 | 0.56 | 44.3 |
| plus mDPO | 2.96 | 0.42 | 27.0 |
| LLaVA-1.5-7B | 2.19 | 0.57 | 54.7 |
| plus DPO | 2.14 | 0.65 | 49.0 |
| plus mDPO | 2.39 | 0.54 | 35.7 |
The ablation on Bunny is the informative part. Removing the conditional term dropped the MMHal score from 2.96 to 2.36, removing the anchor dropped it to 2.50, and removing both gave DPO's 2.28. So conditioning on the image does most of the work.
The choice of corruption mattered too. A random unrelated image as scored 2.81, because it is too easy to tell apart from the true one. A crop keeping 20 to 50 percent of the image scored 2.92, against 2.96 for the default. Hard negatives that share most of the image's content teach the most. §31.6 shows how the object hallucination these methods target is measured.
Reasoning language models are trained with RL on problems whose answers a program can check, called verifiable rewards (§18.3, §18.5). The usual algorithm is GRPO. It samples a group of responses to each problem and scores each response against the average of its group, instead of against a learned value function (§18.4).
Many visual tasks have checkable answers too.
GLM-4.1V-Thinking (GLM-V Team 2025) is a detailed public account of doing this at scale. Two lessons stand out.
The verifier is the product. The same answer can be right in one domain and wrong in another. "43" and "43.0" are equal in a math problem and different in OCR. So the authors built a separate verifier for each domain and recommend unit-testing each against that domain's outputs. A weak verifier anywhere could destabilize the whole run, and they report a concrete case. After more than 500 iterations with a carelessly designed verifier, the model answered a counting question with "a correct number between 0 and 10", which some LLM-based reward models accepted. They also made the model wrap its final answer in special box tokens, so the verifier never has to guess which number in a long chain of thought is the answer.
Sampling should follow difficulty. Their curriculum sampling labels each problem's difficulty offline, by pass@k with existing models (the chance that at least one of samples is right), and online, from the current model's rollouts. It then down-samples problems that are already easy or still hopeless. Both kinds give a group of identical rewards, and identical rewards give every response a GRPO advantage of zero, so the model learns nothing from them.
Visual RL has one failure of its own. A policy can earn rewards by answering from language priors without looking, since many benchmark questions can be answered from the text alone. RL then strengthens exactly the habit we want to remove. One defense is in the data. Before training, ask the model each question with the image removed, and drop or down-weight the questions it still answers correctly. §31.6 shows how the MMStar benchmark applies the same test to evaluation.
The exercise builds the verifier for four kinds of answer, and the blind filter on top of it. Its tests include the failures described above. One is GLM-4.1V's hedged count. Another compares numbers as floats where the task is to read text exactly. A third reads a box from the middle of the reasoning instead of from its end.
A reward function for visual RL reads the model's whole output, chain of thought included, and returns 1.0 or 0.0. Boxes use this section's Qwen-VL format, integer corners in . Implement four functions.
parse_box(text) returns the last <box>(X1,Y1),(X2,Y2)</box> in text as a tuple of four ints, allowing spaces around the numbers. Earlier boxes are zooms or drafts inside the reasoning. Return None if there is no box, or if the last one is malformed (anything but two pairs of nonnegative integers), out of range (a coordinate above 999), or not a proper box ( or ). Never fall back to an earlier box.iou(a, b) returns the intersection over union of two (x1, y1, x2, y2) boxes as a float. It is 0.0 when they do not overlap and 0.0 when their union has zero area.reward(output, target, kind) scores one output.
kind="box" the target is a box tuple, and the reward is 1.0 when the parsed box has IoU at least 0.5 with it.<answer>...</answer> span, with surrounding spaces stripped. An output without such a span scores 0.0."number", remove commas and a trailing % from the answer and from the target. Require what is left to be a plain decimal number, an optional sign followed by digits with at most one decimal point, such as -3, 12.5, or .5. Then accept , ChartQA's relaxed accuracy."count", the answer must be a nonnegative integer written in digits and equal to int(target)."string", collapse runs of whitespace to one space, lowercase both sides, and compare exactly.ValueError.blind_filter(questions, blind_outputs, thr) takes questions as dicts with keys "target" and "kind", and for each question a list of outputs sampled with the image removed. Return the indices, in order, of the questions whose blind pass rate (the mean reward of their blind outputs) is below thr. The others can be answered without looking and are dropped.Text reasoning lets a model spend more tokens on a hard problem (§18.7). A VLM that has encoded an image once, at 336 or even 1,000 pixels, cannot spend more on looking, however long it thinks. The detail it missed was never encoded. OpenAI's announcement of o3 and o4-mini in April 2025 introduced the phrase "thinking with images". It describes models whose chain of thought includes operations on the image itself, such as cropping, zooming, and rotating. Each result is fed back into the context.
DeepEyes (Zheng et al. 2025b) shows how to train this behavior with RL alone, starting from Qwen2.5-VL-7B with no supervised reasoning traces. During a rollout, one sampled attempt at a problem (a trajectory, as in §15.1), the model may write a bounding box. The environment crops that region from the full-resolution image and appends it to the context as new image tokens, up to 6 times per rollout. The appended tokens are observations, not actions, so the loss masks them out, exactly as tool outputs are masked in agent training. For a rollout , the reward is
In plain words, the model earns a reward for a correct final answer, a reward for the right output format, and a bonus for using the zoom tool at least once that is paid only when the answer is right. They trained with GRPO for 80 iterations of 256 prompts with 16 rollouts each, without a KL penalty. On V*, a benchmark of small objects in very large images, accuracy rose from 71.2 to 90.1.
The interview follow-up is cost, since every zoom adds hundreds of image tokens to the context. The deeper remedy for fine detail is to encode it in the first place, the subject of §31.5.
The table puts the published recipes side by side. Each row says what each stage trains, on how much data, and the one choice worth remembering.
Read down the second column and a trend appears. Early recipes froze as much as possible, because data were scarce and compute was short. Later ones train nearly everything, gently, on far more data. The frontier trains vision and language together from the start of pretraining, the native multimodal design of §31.6.
The freezing choices, side by side, are what an interviewer expects you to weigh.
| freezing choice | memory | stability | what it preserves | what it costs |
|---|---|---|---|---|
| connector only | lowest, the LLM at 2 bytes per parameter | safest | the LLM exactly | no in-context learning gain, weaker instruction following (VILA) |
| connector and LLM, encoder frozen | 16 bytes per LLM parameter, sharding needed | good with a low learning rate | encoder features | text skills need text data in the mix |
| everything | highest | needs warmups and care, can diverge (Idefics2) | nothing by construction | best results when it trains stably (PaliGemma, MM1) |
| LoRA on the backbones | near connector-only memory | stable where full training diverged (Idefics2) | base weights, switchable adapters | less capacity than full training |
| frozen LLM plus new cross-attention | new layers only | stable by the zero-initialized gate (§31.2) | text behavior exactly | many new parameters, needs interleaved data |