Search

Search papers and lessons

SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis

Dustin Podell, Zion English, Kyle Lacey et al. · 2023

SDXL is a 2.6B-parameter latent text-to-image model that adds size and crop conditioning so it can train on all images, plus a refiner that sharpens its outputs.

On this page

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

TL;DR

SDXL is a text-to-image latent diffusion model with a UNet about three times larger than Stable Diffusion's, and 2.6 billion parameters against 860 million. The paper adds conditioning on the original image size and on crop position, so that small images are no longer thrown away. A separate refinement model then sharpens the base model's latents. The paper reports that users preferred the full pipeline over Stable Diffusion 1.5 and 2.1.

Where you'll see it: in open text-to-image pipelines that generate at 1024 by 1024 pixels, and in the paper's own model weights, which the authors release alongside the code.

The problem

Stable Diffusion's training data had a practical problem. A latent diffusion model needs a fixed minimum image size, because it runs in two stages, an autoencoder and then a diffusion model. The usual fixes both hurt. Discarding images below the minimum throws data away: the paper says that discarding everything below 256 pixels would remove 39% of its pretraining set. Upscaling small images fixes the size but adds artifacts, and those can leak into the model's outputs as blur.

A second problem came from random cropping. Training pipelines resize an image, then crop the longer side at random. That crop is a useful augmentation, but the model cannot tell that a crop happened, so it learns that objects are sometimes cut off. The paper's Figure 4 shows an example, a cat whose head is cut off in outputs from SD 1.5 and SD 2.1.

Finally, the paper argues that square output formats are an unnatural default. Most real screens and photos are landscape or portrait, so a model trained only on squares fits them poorly.

Key idea

SDXL keeps the latent diffusion recipe and changes what the model is told during training. Three conditioning signals carry information that would otherwise be lost.

  1. Original size. The model is given the original height and width of each image before rescaling. At inference, the user picks the apparent resolution.
  2. Crop coordinates. During training the model is given the top and left crop offsets. At inference the paper sets them to (0,0)(0, 0), which produces object-centred samples.
  3. Target aspect bucket. During multi-aspect training the model is given the target size of the bucket the image came from.

These signals have no supervision cost, because the information is already available when the data is loaded. The paper calls the first two micro-conditioning, and that is the concept Micro-Conditioning that this paper introduces.

The paper also changes the architecture and the text conditioning, and it adds a second model, the refiner, which runs after the base model.

flowchart LR
  P[Prompt] --> T[Two text encoders]
  T --> B[Base UNet with size, crop and aspect conditioning]
  B --> L[Base latents at 128 by 128]
  L --> R[Refiner UNet via SDEdit noising and denoising]
  R --> D[Decoder to a 1024 by 1024 image]

The method

Architecture and scale

The paper uses a UNet with the same overall shape as Stable Diffusion's but a different distribution of transformer blocks. It omits the transformer block at the highest feature level, uses 2 blocks at the next level and 10 at the lowest retained level, and removes the lowest, 8×8\times-downsampled level altogether. Most of the transformer computation moves to lower-resolution features.

The text conditioning is also stronger. The model uses OpenCLIP ViT-bigG together with CLIP ViT-L, and it concatenates the penultimate outputs of the two encoders along the channel axis. The model is also conditioned on the pooled OpenCLIP embedding. These changes give a UNet of 2.6 billion parameters, against 860 million for SD 1.4 and 1.5 and 865 million for SD 2.0 and 2.1. The two text encoders together have 817 million parameters.

Micro-conditioning on size

The size signal is csize=(horiginal,woriginal)\mathbf{c}_{\text{size}} = (h_{\text{original}}, w_{\text{original}}). Each component is embedded with a Fourier feature encoding. The two embeddings are concatenated and added to the timestep embedding. Training then never has to discard small images, and the model learns to associate the size signal with resolution-dependent features.

The paper tests this on class-conditional ImageNet at 512×512512 \times 512 with three models. The first, CIN-512-only, trains only on images with both edges at least 512 pixels, leaving 70k images. The second uses all images without size conditioning. The third uses all images with size conditioning. The results in its Table 2 are:

ModelFID-5k (lower is better)IS-5k (higher is better)
CIN-512-only43.84110.64
CIN-nocond39.76211.50
CIN-size-cond36.53215.34

The conditioned model is best on both metrics. The paper's explanation for the two baselines is that the 70k-image model generalizes badly because it overfits its small training set, and that the unconditioned model produces a mode of blurry samples, which worsens its FID.

Micro-conditioning on crop

The crop signal is ccrop=(ctop,cleft)\mathbf{c}_{\text{crop}} = (c_{\text{top}}, c_{\text{left}}). During data loading the crop offsets are sampled uniformly, and the image is cropped at those offsets. The model is given the offsets, so the crop is still useful as augmentation but does not leak into the output. The paper's Algorithm 1 samples the offset along the longer axis only. The two signals can be combined, by concatenating their embeddings along the channel dimension before adding them to the timestep embedding.

At inference, the paper sets the crop to (0,0)(0, 0). Because large datasets are on average object-centric, this gives centred samples. Setting the offsets to other values simulates different amounts of cropping, which the paper calls conditioning augmentation.

Multi-aspect training

The paper partitions the data into buckets of different aspect ratios. It keeps the pixel count of each bucket close to 102421024^2 and varies height and width in multiples of 64. A training batch comes from one bucket, and the model alternates between buckets across steps. The target bucket size is given to the model as a third conditioning tuple. This stage is applied as fine-tuning after the fixed-resolution pretraining, and the paper notes that crop conditioning then only works within bucket boundaries.

The autoencoder

Stable Diffusion's local detail is limited by its autoencoder. The paper trains the same architecture at a larger batch size, 256 against 9, and tracks the weights with an exponential moving average. The paper's Table 3 compares reconstruction on COCO2017 validation images at 256×256256 \times 256:

AutoencoderPSNR (higher)SSIM (higher)LPIPS (lower)rFID (lower)
SDXL-VAE24.70.730.884.4
SD-VAE 1.x23.40.690.965.0
SD-VAE 2.x24.50.710.924.7

The new autoencoder is best on every metric. The paper also notes that it was trained from scratch, while the SD 2.x decoder was fine-tuned with a reduced perceptual loss.

Training schedule

The base model uses a discrete-time diffusion schedule with 1000 steps. It is pretrained for 600,000 optimization steps at 256×256256 \times 256 with batch size 2048, using size and crop conditioning. It is then trained for 200,000 more steps at 512×512512 \times 512. Finally, multi-aspect training is applied at about 1024×10241024 \times 1024 pixels, with offset noise of 0.05.

The refinement stage

Base-model samples sometimes have low local quality. The paper trains a separate latent diffusion model on high-quality, high-resolution data, specialised to the first 200 discrete noise scales. At inference, the base model produces latents, and the refiner adds noise and denoises them in latent space using the same prompt. This is the SDEdit procedure. The paper says the step is optional, and that it improves detailed backgrounds and human faces.

Results

User preference

The paper runs a user study in which people pick their favourite among four models: SDXL, SDXL with the refiner, Stable Diffusion 1.5, and Stable Diffusion 2.1. The reported win rates are:

ModelWin rate
SDXL with refiner48.44%
SDXL base36.93%
Stable Diffusion 1.57.91%
Stable Diffusion 2.16.71%

These four numbers sum to 99.99%, which is the rounding of 100%. The refiner pipeline is the highest rated, and the paper says both SDXL variants beat the older models by a significant margin.

The paper also reports that classical metrics such as FID and CLIP score do not reflect these gains. Its Figure 12 shows that SDXL's CLIP score improves only slightly, which the authors connect to earlier findings that such metrics do not track human judgement well for text-to-image models.

Comparison with Midjourney

The paper compares SDXL v0.9 with Midjourney v5.1 on the PartiPrompts benchmark. Across 17,153 user preference comparisons, SDXL was favoured 54.9% of the time. By category, the paper says SDXL outperforms Midjourney in four of six categories, and in seven of ten challenges there is no significant difference or SDXL is better. The paper treats the comparison as evidence of prompt adherence, not overall image quality.

Failure modes the paper reports

The paper's Figure 7 shows failures on very complex prompts with detailed spatial arrangements. It also says the model still struggles to render long, legible text, and that its text is sometimes garbled. The two-stage pipeline is a limitation the authors name directly: it needs two large models in memory, which hurts accessibility and speed.

Why it mattered

The paper's stated contribution is an open model with competitive results. It releases code and model weights under the Stability AI GitHub organisation, and it says the goal is to support transparent evaluation and reproducibility, in contrast to closed black-box generators.

The micro-conditioning idea is the more transferable result, and the paper says it is not specific to latent models. The crop-conditioning section states that the technique could be used for any diffusion model. The paper's own evidence for that is the ImageNet experiment in Table 2 and the qualitative comparisons, not a test on other architectures.

Reading guide

Read the paper in this order. Each step names the prerequisites it needs.

  1. Section 1, Introduction. Needs Latent Diffusion Model for what Stable Diffusion is, and Classifier-Free Guidance for the guidance scale that appears in the figures.
  2. Section 2.1, Architecture and scale. Needs U-Net for the backbone, Attention Mechanism for the transformer blocks, CLIP for the text encoders, and Variational Autoencoder for the latent space.
  3. Section 2.2, Micro-conditioning. Needs Micro-Conditioning. Read Table 2 and Figure 2 for the data argument.
  4. Section 2.3, Multi-aspect training. Needs Micro-Conditioning for the bucket conditioning, and no further lesson.
  5. Section 2.4, Improved autoencoder. Needs Variational Autoencoder for reconstruction metrics.
  6. Section 2.5, Refinement stage. Needs Latent Diffusion Model for the noising and denoising process in latent space.
  7. Section 3, Results. Needs Classifier-Free Guidance for the cfg scale used in the figures, and the reader should keep the caveat about FID and CLIP scores in mind.

Check yourself

QuestionThe paper says its UNet is three times larger than Stable Diffusion's. What do Table 1's numbers give as the ratio, and is the claim consistent?Show answer

The UNet has 2.6 billion parameters against 860 million, so the ratio is 2600/860≈3.022600 / 860 \approx 3.02. That is consistent with the claim of three times larger.

QuestionThe refiner's user study win rates are 48.44%, 36.93%, 7.91% and 6.71%. What do they sum to, and what does that tell you about the study design?Show answer

They sum to 48.44+36.93+7.91+6.71=99.9948.44 + 36.93 + 7.91 + 6.71 = 99.99, which is 100% after rounding. The four models were compared as a forced choice among exactly four options, so every vote goes to one model. That is why the shares partition the total.

QuestionWhy does size conditioning let the model train on small images without the blur that upscaling causes?Show answer

Without size conditioning, small images either have to be discarded or upscaled to the minimum size, and upscaling introduces artifacts the model then learns. With size conditioning, each image is trained at its original resolution, and the model is told that resolution through the size signal. At inference the user chooses the apparent resolution, so the model does not have to pretend a small image is large.

QuestionWhy does the paper set the crop offsets to (0, 0) at inference, and what would other offsets do?Show answer

Large datasets are on average object-centric, so the zero offset tends to produce a centred object rather than a cut-off one. Other offsets simulate different amounts of cropping, which the paper calls conditioning augmentation. Choosing offsets this way lets the user control framing without changing the training data.

QuestionA 512 by 512 ImageNet model trained only on images with both edges at least 512 pixels has 70k training images. What does Table 2 suggest about discarding data?Show answer

Table 2 shows that the 70k-image model has the worst FID of the three, 43.84, against 39.76 for the unconditioned model on all data and 36.53 for the size-conditioned model. So discarding small images hurt here. The paper attributes this to overfitting on the smaller dataset.

Sources

Read the full paper

Dustin Podell, Zion English, Kyle Lacey et al., 2023. arXiv:2307.01952