TL;DR
Training images come in many sizes, and the usual fixes both cost something. Micro-conditioning hands the model two facts it already knows during training: the original height and width of each image, and the offset of the crop that was taken from it. The model learns to use these as inputs. At sampling time you can set them yourself, and the defaults push the model toward whole, object-centred pictures.
Where you'll see it: in SDXL, where the original size and crop offset are extra inputs alongside the prompt.
Intuition
A photo that was trimmed
Imagine learning to paint from a stack of photos, where some have been trimmed to fit a frame. A painter who never knows which photos were trimmed will start to paint the trimmed look as normal, with a head cut off at the edge. A painter who is told "this photo was 600 by 400, and we kept the square starting 90 pixels in from the left" can tell the trim apart from the subject.
Micro-conditioning does the same for a diffusion model. The trimming happens anyway, in the data pipeline. The model is simply told about it.
Why the idea exists
A latent diffusion model needs every training image to be at least a minimum size, because of how it is built. The paper that introduced micro-conditioning, SDXL, lists two standard answers to small images, and both hurt:
- Drop every image below the training resolution. For SDXL's pretraining data, discarding everything below 256 pixels would throw away 39 percent of the samples.
- Upscale small images. This adds upscaling artifacts that can leak into the outputs, for example as blur.
Micro-conditioning avoids both. Every image is resized and cropped to the training size, and the model is given what the original size was and where the crop came from.
flowchart LR A["Original image (h, w)"] --> B["Resize shorter side to target"] B --> C["Random crop to target size"] A --> D["c_size = (h, w)"] C --> E["c_crop = (c_top, c_left)"] D --> F["UNet conditioning"] E --> F
The math
Let an image have original height and width before any rescaling. Let be the training size, for example . Micro-conditioning adds two vectors to the model's inputs: the size and the crop offset , where and count the pixels cut from the top and the left edge.
Each number is turned into a vector with a Fourier feature encoding. The encodings of the components are concatenated, and the result is added to the timestep embedding that tells the UNet how much noise is present. For size and crop together, the paper concatenates the two embeddings along the channel dimension before the addition. This lesson does not state the feature frequencies or widths.
The sampling rule
During training, the crop is random, so the model sees the crop offset it actually got. The rule is in Algorithm 1 of the paper. After resizing, the shorter side equals the target side, so the longer side has some extra length . The crop offset along that longer side is drawn uniformly from the integers in the range
The offset along the shorter side is zero. If , then and is drawn from that range. If , then and is drawn from it.
Inference
At sampling time the user chooses , which sets the apparent resolution of the picture. The paper sets by default. The reason it gives is that large scale datasets are, on average, object-centric, so offset zero gives whole objects rather than cut-off ones.
Worked examples
Take an image 600 pixels wide and 400 pixels tall, and a training size of .
- The height is less than the width , so the shorter side is the height.
- Scale so the height becomes 256: the scale factor is .
- The width becomes . The resized image is .
- The extra length is , so is drawn from , which has 129 values. Here .
- The chance that the crop starts at the left edge is .
- The model receives and .
Interpretation: the model learns that a 256-pixel square from this photo can start at many horizontal offsets, and it is told which one was used. The numbers are worked out by hand from the sampling rule above, not taken from the paper or measured.
The paper reports that discarding images below 256 pixels would remove 39 percent of its pretraining data. Suppose a set of one million images with that spread.
- Discarding: images remain.
- Micro-conditioning: all images are used, each with its size and crop given to the model.
Interpretation: the conditioning does not add images. It keeps the 390,000 images that the simple filter would have thrown away, at no cost in preprocessing.
The paper trains class-conditional latent diffusion models on ImageNet at and reports FID (lower is better) and IS (higher is better). Its Table 2 has three rows.
| Model | FID | IS |
|---|---|---|
| Only images at least 512 px (70k images) | 43.84 | 110.64 |
| All images, no size conditioning | 39.76 | 211.50 |
| All images, with size conditioning | 36.53 | 215.34 |
- Size conditioning against no conditioning: the FID falls by .
- Size conditioning against keeping only large images: the FID falls by , which is percent of the baseline.
- The IS rises from 211.50 to 215.34, a difference of 3.84.
Interpretation: throwing away data hurts more than the blur that comes from keeping small images, and conditioning on size helps further on top of keeping all the data. The paper also notes that these classical scores are not reliable for text-to-image models, so the table supports the claim only on ImageNet.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Drop images below the training size | Large loss of data, here 39 percent | Micro-conditioning on size |
| Upscale small images | Upscaling artifacts, such as blur, reach the outputs | Micro-conditioning on size |
| Random crop with no record of it | Cut-off objects are learned as normal, the failure seen in older Stable Diffusion models | Record the crop offset as a condition |
| Sample with offset other than zero | Cut-off or off-centre framing, which is useful for simulating a crop | Keep the default for object-centred output |
| Set a size the model rarely saw in training | Output may be unpredictable, since the model has little data for that range | Stay near the sizes in the data |
Alternatives include data bucketing, which groups images by aspect ratio so batches share a shape. The paper says bucketing also solves the size problem, but it gives up the crop augmentation that micro-conditioning keeps, and it needs extra preprocessing. Micro-conditioning is applied online during training.
Related ideas are conditioning augmentation, where a model is conditioned on the amount of augmentation it saw, used in autoregressive and diffusion models. The paper cites this link.
History
Micro-conditioning was introduced in the SDXL paper by Dustin Podell, Robin Rombach and co-authors, posted to arXiv in July 2023. The problem was practical. The Stable Diffusion 1.x models discarded every image under 512 pixels, and their random crops produced cut-off subjects. SDXL was pretrained at 256 pixels, and the authors used the conditioning to keep the full dataset and avoid cut-off objects.
Check yourself
QuestionWhat two pieces of information does micro-conditioning give the model, and where are they added?Show answer
The original height and width of the image, , and the crop offset . Each number is Fourier-encoded, and the encodings are added to the timestep embedding.
QuestionAn image is 1024 pixels wide and 512 pixels tall, and the training size is 256 by 256. The image is resized and then randomly cropped along the longer axis. What is the probability that the crop starts at the far right edge?Show answer
Resize by , so the image becomes . The extra length is , so takes one of , which is 257 values. The chance of the far right, , is .
QuestionWhy not just discard all images below the training size?Show answer
Because it throws away data. For SDXL's pretraining set, discarding images below 256 pixels would remove 39 percent of the samples. Upscaling the small images instead adds artifacts that can appear in the outputs. Micro-conditioning keeps every image and records how it was resized and cropped.
QuestionA user generates a cat in SDXL and its head is cut off at the top of the frame. Using the paper's defaults, what should they set the crop offset to, and why?Show answer
They should set . The paper sets this as the default at inference because large datasets are mostly object-centric, so zero offset gives whole objects. The cut-off head comes from the crop that older models learned from training data, and the zero offset avoids it.
Sources
- Podell et al., SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis, section 2.2: https://arxiv.org/abs/2307.01952
- Rombach et al., High-Resolution Image Synthesis with Latent Diffusion Models: https://arxiv.org/abs/2112.10752