Search

Search papers and lessons

Multimodal Diffusion Transformer

Level 4 · 11 min read

A multimodal diffusion transformer gives text and image tokens separate weights but lets them attend to each other in one joint sequence, so the prompt shapes the image at every layer.

On this page

  • Colour = topic mix
  • Probability
  • Architectures
  • Calculus
  • Generative models
  • Neural network basics
  • Linear algebra
  • Sign in to see your progress

TL;DR

A multimodal diffusion transformer, or MM-DiT, processes text tokens and image tokens in one joint sequence. Each modality has its own weights, so the two streams can keep their own representations, but the attention step runs over both streams together. The prompt therefore influences the image in every layer, not just once at the start.

Where you'll see it: in text-to-image models that use the Stable Diffusion 3 design, where it denoises the latent image of a latent diffusion model while reading the prompt through its text stream.

Intuition

Two translators in one meeting

Imagine two translators who speak different languages and work for the same client. A text translator knows the prompt. An image translator knows the picture being drawn. Each keeps their own notes, since the words of a sentence and the patches of a picture are very different kinds of thing.

In an older design, the image side only looked at the text through a single window, called cross-attention. The image asked a question of the text, received an answer, and that was all. The text never learned anything from the image. A multimodal diffusion transformer puts both sets of notes on the same table for each round of discussion. Each side reads the other's current state before updating its own. Over many layers the text representation is refined in light of the partly drawn image, and the image is refined in light of the words.

The paper motivates this directly. Text and image embeddings are conceptually quite different, so it gives them separate weights, but it joins the sequences for the attention operation so that each representation can work in its own space while taking the other into account (Esser et al., 2024, section 4).

Why the image is a sequence of patches

A diffusion transformer does not run on raw pixels. A pretrained autoencoder first compresses the image into a smaller latent grid, and the denoiser works on that grid. This is the Latent Diffusion Model idea: the expensive denoising happens on a compact code, and a decoder turns the final code back into pixels. The latent grid is then cut into small square patches, and each patch becomes one token. A transformer can handle a sequence of tokens, so the image has become a sequence like the text.

flowchart LR
  P[Prompt] --> T1[Text encoders]
  T1 --> TS[Text tokens]
  N[Noisy latent image] --> PA[2 by 2 patches]
  PA --> IS[Image tokens]
  TS --> J[Joint attention over both sequences]
  IS --> J
  J --> OUT[Predicted velocity for the image]

The math

Let x0x_0 be a clean latent image, ϵ\epsilon a sample of standard Gaussian noise of the same shape, and cc the text conditioning. The model is trained on noisy latents ztz_t at a time t∈(0,1)t \in (0, 1).

The rectified flow path

Rectified flow uses the simplest possible path from data to noise, a straight line:

zt=(1−t) x0+t ϵ.z_t = (1 - t)\, x_0 + t\, \epsilon.

At t=0t = 0 the sample is the clean image, and at t=1t = 1 it is pure noise. The velocity along this path is constant, dztdt=ϵ−x0\frac{d z_t}{d t} = \epsilon - x_0. The network vΘv_\Theta is trained to predict that velocity from the noisy latent, the time and the condition:

L=Et,x0,ϵ ∥vΘ(zt,t,c)−(ϵ−x0)∥2.\mathcal{L} = \mathbb{E}_{t, x_0, \epsilon}\,\Big\| v_\Theta(z_t, t, c) - (\epsilon - x_0) \Big\|^2.

This is a plain regression, and it needs no simulation of an ODE during training. That is the main practical gain of the flow-matching view, covered in Flow Matching.

A quick check of the path. Take x0=2x_0 = 2 and ϵ=−2\epsilon = -2, so the target velocity is ϵ−x0=−4\epsilon - x_0 = -4. At t=0.25t = 0.25, zt=0.75⋅2+0.25⋅(−2)=1z_t = 0.75 \cdot 2 + 0.25 \cdot (-2) = 1. If the network predicted the target exactly, one Euler step from t=1t = 1 back to t=0t = 0 gives z0=z1+(0−1)⋅v=−2+(−1)(−4)=2z_0 = z_1 + (0 - 1)\cdot v = -2 + (-1)(-4) = 2, which is x0x_0.

The time sampler

The paper argues that the choice of timesteps matters. Instead of drawing tt uniformly, it draws tt from a logit-normal distribution. Write logit(t)=log⁡t1−t\mathrm{logit}(t) = \log\frac{t}{1 - t}. The density is

πln(t;m,s)=1s2π⋅1t(1−t)exp⁡ ⁣(−(logit(t)−m)22s2).\pi_{\mathrm{ln}}(t; m, s) = \frac{1}{s\sqrt{2\pi}} \cdot \frac{1}{t(1 - t)} \exp\!\left(-\frac{(\mathrm{logit}(t) - m)^2}{2 s^2}\right).

The location mm biases training towards the data end (negative mm) or the noise end (positive mm). The scale ss sets how wide the distribution is. The paper reports that this sampler beats uniform timesteps for rectified flow, and beats the diffusion baselines it compares against, in its own experiments.

Joint attention

Let the image stream have token matrix XX and the text stream have token matrix CC. Each stream has its own projection weights, which is the "two sets of weights" idea. For each stream s∈{x,c}s \in \{x, c\} the layer computes its queries, keys and values with its own matrices:

Qs=XsWsQ,Ks=XsWsK,Vs=XsWsV,Q_s = X_s W^{Q}_{s}, \qquad K_s = X_s W^{K}_{s}, \qquad V_s = X_s W^{V}_{s},

where Xx=XX_x = X and Xc=CX_c = C. The streams are then joined along the sequence axis for the attention step only:

Attn=softmax ⁣([Qx;Qc] [Kx;Kc]⊤dh)[Vx;Vc].\mathrm{Attn} = \mathrm{softmax}\!\left(\frac{[Q_x; Q_c]\,[K_x; K_c]^\top}{\sqrt{d_h}}\right)[V_x; V_c].

The semicolon means stacking along the sequence. The output rows are split back into the two streams, and each stream then passes through its own feed-forward block. Every position can attend to every other position, so image tokens can read text tokens and the reverse.

Using a single set of weights for both streams, with the two sequences concatenated, is the vanilla diffusion transformer variant. The paper compares it with MM-DiT and finds it weaker.

Timestep conditioning

The timestep tt and a pooled summary of the text, cvecc_{\mathrm{vec}}, enter through the adaptive normalisation of Diffusion Transformer (DiT). The pooled vector carries only coarse information about the prompt, so the full sequence of text tokens is also needed. The paper uses both: the pooled vector modulates each block, and the token sequence takes part in attention.

Normalising queries and keys

Large transformers can diverge during training, because the attention logits grow until the softmax saturates. The paper applies RMS normalisation with a learnable scale to the queries and keys in both streams. It reports that this prevents the logit growth and the collapse in attention entropy that goes with it, and that it allows stable training in mixed precision.

Worked examples

Example
Image tokens for a 1024 by 1024 picture

Take the paper's setup: an autoencoder with downsampling factor f=8f = 8 and d=16d = 16 latent channels, followed by 2×22 \times 2 patches. The numbers are from the paper's configuration. The text length of 256 tokens is an illustrative choice.

  1. The latent grid is 1024/8=1281024 / 8 = 128 by 128128 with 16 channels.
  2. Patching by 2×22 \times 2 gives a grid of 6464 by 6464, so 40964096 image tokens.
  3. Each patch holds 2⋅2⋅16=642 \cdot 2 \cdot 16 = 64 numbers, which is the input size of one image token before its embedding.
  4. The joint sequence has 4096+256=43524096 + 256 = 4352 tokens.
  5. One attention head then has a score matrix of 43522=18,939,9044352^2 = 18{,}939{,}904 entries, about 18.9 million.

Interpretation: almost all of the sequence is image, so the cost of joint attention is dominated by image-to-image attention. Adding the text tokens to the sequence costs little in comparison. This is why the design can fuse modalities without a large overhead.

Example
One rectified flow step on a scalar

Take the path from the math section with x0=2x_0 = 2 and ϵ=−2\epsilon = -2, so the target velocity is −4-4 at every tt.

  1. At t=0.25t = 0.25, zt=0.75⋅2+0.25⋅(−2)=1.5−0.5=1z_t = 0.75 \cdot 2 + 0.25 \cdot (-2) = 1.5 - 0.5 = 1.
  2. Assume the network predicts v=−4v = -4 exactly.
  3. Start at t=1t = 1 with z1=ϵ=−2z_1 = \epsilon = -2, and take a single Euler step of size −1-1 in time: z0=z1+(0−1)⋅v=−2+4=2z_0 = z_1 + (0 - 1) \cdot v = -2 + 4 = 2.
  4. The result z0=2z_0 = 2 equals x0x_0.

Interpretation: a straight path with a constant velocity means one step is enough if the velocity is right. In practice the velocity depends on the input and the model's prediction is imperfect, so sampling uses several steps.

Example
How the time sampler shifts training

Compare the logit-normal density with m=0m = 0 and s=1s = 1, which puts the mass in the middle of the path.

  1. At t=0.5t = 0.5: logit(0.5)=0\mathrm{logit}(0.5) = 0, and 1t(1−t)=4\frac{1}{t(1 - t)} = 4. The density is 12π⋅4⋅e0≈1.60\frac{1}{\sqrt{2\pi}} \cdot 4 \cdot e^0 \approx 1.60.
  2. At t=0.99t = 0.99: logit(0.99)=ln⁡99≈4.595\mathrm{logit}(0.99) = \ln 99 \approx 4.595. The exponent is −4.59522≈−10.56-\frac{4.595^2}{2} \approx -10.56, so e−10.56≈2.6⋅10−5e^{-10.56} \approx 2.6 \cdot 10^{-5}. Also 10.99⋅0.01≈101\frac{1}{0.99 \cdot 0.01} \approx 101. The density is 12π⋅101⋅2.6⋅10−5≈0.001\frac{1}{\sqrt{2\pi}} \cdot 101 \cdot 2.6 \cdot 10^{-5} \approx 0.001.
  3. The density at the middle is about 1,500 times the density near pure noise.

Interpretation: with m=0m = 0 the sampler spends most of its training effort on intermediate noise levels, and rarely visits the extremes. Changing mm moves that effort towards the data or the noise end, and ss controls how concentrated it is.

Tradeoffs and failure modes

The joint design costs more than cross-attention, and the paper reports that MM-DiT significantly outperforms the cross-attention and vanilla variants on validation loss, CLIP score and FID, and that a three-stream version adds only a small gain. The table summarises the choices.

SituationProblemBetter choice
Simple class-conditional generationNo text stream is neededA plain Diffusion Transformer (DiT) is enough
Text-to-image with rich promptsA single cross-attention window carries little prompt detailMM-DiT with separate text and image weights
More modalities or more text encodersEach stream needs its own weights, so parameters and memory growTwo streams, or a third set only when the gain justifies the cost
Limited GPU memory at high resolutionImage tokens dominate the sequence and attention scales with its squareSmaller patches or a latent with fewer tokens, at a cost in detail
Training at high resolution in mixed precisionAttention logits can grow and divergeNormalise queries and keys, and check the loss curve closely

Failure modes to watch for:

  • Sharing one set of weights. In the paper's comparison on CC12M, the vanilla variant with one shared set of weights underperformed MM-DiT, and a third parameter set gave only a small further gain at the cost of more parameters and memory.
  • Unstable high-resolution fine-tuning. The paper pretrains at 2562256^2 and then finetunes at higher resolutions with mixed aspect ratios. Mixed precision can diverge there, and the paper reports that full precision avoids it at a cost of about a factor of two in performance, The normalisation of queries and keys is the cheaper fix.
  • Trusting the pooled text vector alone. The pooled summary keeps only coarse information. Dropping the sequence of text tokens loses fine prompt detail, such as spelling and spatial relations.
  • Reading scaling curves as guarantees. The paper shows that validation loss decreases smoothly with model size and correlates with image metrics. The correlation was measured for its own models and data, and should not be assumed for another architecture.

History

Before this design, text-to-image diffusion models fed a fixed text representation into the image network, usually through cross-attention. The latent diffusion work of Rombach and colleagues used this approach. The paper frames it as the widely used baseline, and argues that a fixed text representation fed directly into the model is not ideal (Esser et al., 2024, introduction). Cross-attention variants of the diffusion transformer also existed, which the paper calls CrossDiT.

Esser and colleagues proposed MM-DiT in 2024 as a backbone with learnable streams for both image and text tokens. In their comparison on CC12M, the multimodal design significantly outperformed the vanilla concatenation and cross-attention variants, and a three-stream version gave only a small further gain. They chose two streams for the rest of the work. The same paper paired this backbone with the rectified flow formulation and the logit-normal sampler.

The paper does not discuss later adoption beyond its own experiments, so this lesson makes no claim about its later influence.

Check yourself

QuestionIn MM-DiT, what is shared between the image and text streams, and what is separate?Show answer

The attention operation is shared: the queries, keys and values of both streams are concatenated along the sequence and attend to each other. The projection weights and the feed-forward blocks are separate for each stream, so each modality keeps its own representation.

QuestionWith x0=4x_0 = 4, ϵ=0\epsilon = 0 and t=0.5t = 0.5, what is ztz_t in the rectified flow path, and what velocity should the network predict?Show answer

z0.5=0.5⋅4+0.5⋅0=2z_{0.5} = 0.5 \cdot 4 + 0.5 \cdot 0 = 2. The target velocity is ϵ−x0=0−4=−4\epsilon - x_0 = 0 - 4 = -4.

QuestionWhy does joint attention cost little extra when the text sequence is short, and why does that matter for the design?Show answer

The attention score matrix grows with the square of the total sequence length. With about 4096 image tokens and a few hundred text tokens, the text adds only a small fraction to the total, so most of the cost is image-to-image attention that the model would pay anyway. This makes it cheap to let the text stream take part in every layer.

QuestionYou want the model to put more training effort into high-noise timesteps. Which way should you move the location parameter mm of the logit-normal sampler, and why?Show answer

Move mm towards positive values. The paper says positive mm biases training towards the noise end, tt near 1, while negative mm biases it towards the data end, tt near 0. Adjusting ss instead would only change how concentrated the samples are, not which end they favour.

Sources