Search

Search papers and lessons

Scaling Rectified Flow Transformers for High-Resolution Image Synthesis (SD3)

Patrick Esser, Sumith Kulal, Andreas Blattmann et al. · 2024

Stable Diffusion 3 trains rectified flow models with a tilted timestep distribution and a two-stream transformer, and shows that validation loss predicts image quality as the model grows.

On this page

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

TL;DR

Diffusion models learn to reverse a fixed path from data to noise, and the choice of path controls how many sampling steps are needed. Rectified flow uses straight paths, which should sample well, but before this paper it had not clearly beaten standard diffusion at scale. The authors make two changes. They sample the training timesteps from a tilted distribution that puts more weight on the middle of the path, and they use a transformer that gives text and image tokens separate weights but joint attention. Their largest model, with 8B parameters, is preferred by human raters over several open and closed text-to-image systems.

Where you'll see it: in text-to-image models that generate high-resolution images from prompts, and in the model's typography and prompt-following benchmarks.

The problem

Diffusion models generate data by reversing a forward process that adds noise. Which forward process to use matters: a curved path needs many integration steps to simulate, while a straight path could in principle be followed in few steps with less accumulated error. Rectified flow is the straight-path choice, and it has better theory, but it had been shown to help mainly in small and class-conditional experiments. The paper asks whether rectified flow can beat the standard latent diffusion recipe for large text-to-image models.

A second problem is the text conditioning. The usual approach feeds a fixed text representation into the image model through cross-attention. The paper compares this with its two-stream design and reports that the two-stream model significantly outperforms a cross-attention variant (CrossDiT) in its ablation.

Key idea

Two things. The first is the training distribution over time. In rectified flow the loss weights every timestep equally, but the target velocity is harder to predict in the middle of the path, so the authors sample intermediate timesteps more often. The second is the architecture. Image and text tokens each get their own weights, but they are concatenated into one sequence for attention, so each modality can read the other while keeping its own representation.

flowchart LR
  P[Prompt] --> T[Frozen CLIP and T5 text encoders]
  I[Image] --> AE[Pretrained autoencoder with 16 latent channels]
  AE --> L[Latent x0]
  L --> M[Mix with noise at time t]
  M --> MM[MM-DiT: image and text streams joined in attention]
  T --> MM
  MM --> V[Predicted velocity]
  V --> S[Sampler integrates back to the latent]

The method

Rectified flow

The forward path is a straight line between data and noise. With data x0x_{0} and standard normal noise ϵ\epsilon, the noisy sample at time tt is

zt=(1−t) x0+t ϵ.z_{t} = (1-t)\,x_{0} + t\,\epsilon.

The network vΘv_{\Theta} predicts the velocity along this path, and its target is ϵ−x0\epsilon - x_{0}, which is the derivative of ztz_{t} with respect to tt. Sampling integrates the predicted velocity from noise back to data, with an ODE solver. Fewer steps means fewer network evaluations.

Tailored timestep sampling

Training with uniform tt weights the velocity loss evenly over the path. The authors observe that the target is harder in the middle, so they replace the uniform density U(t)\mathcal{U}(t) with a density π(t)\pi(t). Changing the density is equivalent to a weighted loss with weight

wtπ=t1−t π(t).w^{\pi}_{t} = \frac{t}{1-t}\,\pi(t).

The density they choose is the logit-normal distribution, with location mm and scale ss:

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

A negative mm biases training toward data, a positive mm toward noise, and ss sets the width. The paper also tests a mode-sampling density and a cosine-based map, and compares all of them with uniform sampling and with the EDM and cosine-schedule formulations.

Architecture: MM-DiT

The backbone builds on the diffusion transformer, which conditions on the timestep and the pooled text embedding through a modulation mechanism. The pooled embedding keeps only coarse information, so the model also takes the full token sequence of the text.

Image latents are split into 2×22 \times 2 patches, and the patch embeddings and text tokens are projected to a common width and concatenated into one sequence. Each modality has its own set of weights. Attention runs over the joined sequence, so the two streams interact, but each keeps weights suited to its own kind of data. The paper notes that this is equivalent to two transformers that share attention. The authors also add RMS normalization on queries and keys, which they found stabilised training. For scaling, the model is set by its depth dd: hidden size 64d64d, and dd attention heads.

Text is encoded by frozen pretrained models: the pooled outputs of two CLIP models, OpenCLIP bigG/14 and CLIP L/14, and a T5 encoder for the token sequence. The paper's ablation shows T5 matters most for complex prompts, such as those with a lot of detail or longer spelled text.

The images are encoded by a pretrained autoencoder with a spatial downsampling factor of 8. The authors chose a 16-channel latent after a study of reconstruction and FID, because a flow model on that space needs more capacity but it scales better.

Worked example: a number from the timestep density

The logit-normal density with m=0m = 0 and s=1s = 1 is symmetric around t=0.5t = 0.5. At t=0.5t = 0.5 the logit is 0, so the exponential term is 1, and the density is

πln(0.5;0,1)=12π⋅10.5⋅0.5=0.3989⋅4≈1.596.\pi_{\text{ln}}(0.5; 0, 1) = \frac{1}{\sqrt{2\pi}} \cdot \frac{1}{0.5 \cdot 0.5} = 0.3989 \cdot 4 \approx 1.596.

The weight of the loss at that point is w=t1−tπ(t)=1⋅1.596=1.596w = \frac{t}{1-t}\pi(t) = 1 \cdot 1.596 = 1.596. Under uniform sampling the density at t=0.5t = 0.5 is 1, so the middle of the path gets about 60 percent more weight. Near t=0.9t = 0.9 the density drops, because the logit-normal puts little mass in the extreme tails.

Results of the formulation study

The paper ranks 61 formulations over sampler settings and two datasets. The table below shows a few rows of its averaged rank, where lower is better.

FormulationAverage rank, all settingsAverage rank, 5 stepsAverage rank, 50 steps
rf/lognorm(0.00, 1.00)1.541.251.50
eps/linear (previous latent diffusion)2.884.252.75
rf (uniform timesteps)5.676.505.75
edm (Karras et al. settings)15.5820.2515.00

Only rectified flow formulations with modified timestep sampling beat the previous latent diffusion formulation. The uniform rectified flow sits below it. This is the main evidence for the timestep change.

Tradeoffs and failure modes

The authors' results point to several practical issues. Some formulations are good at one step count and poor at another: rf/lognorm(0.50, 0.60) is best with 50 steps but ranks 8.5 with 5 steps. Choosing the formulation therefore depends on the sampler budget.

High resolution brings instability. Mixed-precision training can diverge when the model moves to high resolution, and full precision avoids this at a performance cost, according to the authors. QK normalization stabilises attention, because without it the attention logits grow and the attention entropy collapses in the last blocks. Pretraining at 256 pixels and finetuning at higher resolution, with mixed aspect ratios through bucketed sampling, also needs positional encodings that adapt to the resolution.

Higher resolutions also need more noise, because more pixels carry the same signal. The authors shift the sampling schedule with a resolution-dependent function:

tm=α tn1+(α−1) tn,α=m/n,t_{m} = \frac{\alpha\, t_{n}}{1 + (\alpha - 1)\, t_{n}}, \qquad \alpha = \sqrt{m/n},

where nn is the pixel count of the training resolution and mm the target. A human study shows strong preference for shifts above 1.5.

Data filtering and captions matter too. The authors filter for NSFW content, low aesthetic scores and regurgitation, and they mix synthetic and original captions 50/50 because the mix improves GenEval scores in their ablation.

Prior work

The paper's main contribution is the empirical study. The authors say the rectified flow formulation was introduced by Liu et al., Albergo and Vanden-Eijnden, and Lipman et al., and that its advantages had been shown only in small and medium experiments, mostly class-conditional. The latent diffusion setup, the DiT backbone and CLIP-based text conditioning are the prior work the paper builds on.

Results

Scaling. The authors train models of several depths and report that validation loss falls smoothly with both model size and training steps, for image and video models alike. The validation loss on the CoCo dataset correlates with CompBench, GenEval and human preference, so the authors treat it as a simple and general measure. The results do not show saturation in the range tested.

GenEval. Table 5 gives the paper's GenEval results. The largest model, depth 38, with DPO and training at 1024 pixels, scores 0.74 overall. The paper's table lists DALL-E 3 at 0.67, SDXL at 0.55 and SD v2.1 at 0.50.

Human preference. On the Parti prompts, the depth-38 model is preferred by human raters over current proprietary and open models in three categories: visual aesthetics, prompt following and typography. The paper gives the exact questions it asked, and reports the preference as a comparison, not as a single score.

Sampling efficiency. Larger models reach their peak with fewer steps. Table 6 shows the relative CLIP score drop when sampling with 5 or 10 steps instead of 50, which shrinks with model size. The authors attribute this to larger models fitting the straight-path objective better.

DPO. The paper applies a preference-optimization step for diffusion models, following the method of Wallace et al., and reports that raters prefer the DPO-finetuned models for prompt following and general quality.

Why it mattered

The paper states its own contribution: a scaling analysis of rectified flow for text-to-image synthesis, a timestep sampling that improves on previous latent diffusion training, and an architecture that treats text and image as two streams. It reports a predictable scaling trend in validation loss and that lower loss correlates with better automatic and human evaluations.

The paper does not report what followed from its release, so this lesson does not describe any downstream effect.

Reading guide

Read the paper in this order, using these prerequisite lessons:

  1. Section 1, Introduction. Needs Diffusion Model for forward and backward processes and Flow Matching for Generative Modeling for the idea of rectified flow as a straight path. The introduction's argument about curved paths and step counts depends on that.
  2. Section 2, Simulation-free training. Needs Ordinary Differential Equation to understand integrating a velocity field, and Flow Matching for Generative Modeling for the training objective.
  3. Section 3, Flow trajectories. Needs Flow Matching for Generative Modeling for the rectified flow path. The density π(t)\pi(t) and the weight wtπw^{\pi}_{t} need only basic probability, plus Diffusion Model for the noise schedule. The logit-normal density is defined in the same section.
  4. Section 4, Architecture. Needs Diffusion Transformer (DiT) for the base backbone, Multimodal Diffusion Transformer for the two-stream design, Classifier-Free Guidance for the conditioning, Learning Transferable Visual Models From Natural Language Supervision (CLIP) and Exploring the Limits of Transfer Learning (T5) for the text encoders.
  5. Section 5, Experiments. Needs Diffusion Transformer (DiT) for the scaling study and Multimodal Diffusion Transformer for the final model. The GenEval and human preference results need no further prerequisites.
  6. Appendix C, DPO. Needs the preference-optimization idea from the language model side, so read the DPO lesson if you have not already.

Check yourself

QuestionIn the rectified flow path z_t = (1 - t) x_0 + t epsilon, what is the training target for the velocity, and why is it the derivative?Show answer
The target is epsilon minus x_0. Differentiating z_t with respect to t gives minus x_0 plus epsilon, which is that difference. The network learns to predict the direction and speed of the straight path at each time.
QuestionUsing the logit-normal density with m = 0 and s = 1, what is the loss weight w = t/(1-t) times pi(t) at t = 0.5?Show answer
At t = 0.5 the logit is 0, so the density is 1/sqrt(2 pi) times 1/(0.25), which is about 1.596. The weight is t/(1-t) = 1 times that density, so w is about 1.596.
QuestionIn Table 1 of the paper, rf/lognorm(0.00, 1.00) has an average rank of 1.54, and eps/linear has 2.88. What does the lower number mean, and what does it say about the change?Show answer
Lower rank is better. The change of timestep sampling moves rectified flow from 5.67 (uniform timesteps) to 1.54, which puts it ahead of the previous latent diffusion formulation at 2.88. This is evidence that the sampling change, not only the straight path, is what improves results.
QuestionThe paper's largest model reaches 0.74 on GenEval and DALL-E 3 reaches 0.67. What is the difference in points, and why might a single benchmark score not be enough to compare the two models?Show answer
The difference is 0.07 on a 0 to 1 scale. A single benchmark is not enough because GenEval covers only some capabilities; the paper also reports human preference, which shows the model is preferred on aesthetics, prompt following and typography, and the authors argue that validation loss correlates with both.
QuestionWhy does the paper use mixed aspect ratios with bucketed sampling at high resolution?Show answer
Each batch has images of one size H times W, close to the target area, so the model sees a range of aspect ratios without padding every image to one shape. The positional encodings then have to be adapted to each resolution, which the paper addresses by extending them.

Sources

Read the full paper

Patrick Esser, Sumith Kulal, Andreas Blattmann et al., 2024. arXiv:2403.03206