DreamLLM

DreamLLM writes a document and draws its own pictures, deciding where each one goes. It trains by asking a frozen Stable Diffusion to grade its notes, and reaches FID 8.46 on MS-COCO.

See how one language model can both read pictures and make them, and why that may help it understand better.

Pick a partner, then press Write the document. Watch which one draws, and who chooses where the pictures go. Then we build, piece by piece, the reader, the painter, the learned queries that link them, and the evidence.

You need a feel for what a language model does (it predicts the next word) and the idea of a photo as a grid of numbers. We build the rest from zero.

A reading of the paper “DreamLLM: Synergistic Multimodal Comprehension and Creation” by Runpei Dong, Chunrui Han, Yuang Peng, Zekun Qi, Zheng Ge, Jinrong Yang, Liang Zhao, Jianjian Sun, Hongyu Zhou, Haoran Wei, Xiangwen Kong, Xiangyu Zhang, Kaisheng Ma and Li Yi (ICLR 2024). arXiv 2309.11499. Assigned in MIT MMAI (Spring 2026) beside the lecture Cross-modal transfer. The course schedule.

Write a page with pictures

The scores are the paper’s: FID on MS-COCO from Table 2 (SDv2.1 12.43, Emu-13B 11.66, DreamLLM-7B 8.46; lower is better) and VQAv2 accuracy from Table 1 (Flamingo-9B 51.8, Emu-14B 40.0, DreamLLM-7B 56.6). The page, its two slots and the animation are illustrative, and the roles follow the paper’s Fig. 1 and Sec. 3.1.

Chapter 0

Why Reading and Drawing Were Two Separate Skills

See why a model that looks at pictures and a model that paints them were built apart, and what DreamLLM tries to change

A friend asks you for a short travel guide to Vienna. She wants paragraphs, and she wants a photograph after each one. You write the first paragraph. Then you stop and think: a picture of the opera house belongs here. You sketch it, and you carry on writing.

You did two things without noticing. You decided where a picture should go, and you made it. Your reading of the first paragraph also shaped the picture. A language model of 2023 could do almost none of this in one piece.

Two skills, two kinds of model

Researchers call a language model that also takes images a multimodal large language model, or MLLM. A modality is a kind of data, such as words or pictures. The best MLLMs of that time could comprehend: you show a photo and ask a question, and they answer in words. This is like a friend who can look at a picture and describe it.

Making pictures is called creation. The tool for it was a diffusion model such as Stable Diffusion, which paints an image from a text prompt. Think of a painter who takes a written commission. The painter cannot chat, and cannot read a whole essay and decide where the pictures go.

The paper wants one model that does both, as one stream. It also asks a bigger question: if a model learns to create, does it understand better? The authors open with Feynman’s line from his blackboard, “What I cannot create, I do not understand.” Their word for the hoped-for benefit is synergy: two skills that help each other more than they would apart.

The words the paper uses

The paper talks about posteriors. A posterior is just the answer to “what do I expect, given what I have seen?” The model for p(words | image) is a language posterior: given a picture, which words follow? The model for p(image | words) is an image posterior: given words, which pictures are likely?

A conditional distribution is one of these, with something given. A marginal distribution is a single thing on its own, such as p(words). A joint distribution covers both together, such as a whole page of words and pictures. A model that learns the joint can produce all the others. That is the paper’s aim.

Four ways to wire a model

The paper’s Fig. 1 compares four designs. Try them in the device below. Pick one and look at which of five abilities it has.

Compare four designs

Left to right: what goes in, the model, what comes out. Choose a design, and the five abilities underneath light up or stay dim.

This is my reading of the paper’s Fig. 1 and its caption, not a table the paper prints. The paper’s own claim about (c) is that its image target lives in CLIP space and that it needs a second-stage Stable Diffusion fine-tune and human choice of image positions.

Design (a) is CLIP, a model with two towers: one encodes text, one encodes images, and training pulls matching pairs together. It reads and aligns, but it does not write. Design (b), the Flamingo and BLIP family, feeds image features into a language model. It answers in words only, so it is not fully autoregressive over images (it never produces the next image piece).

Design (c) is the most recent before DreamLLM. GILL and Emu let the language model output an embedding that matches what CLIP would say about the target picture. A pretrained Stable Diffusion then paints from that embedding. The aim is CLIP space, an intermediate space, not pixels. The next chapters explain why the authors think that hurts.

Design (d) is DreamLLM. It takes raw words and raw images in, and puts raw words and raw images out, in one causal stream. Two principles carry it, in the authors’ words: generate everything as it is, and interleaved generative pre-training.

The two principles in plain words

Principle one says the model should not learn to imitate a CLIP summary of a picture. It should learn a hidden note that makes a frozen painter produce the real picture. We build this note in Chapters 3 to 5. It is called a set of dream queries.

Principle two says the model should train on whole web pages, where words and pictures alternate. A special <dream> token marks “a picture goes here.” We build that in Chapter 6. The headline numbers, which we check in Chapter 7: FID 8.46 on MS-COCO, and 49.9 on MMBench and 35.9 on MM-Vet for the 7B model. The whole thing trained on 128 A800 chips for about 17.5 hours in three stages.

One caution before we start. The paper says 49.1 for MMBench in its introduction and 49.9 in Tables 1 and 5. We use the table value and flag the difference.

The road

  1. How a language model reads a picture: a picture becomes 256 tokens.
  2. How a diffusion model paints: noise in, noise guessed, picture out.
  3. The CLIP alignment trap: why aiming at an intermediate space loses detail.
  4. Dream queries: 64 learned slots that carry the thought to the painter.
  5. Score distillation: the frozen painter grades the notes.
  6. Interleaved documents: the dream token, three training stages, the generation loop.
  7. What the tables show: the numbers, the synergy test, the limits.
  8. Field guide: numbers, checklist, code, and where to go next.
A design (c) model like Emu aims at CLIP embeddings; DreamLLM does not. What does DreamLLM aim at instead?

Chapter 1

How a Language Model Reads a Picture

Turn a photo into 256 tokens that a language model can read like words, and count what they cost

You hold up a photo of a cat and ask, “What colour are its eyes?” A person looks and answers. A language model has a problem. It only knows how to take a list of word vectors and predict the next word. It has no eyes.

The fix is simple to say. Turn the photo into a list of vectors of the same kind. Then the model reads the photo the way it reads a sentence: as more items in the list. This chapter builds that conversion. It is the part of DreamLLM that handles comprehension, and it is the standard recipe of that time.

A quick refresher: tokens and the next-word game

A token is the unit a language model counts: a word, or a piece of one. Inside the model each token becomes an embedding, a list of numbers (for Vicuna-7B, 4,096 of them) that stands for it. A language model plays one game: given all the tokens so far, give each possible next token a probability. This is autoregressive modelling.

The paper writes it as a product of small questions, one per token:

pθ(w)
The probability the model gives to the whole sequence w of T tokens. The Greek letter theta stands for all the model’s learned weights.
∏t=1T
Multiply the factors for position 1 up to position T.
pθ(wt | w<t)
The probability of token t given every token before it. The model answers this once per position.

From photo to tokens

Now the image. Three parts do the work, and the paper names each one. The visual encoder Hφ is CLIP ViT-L/14 from OpenAI. It is frozen, which means its weights never change during DreamLLM’s training. The projector Mζ is one linear layer. The language model is Vicuna-7B.

The image is resized to 224 × 224 pixels. CLIP cuts it into square patches 14 pixels wide, so 16 × 16 = 256 patches. Each patch becomes one feature vector. The paper confirms the count: a sequence of 256 tokens for each image.

  1. Image: 3 × 224 × 224 pixels.
  2. CLIP ViT-L/14 (frozen): 256 patch features, 256 × 1024. The width 1,024 is the standard width of this CLIP model; the paper does not print it.
  3. Linear projector Mζ (trained): 256 × 4096, the width of Vicuna-7B, so each patch looks like a word embedding.
  4. Markers: a special <IMG> token goes before the 256 vectors and <IMG/> after. One image costs 258 positions.

Why a linear layer and not something bigger? The CLIP features already carry the meaning. The projector only has to rotate and rescale them into the language model’s space. A small trainable piece also keeps Stage I cheap, because the big models around it stay frozen.

The comprehension loss

Now put words and pictures in one sequence. Say the document has K ordered images I1 to IK mixed with words. Let Vk be the projected tokens of image k. Let K(t) be the number of images that come before word t. The training goal is to minimise:

LMLLM
The loss: a number that is large when the model assigns low probability to the true words.
Et
Average over the word positions t in the data.
pΘ(wt | …)
The probability of the true word, given earlier words and the tokens of every image that came before. Capital Theta is theta plus the projector’s weights.
Vk = Mζ ˆ Hφ(Ik)
Image k goes through the CLIP encoder first, then the projector. The small circle means “apply right to left.”

A worked example. The training text is: photo, then “a cat on a sofa”. The sequence is <s>, <IMG>, 256 picture vectors, <IMG/>, a, cat, on, a, sofa. The loss covers only the five word positions. Suppose the model gives “cat” the probability 0.20. The loss for that position is −ln 0.20 = 1.609. If training pushes the probability up to 0.60, the loss falls to 0.511. (These probabilities are illustrative.) The picture tokens themselves are never predicted in this equation. Chapter 6 changes that.

The cost nobody mentions

Every image takes 258 positions. The paper trains with a maximum token length of 2,048 (Table 13). Do the sums: seven images take 7 × 258 = 1,806 positions and leave 242 for words. An eighth image makes it 2,064, which is over the cap. Try it below.

Fill the context

The bar is the 2,048 positions the model sees at once. Blue blocks are images, warm is words. Slide the number of images and words. Watch the cap.

3
400

258 = 256 CLIP patches plus the two markers, and 2,048 is the maximum token length in the paper’s Table 13. The paper does not say how it truncates a document that goes over, so that rule is yours to choose.

Failure mode, as symptom, measurement and fix. Symptom: in long web pages the last pictures never influence the answer. Measurement: add up 258 per image plus the words, and compare with 2,048. Fix: the paper filters its documents (MMC4 pages with a CLIP score above 0.25, about 2 million kept) and caps the length. When you rebuild this, pick a rule for pages that do not fit and write it down.

How many positions does one image occupy in DreamLLM’s input sequence, and why?

Chapter 2

How a Diffusion Model Paints

Learn to guess the noise that was added to a picture, and see why that guess is also a way to paint

Drop ink into a glass of water. The ink spreads until the water is evenly grey. Nobody can watch the grey water and say where the ink first fell. Now imagine a film of this played backwards: the grey gathers into a drop. A diffusion model learns to run that film backwards for pictures.

The forward film: add noise on purpose

Start with a clean picture z. Add a little random noise (numbers drawn from a bell curve, with no pattern). Add more. After enough steps, only noise is left. This forward process is fixed. Nothing is learned in it.

The paper writes one jump from the clean picture straight to noise level t. Here αt is a number that falls from 1 toward 0 as t grows:

zt
The noisy picture at noise level t.
√αt
How much of the clean picture survives. At αt = 1 all of it; at 0 none.
z
The clean picture. Stable Diffusion works on a compressed version of the image (a latent), not on raw pixels.
√(1 − αt)
How much noise is mixed in. It grows as the picture fades.
ε
The noise itself, one random number per entry, drawn from a standard bell curve (mean 0, spread 1).

A worked example with one number. Let z = 0.8, αt = 0.64 and ε = −0.5. Then √0.64 = 0.8 and √0.36 = 0.6. So zt = 0.8 × 0.8 + 0.6 × (−0.5) = 0.64 − 0.30 = 0.34. The noisy value is 0.34. (Illustrative numbers.)

The learned part: guess the noise

Here is the trick. Give a network the noisy value zt and the noise level t. Ask it to guess ε, the noise that was added. The network is a U-Net, a convolutional network shaped like the letter U that outputs something the same size as its input. Call it εξ, with weights ξ. It also gets a condition C, such as the embedding of a text prompt, so it can paint toward what you ask for.

LDM(ξ, z)
The diffusion loss: the average squared miss of the noise guess.
Et, ε
Average over random noise levels t (uniform between 0 and 1) and random noise draws.
εξ(zt; C, t)
The network’s guess of the noise, given the noisy picture, the condition and the level.
ε
The true noise we added. We know it, because we added it. That makes this a supervised problem.

Continue the worked example. The network guesses ε̂ = −0.2. The miss is (−0.2 − (−0.5))2 = 0.09. A good network guesses −0.5 and the loss is 0. We can also recover the clean value from the guess: (zt − 0.6 × ε̂) / 0.8. With ε̂ = −0.2 that is (0.34 + 0.12) / 0.8 = 0.575. With the perfect guess, (0.34 + 0.30) / 0.8 = 0.80, the true z.

Add noise, guess it back

The grey curve is the clean signal. The blue curve is the noisy version. The yellow curve is what you get back from a noise guess. Slide the noise up, then slide the denoiser’s skill up.

0.40
0.50

Illustrative: a 48-point wave with seeded noise. Skill 1 means the guess equals the true noise; skill 0 means a guess of pure fresh noise. The formulas are the paper’s Eq. (2) and the forward step above.

Why guessing noise is painting

Look at what the network learned: from any messy picture, which way is the noise? The opposite way points toward a cleaner picture. The paper notes that εξ = −σt sξ, where sξ is the score, the arrow that points uphill in the log of the picture density (toward more likely pictures). So a good noise guess is a good sense of direction. To paint, start from pure noise, guess, take a small step toward the cleaner picture, and repeat. The paper times 50, 100 and 150 steps in Table 9b; each step costs about 0.07 seconds on an A800 chip.

The condition C steers each step. In Stable Diffusion, C is a sequence of vectors that the U-Net reads through cross-attention, a layer where picture features look up information in C. In SDv2.1 that sequence has 77 vectors of width 1,024 (standard for that model; the paper does not print it). Remember this: the painter only sees C. Whatever you put in C is everything it knows about your wishes.

Failure mode. Symptom: the painted picture is mush at high noise. Measurement: at α near 0.02 the signal share is √0.02 = 0.14, so even a good guess leaves a large error in the recovered curve. Fix: take many small steps, not one big one. That is why a diffusion model spends 50 or more steps.

In the diffusion loss, what is the network trained to predict?

Chapter 3

The CLIP Alignment Trap

See why asking a language model to imitate CLIP loses detail, and what the paper measured when it tried

You describe a friend’s face to a sketch artist, but you may only use words that a stranger would also use for everyone. “Round face, brown eyes, smiling.” The artist draws a face. It is a fair face. It is not your friend. The details that make your friend different never passed through the words.

This is the problem the paper sees in earlier designs. To explain it, we first need to know what CLIP learns.

What CLIP keeps, and what it drops

CLIP trains two encoders, one for text and one for images. A contrastive loss pulls the embedding of a picture toward the embedding of its caption, and pushes it away from other captions. The result is a space where a photo of a dog sits near the words “a dog.”

Look at what such training rewards. It rewards information that a caption can say. It does not reward the exact fur pattern, the exact position of the dog, or the light. The paper cites the modality gap (Liang et al., 2022): text and image embeddings occupy separate regions of the space, and the space keeps mainly what is shared between the two modalities. Modality-specific knowledge is mostly lost.

The earlier recipe

GILL, Emu and SEED-style systems wanted a language model that can also paint with Stable Diffusion. Stable Diffusion already reads a condition built from CLIP text features. So their plan was to make the language model output vectors that look like CLIP’s. Call the language model’s output CMLLM and CLIP’s target CCLIP. The training loss is:

Lalign
The alignment loss. Small when the model’s output matches CLIP’s embedding.
D
A distance, for example the mean squared difference.
Mψ
A condition projector, a small layer that maps the model’s output to the CLIP width.
CMLLM
What the language model outputs for the picture it wants to draw.
CCLIP
What the frozen CLIP encoder gives for the real picture or its caption. This is the target.

The paper raises three objections to this recipe.

  1. The target is thin. CCLIP keeps shared meaning and drops modality-specific detail. The painter can never get back what the target never carried.
  2. The model is forced out of its own space. The language model must emit “semantically reduced” vectors that differ from what it naturally encodes. The paper says this “may induce more conflicts than synergies.” Its comprehension then stays weak.
  3. The setup needs extra stages. Fig. 1 notes that models such as Emu need a second-stage fine-tuning of Stable Diffusion to make raw images.

Squeeze through the shared space

Eight things about a picture. Each has a share a caption can say. Slide the pressure toward CLIP and watch which details survive.

0.80

A toy, not a measurement. The eight shares are made-up numbers for how well a caption can express each attribute. The rule is: detail kept = (1 − pressure) + pressure × share. The paper’s only direct test is the collapse in Table 3 (below).

The paper’s test: add the alignment loss back

The authors did something direct. They took the DreamLLM design and added Lalign on top (Table 3, line 6). Result: the model “fails to converge but rather ends in a collapsing point.” Table 3 prints N/A for every score on that line. They read this as proof that the learned queries are fitting the true data distribution, and that CLIP’s semantics conflict with what the language model encodes.

Be careful with what this shows. It shows that with this training setup, adding the alignment loss on top breaks training. It does not prove that every CLIP-aligned system must fail; Emu and GILL do produce pictures. The claim is narrower: for this design, the alignment target conflicts with the free queries.

The way out

If the target must not be a CLIP summary, what can it be? The paper’s answer: the real image. The language model should output whatever a frozen painter needs to paint the real image. We do not need to know in advance what that looks like. The model finds out by trial, using the painter’s own loss as the teacher. That loss is Eq. (2) from Chapter 2. The next two chapters build the message (the dream queries) and the teaching signal (score distillation).

Failure mode, as symptom, measurement and fix. Symptom: pictures from a CLIP-aligned model get the subject right and lose the layout and the style. Measurement: compare FID on LN-COCO, where captions are long and detailed. Stable Diffusion alone gets 34.26; DreamLLM gets 20.53 (Table 2). Fix: stop aiming at an intermediate space; let the painter’s own loss shape the condition.

What happened when the authors added the CLIP alignment loss Lalign on top of DreamLLM (Table 3, line 6)?

Chapter 4

Dream Queries: 64 Slots That Carry the Thought

Build the learned message that lets a language model brief a painter, and see why 64 slots work best

You have finished an essay about a Siamese cat. Now you want a painter to illustrate it. You cannot hand the painter your whole mind. So you stick 64 blank notes at the end of the essay and say: “Fill these in with what the painter needs.” Later, the painter reads only the notes.

That is the whole idea of this chapter. The blank notes are dream queries. They are the paper’s key trick for letting a language model talk to a diffusion model without a CLIP target in between.

What a query is

A dream query is a learned embedding: a vector of 4,096 numbers, the same width as a word in Vicuna-7B. It starts as a blank and training gives it values. There are Q of them; the default is Q = 64. The paper writes the set as d = {d1, …, dQ}. They are the same for every picture. They are like the blank form: the form is fixed, and what the model reads into it changes with the context.

Why does that work? Because the language model is causal: each position can look at everything before it, and nothing after it. If the 64 query positions are placed at the end of the context, each one can read the entire document so far, including earlier pictures. After the model runs, the 64 output vectors at those positions hold its answer. They are the filled-in notes.

The equation, and the shapes

Suppose token t is predicted as the special <dream> token. The model then needs the condition for image number K(t)+1. The paper writes:

CDreamLLMK(t)+1
The condition for the next image: the 64 filled-in notes. It replaces the text embedding that Stable Diffusion normally takes.
Fθ
The causal language model (Vicuna-7B) with weights θ.
d
The 64 learnable dream queries, appended at the end of the context.
x<t+1
Everything written so far, including the <dream> token at position t.
V<K(t)+1
The tokens of every earlier image (Chapter 1), so the new picture can match them.
  1. Context so far: words and image tokens, then <dream>. Call its length T.
  2. Append the queries: (T + 64) × 4096 going into the language model.
  3. Causal pass: read the last 64 output vectors, 64 × 4096.
  4. Condition projector Mψ (one linear layer): 64 × 1024, the width Stable Diffusion v2.1 expects for its cross-attention. The paper does not print 1,024; it is the standard width of that model.
  5. Frozen U-Net: reads these 64 vectors in place of the usual 77 text vectors.

Why 64 vectors and not one? One vector is a tiny channel for a whole scene: subject, layout, style. Many vectors give the painter many separate things to look up, the same way a long prompt gives it many words. Why queries and not just the last hidden state of the sentence? The hidden state belongs to a word. The queries belong to the job. They always sit in the same place and always have the same duty, so the painter’s cross-attention can learn where to look.

Choose how many queries

Each small square is one query. Purple lines show every query reading the whole history to its left. Pick 32, 64 or 128 and read the paper’s score.

FID values are the paper’s Table 9a: 32 queries 9.56, 64 queries 8.46, 128 queries 14.24 (zero-shot, MS-COCO 30K, lower is better). The grid and the lines are a drawing of the mechanism, not real attention weights.

What the queries learn

The paper looks inside in Fig. 6. It draws the cross-attention between each of the 64 queries and the U-Net’s picture features, averaged over all noise levels. The queries sit in an 8 × 8 grid. Two things stand out. First, the attention is structured and disentangled: different queries pick out different subjects and the background. Second, the patterns look very alike across different prompts. In plain Stable Diffusion, the attention follows which words are in the prompt. In DreamLLM, each query seems to keep a fixed job. The authors guess this comes from the causal order giving a steady semantic structure.

That is a guess, and the paper says “we postulate.” Treat it as a clue, not a proof.

How many queries, and why not more

Table 9a says 64 is best, and 128 is worse, at 14.24 FID. The authors say 128 “may be too many,” and that the best number depends on data size and on the decoder. A reimplementer should treat Q as a setting to tune. It is not a law. Failure mode, as symptom, measurement and fix. Symptom: FID jumps from 8.46 to 14.24 after raising Q. Measurement: Table 9a. Fix: go back to 64 unless you have more data and a stronger image decoder.

Why can the same 64 dream queries produce different pictures for different documents?

Chapter 5

Score Distillation: A Frozen Painter Grades the Notes

Follow the training signal from the painter’s noise error back into the language model, with no CLIP target

Back to the essay and the painter. You wrote 64 notes. The painter, who never changes, tries to repaint a known real picture from your notes. If the notes are poor, the repaint is poor. You see the error, change your notes, and try again. After thousands of tries, your notes get good. The painter did not learn anything. You did.

This is how DreamLLM trains its image side. This chapter shows exactly where the signal goes.

The loss

Take the diffusion loss from Chapter 2. Replace the generic condition C with the condition made by the language model, the 64 notes from Chapter 4. The paper’s Eq. (4) is:

LDMDreamLLM(θ, d, ζ, ψ, z)
The loss. Its inputs list what can change: the language model θ, the queries d, the visual projector ζ, the condition projector ψ. The picture z is data.
Et, ε
Average over random noise levels and noise draws, as before.
εξ(zt; CDreamLLM, t)
The frozen U-Net’s noise guess, now conditioned on the 64 notes. The paper states: “ξ is not updated since the SD is frozen.”

Compare with Eq. (2). The formula is almost the same. Only two things changed: C comes from the language model, and the gradient does not update ξ.

Frozen does not mean silent

This is the point beginners miss. Frozen means the weights ξ are not changed by the optimiser. It does not mean the gradient cannot pass through them. By the chain rule, the loss can still ask: if I nudged the condition C a little, how would the error change? That answer flows backward through the U-Net layers, then through the condition projector Mψ, then through the 64 query outputs, then into the language model and the queries.

  1. Loss: squared error between true noise and the guess.
  2. Back through the frozen U-Net: weights stay put; the gradient with respect to C comes out.
  3. Back through Mψ: the projector is trained.
  4. Back through the language model at the 64 query positions: the model weights θ and the queries d are trained (the language model only in Stage II and III; Chapter 6).

A worked example with single numbers. Let the frozen painter be a one-weight function: guess = w · c, with w = −1.5 (frozen). The true noise is ε = −0.5. We want to find the note c. The best note is c* = ε / w = 0.333. Start with a poor note, c = −0.6.

The guess is −1.5 × (−0.6) = 0.9. The loss is (0.9 − (−0.5))2 = 1.96. The gradient with respect to c is 2 × (guess − ε) × w = 2 × 1.4 × (−1.5) = −4.2. With learning rate 0.2, the new note is c = −0.6 − 0.2 × (−4.2) = 0.24. The new guess is −0.36, and the loss is 0.0196. One step took the loss from 1.96 to 0.02, and w never moved. (Illustrative numbers.)

Train the note, not the painter

The painter weight w is locked at −1.5. Only the note c changes. Choose a learning rate and press Step or Run. Then try the big one.

A one-number toy of the gradient path, not the real U-Net. The update is c ← c − lr × 2(w·c − ε)·w. It converges when lr × 2w² is below 2, which fails for the big rate here.

Why the paper calls it score distillation

Chapter 2 said the noise guess is a score, a direction toward likelier pictures. The frozen Stable Diffusion has already learned that score from billions of pictures. DreamLLM distils from it: it borrows the painter’s knowledge and uses it as the teacher for the notes. The paper links this to score distillation sampling (the trick used to turn 2D painters into 3D shape makers) and to textual inversion (learning one word embedding that makes a painter draw a given subject). DreamLLM’s version learns a whole condition, from a model, for every document.

The paper also writes the same objective as a KL divergence (Eq. 5): it pushes the distribution the painter would give under the condition toward the true one. If you take Stable Diffusion as the best possible score function, then minimising Eq. (4) is maximum likelihood for the image posterior. This is a modelling assumption of the paper, not something it proves.

Failure mode, as symptom, measurement and fix. Symptom: the loss climbs after a few steps. Measurement: print the loss every step and the note value; if the note flips sign each step, the step is too big. Fix: lower the learning rate. In the paper the learning rates are 2e-3 in Stage I (only projectors and queries train) and 2e-5 in Stage II, when the whole language model is open (Table 13).

Stable Diffusion is frozen in DreamLLM. How can its loss still teach the language model?

Chapter 6

Interleaved Documents and the Dream Token

Learn how one model decides where a picture goes, paints it, reads it back, and how the three training stages build that skill

Open any news article. A paragraph, a photo, a paragraph, another photo. Web pages are interleaved documents: words and images in a mixed order. A pair like “photo plus caption” is just a short special case, and so is a page of text alone. If a model learns pages, it learns all of these.

The paper calls this interleaved generative pre-training, or I-GPT. “Pre-training” here means the long first phase of learning from raw documents, before any instruction tuning. The target is a model that can make the page, not just read one.

The <dream> token: a picture goes here

To write a page, the model must decide when to put a picture. The paper adds one new token, <dream>, and places it before each image in the training data. The model is trained to predict it like any other word. When it does so at inference time, it takes this as “draw now,” “on its free will,” in the paper’s phrase. A closing <dream/> follows the queries, like the <IMG/> marker for input images.

This is the answer to the question in the hero. A CLIP-aligned model needs a person to say where images go. DreamLLM learned where pictures appear in real pages, because that is exactly what it was trained to predict.

One loss for words and pictures

For a text token the loss is the usual next-word cross-entropy. For a <dream> token the same loss teaches the placement. For the image that follows, the loss is the diffusion loss from Chapter 5. The paper folds them into one maximum-likelihood statement:

LMLLMDreamLLM(Θ, x)
The unified loss over a whole interleaved document x. Theta now holds the language model, queries and both projectors.
Et
Average over positions in the document.
pΘ(xt | x<t)
The probability of item t given all earlier items. An item can be a word or an image. For an image, the paper uses Eq. (4) as the stand-in for this probability, assuming the frozen Stable Diffusion is an optimal score function.

The paper does not state a weight between the word loss and the image loss. A reimplementer has to choose one; weighting both by 1 is the simplest start. This is an unspecified detail, and it matters.

The causal order gives every conditional for free. Words given an image, p(w | I), is comprehension. An image given words, p(I | w), is text-to-image. A page is the joint. One stream, all of them.

The generation loop

At inference the model writes like a normal language model, with one extra move. Step through it below. The example is the paper’s Fig. 2: “I like my cute Siamese cat.” then a picture, then “She has beautiful blue eyes…”

Step the loop

Press Next to walk through one image being created. The bottom strip is the context. The boxes above are the pipeline pieces.

The sentence and its token counts are illustrative (a real tokenizer splits differently). The pipeline order, 64 queries, 50 denoising steps, the classifier-free scale 7.5 and the 258-position feedback are the paper’s (Sec. 3, Fig. 2, Appendix C.2, Table 9b).

  1. Write words until the model predicts <dream>.
  2. Append the 64 queries; run the language model; take the 64 outputs. Project to 64 × 1024.
  3. Paint: the frozen Stable Diffusion v2.1 denoises from noise to a 512 × 512 picture, with the 64 vectors as its condition.
  4. Read it back: the new picture goes through CLIP and the projector (Chapter 1) and is appended as 258 positions.
  5. Keep writing words with the picture now in context, until the end token.

One extra detail: classifier-free guidance (CFG). At each denoising step the painter makes two guesses, one with the condition and one with an empty condition. The final guess pushes away from the empty one: ε̂ = (1 + s) ε(C) − s ε(∅). The scale s makes pictures more faithful and less varied. DreamLLM uses it only at inference: the scale is 7.5 by default and 2.0 for MS-COCO scoring.

The three training stages

StageWhat trainsDataLearning rateCost
I Alignmentvisual projector, condition projector, dream queries (LLM, CLIP, SD frozen)about 30M image-text pairs2e-3about 6 h, 128 A800
II I-GPT pretrainingthe same, plus the whole language modelabout 2M MMC4 documents (CLIP score above 0.25) plus 2M BLIP-LAION pairs2e-5about 10 h, 128 A800
III Instruction tuninglanguage model unfrozen80K LLaVA instructions, 20K InstructMMC4, 20K Instruct-BLIP-LAION4e-5, 3 epochsabout 1.5 h, 128 A800

Why this order? Stage I lets the new small parts (projectors, queries) settle against frozen big ones, with a high learning rate that would wreck a large model. Stage II opens the language model once those parts are sane. Stage III turns the model into an assistant. The last two data sets were made by prompting GPT-4 with document summaries or image captions.

Failure mode, as symptom, measurement and fix. Symptom: pictures in a generated page look unrelated to each other. Measurement: the paper notes that MMC4 has no image consistency, so pages come out with inconsistent subjects (Fig. 3). Fix: the paper fine-tunes on about 270K subject-consistent samples for 20 epochs, following BLIP-Diffusion (Appendix A.4, Fig. 8).

At inference, what makes DreamLLM start drawing a picture in the middle of a document?

Chapter 7

What the Tables Show, and What They Do Not

Read the drawing scores, the understanding scores and the synergy test, then list what the paper admits it cannot do

A friend tells you her new method “draws better and understands better.” You ask: better than what, measured how, and could something else explain it? This chapter asks those three questions of each table in the paper.

How to read an FID

FID, the Fréchet Inception Distance, scores a whole set of generated pictures. A fixed image network turns real pictures and generated pictures into feature vectors. FID is the distance between the two clouds of features. Lower is better, and zero would mean the clouds are identical. It does not judge one picture; it judges the batch. “Zero-shot” means the model was not trained on the test set’s own training split.

The paper tests on MS-COCO (short captions, 30K validation prompts) and LN-COCO (long, detailed captions). Table 2 reports: Stable Diffusion v2.1 alone, 12.43 and 34.26. DreamLLM after Stage I alone, 8.76 and 22.42. DreamLLM at the end, 8.46 and 20.53. So the language model cut MS-COCO FID by 3.97 and LN-COCO FID by 13.73 from the same frozen painter. The authors read the large LN-COCO gain as better use of long context. For comparison: Emu-13B 11.66, GILL-8B 12.20, CM3Leon-7B 10.82. But specialist painters beat DreamLLM: Imagen 7.27 and Parti-20B 7.23. The paper says “competitive,” and that is a fair word.

Note how DreamLLM generated those images. For MS-COCO it sampled 8 pictures per prompt and picked by CLIP score, like earlier work. For LN-COCO it sampled one, because the captions are too long for CLIP’s limit. Eval settings differ across the compared models, so small gaps need care.

Understanding scores

Table 1 covers captioning and question answering. On VQAv2 (answer questions about a photo; the score is accuracy), DreamLLM-7B gets 56.6. Emu scores 40.0, so the gain is +16.6, as the paper says. Flamingo-9B is 51.8. On the comprehensive tests MMBench and MM-Vet it reports 49.9 and 35.9. Those scores are judged by GPT models. A version trained on LLaVA-1.5’s instruction data (marked with a star) reaches 72.9 on VQAv2 and 58.2 on MMBench, but the paper marks it as non-zero-shot. Do not compare the starred row with zero-shot rows.

The hallucination test POPE asks “is there a [object] in the image?” with absent objects chosen in three tricky ways. DreamLLM-7B scores 86.36 accuracy on the random split, with 52.75% “yes” answers. The ideal is 50%, so it does not say yes to everything. Several rivals in Table 7 answer yes 95 to 100% of the time.

Read the paper’s tables

Pick a table. DreamLLM is in green. Read the direction note on each chart, because lower is better for FID.

All values are printed in the paper. Table 3 and Table 1 columns were read from a text extraction; check the original before you quote them. The synergy rows list the ablations with the same architecture and data, as the paper describes.

The synergy test

This is the paper’s main claim, and Table 3 is its evidence. The authors train three versions with the same architecture and data, differing only in the objective: creation-only (image loss only), comprehension-only (word loss only) and joint (both, the default). They also vary whether interleaved data (ID) is used in Stage II. Read it carefully.

SetupInterleaved dataMM-VetVQAv2COCO FID
Stable Diffusion alonenononenone12.43
Creation-onlyno / yesnonenone8.50 / 8.57
Comprehension-onlyno / yes31.0 / 34.455.1 / 54.3none
Joint (DreamLLM)yes35.956.68.46
Joint plus CLIP alignmentyescollapsedcollapsedcollapsed

What does it support? Drawing: the language model helps a lot (8.50 against 12.43), but joint training adds almost nothing over creation-only (8.46 against 8.50). Understanding: joint beats comprehension-only with interleaved data by 1.5 on MM-Vet (35.9 against 34.4) and 2.3 on VQAv2 (56.6 against 54.3). Interleaved data helps MM-Vet (31.0 to 34.4) but VQAv2 slips (55.1 to 54.3). So the evidence for synergy is real but modest: a gain of about 1 to 2 points in understanding, on single runs, with no error bars. The paper shows no seeds or confidence intervals.

A second control is the rewrite-then-generate baseline (Table 10): the model writes a prompt and a stock Stable Diffusion draws it, with no learned queries. It gets FID 11.91, VQAv2 54.2 and MM-Vet 34.1, against DreamLLM’s 8.46, 56.6 and 35.9. The paper also reports that language-only scores mostly hold: DreamLLM is above Vicuna-7B on 5 of 6 tests, but MMLU drops from 45.0 to 41.8, a loss of 3.2 points (Table 4).

Documents, and cost

For free-form pages, the paper generates from instructions on 15K held-out InstructMMC4 documents. FID against the ground-truth images is 36.62 for DreamLLM, against 74.77 for Stable Diffusion given the matched text. In a human study (150 samples, five volunteers) 60.68% of DreamLLM pages were judged supported, against 77.24% for real MMC4 pages, which contain duplicate and poor images. The paper compares this with a 30% bar it calls the Turing test requirement. At inference the extra cost is small: about 0.2 s over Stable Diffusion alone for 50 steps, because the U-Net dominates.

Limits, in the authors’ own words

  1. Scale. Only 7B language models were tested. Larger ones are untried.
  2. Data. MMC4 is noisy, with advertisements among the text and images, which may bias style.
  3. Prompt sensitivity. The model likes long answers, so tests need tailored prompts to get short ones.
  4. Multi-image composition. Given two images and “A and B,” it sometimes blends them into one subject closer to “A like B.”

Failure mode, as symptom, measurement and fix. Symptom: a reported gain looks bigger than it is. Measurement: compare with the right control (same data, same size) and check the direction of the metric. Fix: quote Table 3 differences of 1 to 2 points as suggestive and re-run with seeds before building on them.

Which statement about Table 3 is best supported by the numbers?

Chapter 8

Field Guide: DreamLLM on One Page

Keep the numbers, the terms, a rebuild checklist, the core code and the reading list in one place

DreamLLM turns a language model into a writer of illustrated documents. It reads images through a frozen CLIP and a linear projector. It paints through a frozen Stable Diffusion, briefed by 64 learned dream queries. A <dream> token tells it when to paint. The only training signal on the image side is the painter’s own noise-prediction error, passed back through the frozen U-Net. Go back to the hero and rerun the three partners: you now know what each one lacks.

The numbers

QuantityValueWhere
Language modelVicuna-7B (LLaMA-1 on ShareGPT)Sec. 3, App. C.2
Visual encoderCLIP ViT-L/14, frozen, 224 × 224, 256 tokens per imageApp. C.2
Image decoderStable Diffusion v2.1 at 512 × 512, frozenApp. C.2
Dream queries64 (32 gives FID 9.56, 128 gives 14.24)Table 9a
Max token length2,048 per training sampleTable 13
Training data30M pairs, then 4M documents and pairs, then 120K instructionsTable 13
Compute128 A800 GPUs, about 6 h, 10 h and 1.5 h per stageTable 13
Guidance scale7.5 default, 2.0 for MS-COCO scoringApp. C.2
FID, MS-COCO / LN-COCO8.46 / 20.53 (SDv2.1: 12.43 / 34.26)Table 2
VQAv2, MMBench, MM-Vet56.6, 49.9, 35.9 (zero-shot, 7B)Table 1
Extra latencyabout 0.2 s over SD at 50 stepsTable 9b

The terms

  1. MLLM: a language model that also takes (here also makes) images.
  2. Comprehension / creation: reading images into words / making images from context.
  3. Dream queries: 64 learned vectors appended after <dream>; their outputs form the painter’s condition.
  4. Score distillation: training the notes with the frozen painter’s own noise-prediction loss.
  5. I-GPT: interleaved generative pre-training on documents with words and pictures mixed.
  6. Synergy: the claim that creating and understanding help each other.

A rebuild checklist

  1. Load Vicuna-7B, CLIP ViT-L/14 and SD v2.1. Freeze CLIP and SD for every stage.
  2. Add a linear projector (CLIP width to 4,096) and another (4,096 to SD’s condition width). Add 64 trainable query vectors and the tokens <IMG>, <IMG/>, <dream>, <dream/>.
  3. Stage I: train only projectors and queries, learning rate 2e-3, on 30M pairs, both captioning and text-to-image.
  4. Stage II: unfreeze the language model, 2e-5, on filtered MMC4 documents plus BLIP-LAION pairs.
  5. Stage III: instruction tuning at 4e-5 for 3 epochs.
  6. Pick and record the choices the paper leaves open: the loss weight between words and images, the truncation rule for long pages, the query initialisation.
  7. Evaluate zero-shot with FID on MS-COCO 30K, VQAv2, MMBench and MM-Vet, with the same prompts and sampling as the paper.

The core as code

python# A sketch of DreamLLM's two core moves. Sizes are the standard ones for these backbones.
class DreamLLM(nn.Module):
    def __init__(self, llm, clip, sd_unet, sd_vae, Q=64):
        self.llm, self.clip = llm, clip.eval()            # Vicuna-7B; CLIP ViT-L/14 (frozen)
        self.unet, self.vae = sd_unet.eval(), sd_vae.eval()  # SD v2.1 (frozen)
        self.vis_proj  = nn.Linear(1024, 4096)       # M_zeta: CLIP width to LLM width
        self.cond_proj = nn.Linear(4096, 1024)       # M_psi: LLM width to SD condition width
        self.dream_q   = nn.Parameter(torch.randn(Q, 4096) * 0.02)  # init is my choice, not the paper's

    def encode_image(self, img):                          # img: (B, 3, 224, 224)
        with torch.no_grad(): f = self.clip(img)            # (B, 256, 1024)
        return self.vis_proj(f)                              # (B, 256, 4096), wrapped by <IMG> ... <IMG/>

    def condition(self, prefix_emb):                       # (B, T, 4096), ends with the <dream> embedding
        q = self.dream_q.expand(prefix_emb.shape[0], -1, -1)
        h = self.llm(inputs_embeds=torch.cat([prefix_emb, q], 1)).last_hidden_state
        return self.cond_proj(h[:, -q.shape[1]:])               # (B, 64, 1024): causal, so queries see the prefix

    def image_loss(self, prefix_emb, image512, alphas_bar):
        C = self.condition(prefix_emb)
        z = self.vae.encode(image512).sample() * 0.18215       # (B, 4, 64, 64) latent; SD's usual scale
        t = torch.randint(0, 1000, (z.shape[0],))
        eps = torch.randn_like(z); a = alphas_bar[t].view(-1, 1, 1, 1)
        zt = a.sqrt() * z + (1 - a).sqrt() * eps
        eps_hat = self.unet(zt, t, encoder_hidden_states=C).sample  # weights frozen, gradient still flows to C
        return F.mse_loss(eps_hat, eps)

# total loss = text cross-entropy (incl. predicting <dream>) + image_loss; the paper gives no weight, so I use 1.0.

Where it sits in the field

DreamLLM belongs to the line of work that tries to make one model both understand and generate. The paper’s related work notes that early systems tokenise images into discrete codebook entries and predict them like words. DreamLLM keeps the painter separate and learns the brief. The lecture it was assigned with, Cross-modal transfer, asks what carries over between modalities; DreamLLM is one answer for the pair of reading and drawing.

Keep going

  1. MMAI lecture 14: Cross-modal transfer, the lecture this paper belongs to.
  2. MMAI lecture 9: Multimodal generation, for the generation side.
  3. MMAI lecture 8: Large multimodal models, for the reading side.
  4. Kosmos-2, another paper on grounding images in a language model.
  5. Diffusion and Contrastive learning and CLIP, the two building blocks in Chapters 1 to 3.
The takeaway. Do not make the language model imitate a summary of the picture. Give it a set of learned slots, let a frozen painter grade what it writes there, and train on whole documents so that it learns where pictures belong. The reported gain in understanding is small, so test it before you rely on it.

Credit: DreamLLM is the work of Runpei Dong, Chunrui Han, Yuang Peng, Zekun Qi, Zheng Ge, Jinrong Yang, Liang Zhao, Jianjian Sun, Hongyu Zhou, Haoran Wei, Xiangwen Kong, Xiangyu Zhang, Kaisheng Ma and Li Yi, published at ICLR 2024 (arXiv 2309.11499, project page). This lesson is an independent reading for the MIT MMAI course follow-along. Any error is ours.

You rebuild DreamLLM and its pictures ignore earlier images in the page. Which part of the design is meant to carry that context?

Now press Present or Teach and explain DreamLLM from memory: why the CLIP target loses detail, what the 64 queries are, how a frozen painter still teaches, and what Table 3 does and does not prove. Then go back to the hero and run it once more.

DreamLLM: Synergistic Multimodal Comprehension and Creation
Read the paper · Project page · The lecture it belongs to · MIT MMAI schedule