Latent diffusion and diffusion transformers

How a text-to-image model's denoiser is built and what an image costs: why it works on a VAE latent, the U-Net, DiT and MMDiT, how text gets in, positions and resolution, and few-step distillation. Parameters and FLOPs counted from eleven real configs; SD 1.5 profiled and its cross-attention recorded on an Apple M1 Pro. Data as of October 2026. Reading: 39 min, plus 15 in closed details.

A text-to-image model runs one large network, the denoiser, tens of times on a small VAE latent while a text encoder steers it, so the price of an image is FLOPs per denoiser pass × passes per image. Every design on this page changes one of those two factors or how the text reaches the image: the latent shrinks the pass, the U-Net and the diffusion transformer (DiT) are two ways to build it, cross-attention and joint attention are two ways to read the prompt, and distillation cuts the passes.

Fig. 1, step by step: one image from Stable Diffusion 1.5: the denoiser runs 50 times, everything else once

  1. The prompt, once. CLIP's tokenizer cuts the prompt into 77 positions (section 3); CLIP ViT-L's text encoder (123.1M parameters) turns them into 77 vectors of 768, once per prompt (twice with guidance, for the empty prompt).
  2. A latent, not an image. The denoiser works on a 64 × 64 × 4 latent, 16,384 numbers standing for the 512 × 512 × 3 image, and starts from pure noise. Here the two are not to scale; Fig. 2 draws them so.
  3. The denoiser, 50 times. The U-Net (859.5M parameters, 0.80 TFLOP per pass at 512 pixels, counted) runs at every one of 25 sampler steps, twice per step with classifier-free guidance (the prompt and the empty prompt, batched), and every pass reads the 77 text vectors.
  4. The VAE decoder, once. 83.7M parameters draw the final latent as the 512 × 512 × 3 image.
  5. Where the time goes. The two columns are to scale: 25 guided steps of 0.610 s against one decode of 0.488 s. The price of an image is FLOPs per pass × passes per image.

The running example at the topic's settings (512 × 512, 25 DPM-Solver++ steps, guidance 7.5). Times are the topic's diffusion runs on Apple M1 Pro (root Diffusion lab recordings): 0.319 s per U-Net pass, 0.610 s per guided step (two passes batched), 0.488 s per VAE decode; 25 × 0.610 = 15.3 s of denoising against one decode. measured derived Parameters counted from the configs.

You need: the transformer block, attention and patch tokens that a DiT reuses (The transformer from zero: one block, every shape, a GPT you train); what a denoiser predicts, how a sampler and classifier-free guidance use it, and the forward process and schedule underneath (Diffusion from zero: targets and loss section 3, the three views section 4, samplers section 5, guidance section 6; for SD3 and FLUX, the velocity objective of Flow matching), and the VAE that makes the latent, with its scaling factor (Autoencoders and VAEs, section 11). The parent Topic: generative-and-multimodal gives the map of the topic; its Model map (one prompt through six real pipelines, with every generator's release, licence and size) is reused here, not repeated.

Latent
the VAE's compressed grid standing in for the image: 64 × 64 × 4 for a 512 × 512 SD 1.5 image.
Denoiser, timestep
the network that takes a noisy latent and its noise level (the timestep) and predicts the noise or velocity at every position.
U-Net
a convolutional denoiser that shrinks the grid level by level and grows it back, with skip connections across.
DiT, patchify
a transformer denoiser: the latent is cut into p × p patches, each patch one token.
Cross-attention
image positions as queries, the prompt's text vectors as keys and values.
adaLN-Zero
conditioning by predicting each block's LayerNorm shift and scale and a residual gate, initialised to zero.
MMDiT, single stream
one attention over image and text tokens, with separate weights per modality (MMDiT) or shared weights (single stream).
Passes per step
2 with classifier-free guidance (conditional and unconditional prediction), 1 without or after guidance distillation.
Distillation
training a student to do in a few passes what the teacher sampler does in many.

Six denoiser designs on one screen: how the image is held, how the text gets in, what a pass costs

DesignExampleHow the image is heldHow text gets inParametersFLOPs per pass at 1024 px

Rows in the order the designs appeared. Parameters counted from each config on PyTorch's meta device (no weights), checked exactly against measured or public Hub totals; FLOPs for one denoiser pass at 1024 × 1024 with the pipeline's default text length (two FLOPs per multiply-accumulate, torch.utils.flop_counter). derived Breakdowns: Architecture explorer.

The running example and how everything was counted (provenance)

The topic's own (root src/data/README.md): Stable Diffusion 1.5 in float16 (U-Net 859,520,964 parameters, CLIP ViT-L/14 text encoder 123,060,480, VAE 83,653,863; pinned revision 451f4fe), run on the laptop's GPU with the topic's prompts, for everything about a real U-Net; the topic's tiny denoisers on Fashion-MNIST (grey 28 × 28 clothing, padded to 32 × 32): the 1.04M-parameter TinyUNet of the topic's flow runs (root src/flow), and the shared TinyDiT trained here with exactly the same recipe; and the configs of ten more denoisers (SDXL, DiT-XL/2, PixArt-Σ, Sana, SD3 Medium, SD3.5 Large, FLUX.1, FLUX.2 [klein], Qwen-Image, Z-Image), instantiated without weights so their parameters and FLOPs can be counted exactly.

To count any model: instantiate it on the meta device and run it under FlopCounterMode (src/arch/fwd_meta.py does this for every model on this page in seconds, with no weights). To time it: one pass at several sizes (section 9 does this on the laptop's GPU).

1. Why latent diffusion: the compute arithmetic

The problem. The denoiser runs tens of times per image (at the topic's settings: 25 steps, each two passes with guidance), so everything it costs is multiplied. A 512 × 512 colour image is 786,432 numbers, while the details that matter to a viewer (shapes, layout, texture statistics) are far fewer.

How it works. Train an autoencoder once, then train and run the denoiser on its latent. Stable Diffusion's VAE maps 512 × 512 × 3 to 64 × 64 × 4 = 16,384 numbers, 48 times fewer (the downsampling factor f = 8 per side, 4 channels). The decoder runs once at the end; the denoiser never sees a pixel. Rombach et al. called this splitting "perceptual compression" (the autoencoder) from "semantic compression" (the generator); the paper's own f sweep is rebuilt on the LDM paper page, with a live toy of latent against pixel diffusion at fixed compute.

Fig. 2, step by step: the same image as pixels and as a latent, drawn to scale

  1. The image: 786,432 numbers. Three 512 × 512 colour planes (grid lines every 32 pixels).
  2. Its latent, to scale: 16,384 numbers. The VAE's encoder maps it to 64 × 64 × 4: an eighth of the side, 4 channels, 48 times fewer numbers. This small grid is all the denoiser ever sees.
  3. The same U-Net costs hundreds of times more on pixels than on the latent. One SD 1.5 U-Net pass (batch 1, 77 text tokens) is 0.80 TFLOP on the latent and 545 TFLOP on a 512 × 512 pixel grid, 679 times as much; the columns are to scale, so the latent's is a sliver. The latent pass is counted on meta tensors; the pixel pass is the same network with 512 × 512 positions at its top level (the input convolution would take 3 channels instead of 4, a negligible change), from the counted formula, which is exact for this network.
  4. The N2 part grows fastest. The darker part of each column is the formula's N2 terms (attention scores): 15% of the latent pass, 92% of the pixel pass. Positions grow 64 times, attention entries 4,096 times.

Two parts that scale differently. Convolutions and linear layers cost in proportion to the positions N, attention scores to N2. SD 1.5's top level already compares 4,096 positions with 4,096; on pixels it would hold 262,144, an attention matrix of 6.9 × 1010 entries per head per layer. That is why pixel-space models (DDPM, ADM, Imagen's base model) worked mostly at 64 to 256 pixels and reached higher resolutions with separate upsampling models.

Predict: double the image side, 512 to 1024 pixels (four times the positions). How much more does one SD 1.5 U-Net pass cost?

The price. Latents cap quality at what the decoder can draw (small text, faces at a distance: Autoencoders and VAEs measures nine decoders), and the denoiser must be fed a latent with the statistics it was trained on, which is what the scaling factor is for (same page, section 11). Since 2023 the saved compute has gone into a bigger denoiser and deeper compression with more channels (FLUX.1 and SD3: 16 channels at f = 8; Sana's DC-AE: 32 channels at f = 32), not back to pixels.

2. The U-Net, read from Stable Diffusion 1.5's config

The problem. The denoiser takes a noisy latent and the step's noise level (the timestep) and predicts the noise (or the velocity, for a flow model) at every position. It must see fine detail (to remove noise position by position) and the whole layout (to know that the blob in the corner is a wheel). A U-Net (Ronneberger et al. 2015, arXiv:1505.04597) gets both by shrinking the grid level by level, so that a 3 × 3 convolution at the bottom covers a large part of the image, then growing it back, with skip connections that hand each level's features straight across to the matching level on the way up.

How it works, read from the config. SD 1.5's unet/config.json at the pinned revision says everything: block_out_channels [320, 640, 1280, 1280] (four levels, at 64, 32, 16 and 8 positions per side for a 512 image), down_block_types three CrossAttnDownBlock2D then one plain DownBlock2D (no attention at 8 × 8, except in the middle block), layers_per_block 2 (two ResNet blocks per level on the way down, three on the way up), cross_attention_dim 768 (the width of CLIP ViT-L's text vectors) and attention_head_dim 8, which diffusers reads as the number of heads, so heads are 40, 80 and 160 wide (unet_2d_condition.py line 249; a classic mistake, closed block at the end).

Fig. 3, step by step: one latent through SD 1.5's U-Net, every stage from its config

  1. The noisy latent in. 64 × 64 × 4 (with guidance, two copies, prompt and empty prompt, as a batch). conv_in, a 3 × 3 convolution, widens every position to 320 channels. Each glass plate stands for 160 channels; a plate's width grows with the grid side (square-root scale).
  2. Down: the grid shrinks, the channels grow. 64 × 64 × 320, 32 × 32 × 640, 16 × 16 × 1,280, 8 × 8 × 1,280. Each of the first three levels runs two ResNet blocks, each followed by a transformer block, then a stride-2 convolution halves the grid; the 8 × 8 level has two ResNet blocks, no attention and no downsampling.
  3. The middle, at 8 × 8. ResNet, a transformer block (self- and cross-attention over 64 positions), ResNet. Each 3 × 3 convolution now sees most of the image.
  4. Up, with twelve skips. Each up level runs three ResNet blocks, and each takes one of the twelve saved down-path maps concatenated as extra channels (the arcs, consumed last-saved first), then a 2 × upsample. The doubled input channels are why the up path holds most of the parameters: up_blocks.1 at 16 × 16, with three transformer blocks, is the single largest stage at 258.3M.
  5. Text enters at 16 transformer blocks. Two per level on the way down at 64, 32 and 16, one in the middle, three per level on the way up at 16, 32 and 64 (up_blocks.0 at 8 × 8 has none): each one's cross-attention reads the 77 text vectors (section 3).
  6. Parameters sit low, FLOPs sit high. Columns per stage, to scale: share of the 859.5M parameters (orange) and of the pass's 803.3 GFLOP at 512 pixels (blue). down_blocks.0 holds 1.2% of the parameters and does 13.6% of the FLOPs, up_blocks.3 2.2% and 24.6%, up_blocks.1 30.1% and 18.9%. Parameters and FLOPs per stage counted on meta tensors (src/arch/extras.py), one pass, batch 1. derived
  7. The prediction out. GroupNorm, SiLU and a 3 × 3 convolution (conv_out) back to 4 channels: the predicted noise for every one of the 16,384 latent numbers.

ResNet block (the convolutional part)

GroupNorm, SiLU, 3 × 3 convolution; then the time embedding is projected to the block's channels and added to every position (time_emb_proj); GroupNorm, SiLU, 3 × 3 convolution; plus the input (a residual). The time embedding is a 320-wide sinusoid of the timestep (line 569) through a two-layer MLP to 1,280.

Transformer block (the attention part)

Flatten the grid into a sequence; self-attention (attn1: every position looks at every other), cross-attention (attn2: every position looks at the 77 text vectors, attention.py line 1043), a GEGLU feed-forward, each with LayerNorm and a residual; reshape back to a grid. One per ResNet block at the 64, 32 and 16 levels, one in the middle.

Skip connections are concatenations, not sums: each up-block ResNet receives its input with the matching down-level features stacked on as extra channels (unet_2d_blocks.py line 2444). Twelve feature maps go across (the input convolution, two ResNets and a downsampler at each of the first three levels, two ResNets at the last), and the up path consumes three per level. That is why the up blocks hold most of the parameters: their first convolutions see twice the channels.

Predict: of SD 1.5's 859.5M U-Net parameters, which kind of layer holds the most?

The lesson of the three views: parameters sit where the grid is small and the channels many (the 16 × 16 and 8 × 8 levels hold most of them), while the FLOPs sit where the grid is large (the two 64 × 64 levels do 38% of the work with 3.4% of the weights). A parameter count says what the model can store; FLOPs per pass say what an image costs. DiT's authors measured complexity in Gflops for this reason (section 4).

Parameters sit where the grid is small; FLOPs and time sit where it is large

The cost of the design. The U-Net's convolutions build in locality and multi-scale structure, which makes it data-efficient at small scale (this page's tiny experiment in section 4 shows it) but heterogeneous: every level has its own width, block mix and attention cost, so scaling it means hand-redistributing blocks. SDXL did exactly that: "we omit the transformer block at the highest feature level, use 2 and 10 blocks at the lower levels, and remove the lowest level" (Podell et al. 2023, section 2.1), for a 2.6B U-Net (counted here: 2,567,463,684).

Check it yourself: count a U-Net without downloading it (code that ran here)

Load the U-Net (or instantiate it on the meta device), print unet.config, sum parameters by module name, and hook the top-level blocks with a device sync on each side to time them. The code below ran here; its output is pasted under it.



From src/arch/params.py (simplified: the script also classifies every parameter); CPU, no weights downloaded; diffusers 0.41.0.

3. How the text gets in: encoders, pooled vectors and cross-attention

The problem. The denoiser must draw what the prompt says, so the prompt has to reach every position of the latent at every step. Two questions: what vectors stand for the prompt (the text encoder and which of its outputs), and how the image positions read them (cross-attention, joint attention or modulation).

Fig. 4, step by step: the running example's prompt reaching the image, from SD 1.5's recorded cross-attention

  1. 77 text positions. The prompt as SD 1.5 sees it: the start token, 11 word pieces, the end token and 64 more copies of the end token's id as padding (the first padding position is drawn; the other 63 are faint).
  2. A causal encoder. CLIP's text transformer turns each position into a 768-number vector using only itself and the positions before it (the flows run left to right), so the start token's vector is the same constant for every prompt.
  3. Image positions ask. At a 16 × 16 level of the U-Net the latent's 256 positions are the queries; the 77 text vectors are the keys and values.
  4. Where the attention goes. Each position's softmax over the 77 tokens, averaged over positions, heads, layers and all 25 steps of the recorded run (columns and stream density to scale): the start token takes 91%, the 11 words 5%, the end token and padding 4%.
  5. One word's map. The weight each position gives "bicycle" at the last step, scaled to that token's maximum: it sits where the bicycle is drawn. The viewer below shows every word and step.

Step 1: tokens. SD 1.5's tokenizer (CLIP's byte-pair encoding) turns the running example's first prompt into a start token, 11 word pieces and an end token, then pads to exactly 77 positions with the end token's id (49407) again. 77 is the context length CLIP was trained with; anything longer is cut, with only a logged warning (pipeline_stable_diffusion.py line 413). A 97-token prompt, run here:


Tokens and warning from src/sd/text_enc.py (CPU, the pinned SD 1.5 tokenizer and text encoder, float32). measured

Step 2: the encoder's outputs. CLIP's text transformer is causal (each position sees only itself and earlier positions). Three consequences, each checked here on three prompts:

  • The start token's output is a constant. Position 0 sees only itself, so its 768-number output is identical for every prompt (cosine , largest difference ). It carries nothing about the prompt, yet the U-Net's cross-attention puts most of its weight there (below): a slot to attend to when no word concerns a position, the same "attention sink" seen in language models.
  • The pooled vector is the end token's output, and SD 1.5 ignores it: the whole 77 × 768 sequence goes to cross-attention, padding included.
The pooled vector and the padding, checked (depth)

CLIP's single summary vector (pooler_output) is the final-layer output at the end token (equal here to within 10−5). Padding is not empty: the positions after the end token have seen the whole prompt; their outputs stay close to the end token's (cosine 1.00 just after it, falling to at the last position). SD 1.5's U-Net applies no mask, so the image attends to them.

Step 3: cross-attention. In each transformer block of the U-Net, the latent positions form the queries and the 77 text vectors the keys and values: position i computes a softmax over the 77 tokens and takes the weighted mix of their values. The weights are a map per token: where in the image that word is being used. Recorded here while SD 1.5 generated four of the topic's images (512 × 512, 25 DPM-Solver++ steps, guidance 7.5, float16 on the laptop's GPU). Pick a prompt and a word, then move through the run in the viewer:

How the maps were recorded, and the code (provenance)

Every attn2 processor of the U-Net replaced by one that keeps the softmax output (src/sd/sd_ld.py): diffusers routes every attention layer through a processor object, so swapping the processors records every map without touching the model. The conditional half of the guided batch, mean over heads, summed per resolution; maps stored as 8-bit, each token scaled to its own maximum (the mass bars use the unscaled values). The step image is the model's prediction of the clean latent at that step, x̂0 = (xt − √(1 − ᾱt) ε̂) / √ᾱt with the guided ε̂, decoded by the VAE. The part that records the maps:


Predict: the topic's test image g06 ("an astronaut riding a horse on the moon, digital art", seed 5) shows no horse. What does the "horse" token's cross-attention map look like?

Each word's map is in place from the first steps, while the image is still a blur

SD 1.5's predicted clean image at the chosen step
The start token takes most of the attention

One word changed, same seed: the colour word's map sits on the object it colours

Left: the word's map over the model's guess of the final image at that step (x̂0, decoded by the VAE), at seven of the 25 steps. measured on Apple M1 Pro (MPS), float16

Bigger encoders and other outputs. Every later model changed what the text side hands over (encoders, widths and lengths read from the pipelines and configs, diffusers v0.41.0):

ModelSequence for attentionPooled / global vectorNote
SD 1.5CLIP ViT-L last layer, 77 × 768not usedcross-attention in the U-Net
SDXLCLIP ViT-L and OpenCLIP bigG penultimate layers concatenated, 77 × 2,048 (line 414)bigG pooled (1,280), added to the time embedding with the size and crop numbers (line 734)text encoders 817M (SDXL paper)
PixArt-Σ, SanaT5-XXL encoder (PixArt) or Gemma 2 2B (Sana), up to 300 tokensnone: time only, through one shared modulation (section 4)cross-attention in a DiT
SD3, SD3.5CLIP-L and CLIP-G (77, zero-padded to 4,096 wide) then T5-XXL (256 in diffusers, line 237; the paper's figure says 77 + 77)CLIP-L + CLIP-G pooled, 2,048, into every block's modulationjoint attention (section 5)
FLUX.1T5-XXL, 512 tokens (the diffusers default, padded)CLIP-L pooled, 768, into modulationdouble then single stream (section 6)
Qwen-Image, Z-Image, FLUX.2 [klein]a decoder language model's hidden states: Qwen2.5-VL 7B (Qwen-Image, dropping the first 34 tokens of its chat template), Qwen3 4B's second-to-last layer (Z-Image), three Qwen3 layers concatenated to 7,680 (klein)noneonly the prompt's real tokens (Qwen-Image, Z-Image) or padded to 512 (klein)

Two published results explain the trend. Imagen found that scaling the frozen text encoder improved fidelity and alignment more than scaling the image model (quoted on the parent page). SD3 trained with each of its three encoders dropped independently, which buys a choice at inference: against the full model, the version without T5-XXL (4.7B parameters) won 50% of human comparisons on aesthetics (no difference), 46% on prompt adherence and 38% on written text, i.e. T5 matters most for spelling (Esser et al. 2024, section 5.3.3; vendor, Stability AI's own raters). The same paper credits the joint text-image transformer itself (section 5) with better typography, spelling words inside the image.

A discrepancy in the SD3 paper's drop rate (checked)

The same paper gives the drop rate as 46.3% in one place and 46.4% in another; 0.4643 = 0.0999, so 46.4% is the value that makes "roughly an unconditional model in 10% of all steps" true. derived

The cost. The encoder runs once per prompt (twice with guidance, for the empty prompt), a small share of compute next to 25 to 50 denoiser steps even at 7B, but a large share of memory: why SD3 made T5 droppable and FLUX.2 [klein] uses a 4B encoder. Inside the denoiser, cross-attention costs N × T per layer and joint attention (N + T)2 (section 9).

4. The diffusion transformer (DiT): patches, adaLN-Zero, and scaling with compute

The problem. The U-Net is a hand-built stack of different blocks; a transformer is one block repeated, with well-understood scaling and years of systems work behind it. Peebles and Xie asked whether a plain transformer can replace the U-Net inside latent diffusion, and what to scale (Scalable Diffusion Models with Transformers, Dec 2022).

How it works. Four pieces, drawn on DiT-XL/2's 512 model in Fig. 5: patchify, positions, N identical blocks, unpatchify.

Fig. 5, step by step: one latent through DiT-XL/2, from the authors' code at 512 pixels

  1. The same latent. 64 × 64 × 4, the latent of a 512 × 512 image, as in Fig. 3.
  2. Patchify, and positions. Cut the I × I × C latent into p × p patches and embed each linearly (a convolution with kernel and stride p): T = (I / p)2 tokens of width d. Here p = 2: 1,024 tokens of 1,152 (at 256 × 256 the latent is 32 × 32 × 4, so p = 2 gives 256 tokens). Add a fixed 2-D sine-cosine embedding (as in ViT and MAE): the tokens carry where they came from (section 7).
  3. The condition is one vector. The timestep and class embeddings are summed into c, and each block's modulation layer turns c into six vectors of 1,152: a shift, a scale and a gate for attention, and the same for the MLP (adaLN-Zero, below).
  4. One block. LayerNorm, shift and scale, attention over all 1,024 tokens, times the gate, added back; then the same around the MLP. The gates start at zero, so the block starts as the identity.
  5. N identical DiT blocks with adaLN-Zero conditioning (below). 28 here, each 23.9M parameters and 37.5 GFLOP at 512 pixels (counted): no levels and no skips, the token count and width never change, so scaling means more blocks, wider blocks or smaller patches. Attention scores over 1,024 tokens are about an eighth of each block's FLOPs.
  6. Unpatchify. A final adaptive LayerNorm and a linear layer map each token back to p × p × 2C numbers (the noise and, for DiT, a learned variance), reshaped into the latent grid: 64 × 64 × 8 (models.py line 218).

adaLN-Zero. The timestep and class embeddings are summed into one vector c. Each block feeds c through SiLU and one linear layer to 6d numbers: a shift and scale for the LayerNorm before attention and before the MLP (adaptive LayerNorm, the same trick as FiLM and StyleGAN), and a gate that multiplies each branch before its residual add. That linear layer is initialised to zero, so every gate starts at 0 and every block starts as the identity. The authors' code, as it ran here for counting (models.py lines 119 to 121 and 207):

def forward(self, x, c):
    shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = self.adaLN_modulation(c).chunk(6, dim=1)
    x = x + gate_msa.unsqueeze(1) * self.attn(modulate(self.norm1(x), shift_msa, scale_msa))
    x = x + gate_mlp.unsqueeze(1) * self.mlp(modulate(self.norm2(x), shift_mlp, scale_mlp))
    return x
...
# Zero-out adaLN modulation layers in DiT blocks:
for block in self.blocks:
    nn.init.constant_(block.adaLN_modulation[-1].weight, 0)
    nn.init.constant_(block.adaLN_modulation[-1].bias, 0)

modulate(x, shift, scale) is x * (1 + scale) + shift (line 19). facebookresearch/DiT at ed81ce2.

DiT architecture figure from the paper: on the left, a noised 32 by 32 by 4 latent is patchified, embedded with the timestep and label, passed through N DiT blocks, a layer norm and a linear-and-reshape layer to give noise and covariance; on the right, three block designs: adaLN-Zero with scale, shift and gate parameters regressed from the conditioning, cross-attention, and in-context conditioning
Notice the arrows coming in from the right of the adaLN-Zero block: the conditioning never enters as tokens; an MLP turns it into γ, β (scale and shift for each LayerNorm) and α (the gate before each residual add). The two greyed blocks are the alternatives the paper tested and rejected (results below). Tap to open full size. Figure 3 of Peebles and Xie, arXiv:2212.09748, CC BY 4.0.

adaLN-Zero beat the other three ways of bringing in the condition

Table 4 of the paper: each a DiT-XL/2 trained 400K steps, FID-50K without guidance, lower is better (published, the authors' runs). In-context: c appended as two extra tokens. Cross-attention: an extra cross-attention layer reading c, "roughly a 15% overhead" in Gflops. adaLN: regress shift and scale only (4d outputs), no gates. adaLN-Zero: shift, scale and zero-initialised gates (6d). Parameters from the same table.

Scaling: what to grow. DiT's central result: across 12 models (four widths and depths times three patch sizes), FID after 400K steps follows the forward-pass compute, not the parameter count. Shrinking the patch from 8 to 2 leaves the parameters almost unchanged and multiplies the tokens, and so the compute, by 16.

Predict: DiT-XL with 4 × 4 patches has 675M parameters, 29.05 Gflops and FID 43.01. Halve the patch to 2 × 2. What happens to parameters, compute and FID?
Two more DiT results to read critically (depth)

Sampling compute does not buy back model compute: DiT-L/2 with 1,000 sampling steps (80.7 Tflops per image) scored FID-10K 25.9, DiT-XL/2 with 128 steps (15.2 Tflops) 23.7. The headline FID 2.27 used guidance on three of the four latent channels only, a detail in the appendix; four-channel guidance at scale 1.375 gave 2.20, so the choice did not flatter the result, but a reimplementation that guides all channels at 1.5 is not the published configuration.

DiT's 12 models: FID falls with compute per pass, whatever the size of the model

At toy scale the U-Net wins. Trained here with the topic's flow-matching recipe on Fashion-MNIST, a 4.1M-parameter DiT given the same training compute as the 1.0M-parameter U-Net scored a Fréchet distance of 38.1 against the U-Net's 23.75 (lower is better, guidance 1.5): convolutions build in locality a small transformer must learn. DiT wins by how it scales with compute, not by data efficiency. Smaller patches helped at equal steps (2 × 2 beat 4 × 4 beat 8 × 8, as in DiT's Figure 8), and zero-initialised gates beat the default initialisation. measured on Apple M1 Pro (MPS), one seed

The tiny DiT against the tiny U-Net: setup, every run, the same noise through each (measured here)

The shared TinyDiT (4 × 4 patches of the 32 × 32 Fashion-MNIST image, 64 tokens, width 192, 6 blocks, adaLN-Zero exactly as above: 4,127,632 parameters) trained with the flow-matching recipe of the topic's flow runs (root src/flow) unchanged (batch 128, AdamW 5 × 10−4, 200 warm-up steps, EMA 0.999, 10% label dropout, seed 0), against those runs' TinyUNet (1,040,353 parameters, 4,000 steps). Scored as those runs score: 1,000 samples (100 per class) from the same noise, 50 Euler steps, Fréchet distance in the topic's Fashion-MNIST classifier's feature space (FD; lower is better; 1,000 real images score ) and the classifier's accuracy on the requested class.

DenoiserParametersTokensFLOPs per passStepsTraining computeFD, s = 1FD, s = 1.5Accuracy, s = 1.5

FLOPs per pass counted with FlopCounterMode (batch 1), the DiT's attention scores added by formula because the counter does not see nn.MultiheadAttention's fused path (src/tiny/flops.py). Training compute = 3 × FLOPs per pass × 128 × steps (DiT's own estimate of forward plus backward). s: guidance scale in diffusers' convention. measured on Apple M1 Pro (MPS), float32, one seed

Cheaper modulation: adaLN-single, and attention without N2

adaLN-Zero has a price the paper's Gflops hide: each block's modulation layer is d × 6d, a third of the block (attention 4d2, MLP 8d2, modulation 6d2). Counted here, DiT-XL/2's modulation layers hold 225.8M of its 675.1M parameters (33.4%). PixArt-α found the same, "a substantial proportion (27%) of the parameters" in its text-conditioned DiT, and replaced them with adaLN-single: one MLP computes the six vectors from the timestep once, shared by all blocks, plus a small learned per-block offset (Chen et al. 2023). Sana (section 1's 32 × DC-AE) went further and replaced softmax attention by ReLU linear attention (attention_processor.py line 5371), so its cost grows linearly with tokens: counted here, attention scores are 2% of Sana's FLOPs at 1024 pixels, against 15 to 37% for the softmax transformers on this page.

PixArt's 27% and DiT's 33% agree (checked)

225.8M of modulation over DiT-XL/2 plus PixArt's 148.8M of cross-attention is 27.4%, and the paper's 833M to 611M (−26%) matches the 610,856,096 counted here for PixArt-Σ. derived

5. MMDiT: text and image in one attention

The problem. In cross-attention the text is read but never changes: the 77 vectors are the same in every layer, so the text cannot adapt to what the image has become. DiT's class conditioning through adaLN carries only one vector, too little for a sentence. Stable Diffusion 3 wanted the text processed alongside the image (Esser et al., Mar 2024).

How it works. Concatenate the text tokens and the image tokens into one sequence and run one attention over all of it, but give each modality its own weights: "two separate sets of weights for the two modalities ... equivalent to having two independent transformers for each modality, but joining the sequences of the two modalities for the attention operation" (section 4). Each block has, for image and for text separately, the Q, K, V and output projections, the MLP and the adaLN modulation (driven by the timestep and the pooled text vector); only the softmax is shared. In diffusers the join is one line (attention_processor.py line 1480): query = torch.cat([query, encoder_hidden_states_query_proj], dim=2), the same for keys and values, then split again after attention.

Fig. 6, step by step: one SD3.5 Large block at 1024 pixels (a few tokens of each kind drawn)

  1. Two sequences. Image: 4,096 patch tokens (a 1024 × 1024 image is a 128 × 128 × 16 latent, cut into 2 × 2 patches). Text: 333 tokens, 77 from CLIP-L and CLIP-G and 256 from T5-XXL (diffusers' default).
  2. Each with its own weights. Image tokens go through the image stream's Q, K and V projections, text tokens through the text stream's: two independent sets in every block, each with its own modulation from the timestep and the pooled text vector.
  3. One attention over both. The two streams' queries, keys and values are concatenated, so every image token attends to every text token and the reverse: one softmax over 4,429 tokens. The text is rewritten by the image, block after block.
  4. Split again. The outputs go back to their own streams, each with its own output projection and MLP.
  5. 38 such blocks. SD3.5 Large stacks 38 (hidden width 64 × 38 = 2,432), 8,056.6M parameters counted from the config.

What it bought, by the paper's own comparison. On CC12M at matched settings, "Our MM-DiT variant significantly outperforms the cross-attention and vanilla variants" (DiT with concatenated text, CrossDiT with cross-attention, and UViT), on validation loss, CLIP score and FID (section 5.2.3, Figure 4; vendor, the authors' runs). QK-normalisation came with it: at scale, attention logits grew until the attention entropy collapsed in the last blocks; RMSNorm on Q and K in both streams prevented it and "enables efficient training at bf16-mixed precision" (section 5.3.2, "QK-Normalization"). Modulation is a third of the model: each stream has its own d × 6d modulation per block, so counted here SD3.5 Large's modulation layers hold 2,686.3M of 8,056.6M parameters (33.3%) and Qwen-Image's (60 MMDiT blocks) 6,815.9M of 20,430.4M (33.4%).

The cost. Joint attention costs (N + T)2 per layer and the text stream's weights run on every text token, so text length is no longer nearly free: SD3.5 Large at 1024 pixels costs 28.95 TFLOP per pass with 77 text tokens and 31.12 with diffusers' 333 (a 7.5% difference, counted).

Who attends to whom: only cross-attention leaves the text unchanged

A finding from counting: the position table the Hub counts and diffusers does not (checked)

SD3 Medium's config instantiated here has 2,028,328,000 parameters; the Hub's public total for the repo is 2,084,951,104. The difference, 56,623,104, is exactly 192 × 192 × 1,536: the 2-D position table for a 192 × 192 patch grid. Diffusers registers it as a buffer that is saved with the weights (embeddings.py line 331: persistent = True if pos_embed_max_size else False), not as a parameter. SD3.5 Large: 8,146,280,768 on the Hub against 8,056,627,520 here, a gap of 89,653,248 = 192 × 192 × 2,432. With the table, both configs reproduce the Hub totals exactly. derived Parameter counts in model cards can include such tables; check before comparing.

6. FLUX-style double and single stream blocks

The problem. Two full weight sets per block double the parameters per unit of depth. Once text and image have been mixed for a while, do they still need separate weights?

How it works. FLUX.1 (Black Forest Labs, August 2024; no paper, but the FLUX.1 Kontext report describes it) : "Double stream blocks employ separate weights for image and text tokens ... we concatenate them and apply 38 single stream blocks to the image and text tokens. Finally, we discard the text tokens and decode the image tokens" (Labs et al. 2025, section 2). The released code has 19 double blocks and 38 single blocks (BFL flux util.py: depth 19, depth_single_blocks 38, hidden size 3,072, 24 heads). A single-stream block is a parallel transformer block (as in ViT-22B): one LayerNorm and one modulation, then attention and the MLP computed side by side from the same input, their outputs concatenated and projected once (transformer_flux.py line 404), which halves the modulation parameters and makes larger matrix multiplications.

Fig. 7, step by step: FLUX.1 [dev] at 1024 pixels, double then single stream

  1. 19 double-stream blocks. 4,096 image tokens and 512 T5 text tokens keep separate weights and meet in one attention, as in Fig. 6: 6,456.8M parameters in all, about 340M a block.
  2. One sequence. After the 19th block the two streams are concatenated into one sequence of 4,608 tokens.
  3. A parallel block. One LayerNorm and one modulation, then attention and the MLP side by side from the same input, their outputs concatenated and projected once.
  4. 38 single-stream blocks. One set of weights for every token: 5,380.5M parameters in all, about 142M a block, less than half a double block.
  5. Discard the text. The text tokens are dropped and the image tokens decoded into the prediction for the latent.

Three things the counts show. (1) Guidance distillation is visible in the weights. FLUX.1 [dev] counted here is 11,901,408,320 and [schnell] 11,891,178,560, both equal to the Hub's public totals; the difference, 10,229,760, is the guidance embedder: [dev] was distilled to take the guidance scale as an input (embedded like the timestep), so it runs one denoiser pass per step where classifier-free guidance runs two (section 10). (2) Single blocks are half-size: FLUX.1's 38 single blocks hold less than its 19 double blocks (Fig. 7). (3) Modulation keeps shrinking: 27.3% of FLUX.1, then FLUX.2 [klein] 4B shares one modulation per stream across all its blocks (5 double, 20 single): 160.4M, 4.1% of 3,875,544,576 (equal to the Hub total). Z-Image runs a single stream from the start (two refiner layers each for noise and caption, then 30 joint layers) with a low-rank modulation: 2.1% of 6,154,908,736.

Predict: FLUX.1 [dev] at 28 steps against SD3.5 Large at 28 steps with guidance 7.0, both at 1024 pixels. FLUX.1 has 1.5 times the parameters. Which costs more per image?

Where the parameters go in eleven denoisers: modulation shrinks from a third to a few per cent

Shares of each model's parameters by kind of layer, counted on the meta device from the configs (attention and MLP split by stream; modulation = every adaLN, adaLN-single, time-injection or shared modulation layer). derived The Architecture explorer shows the numbers and the block structure.

7. Positions for image tokens: tables, crops and 2-D RoPE

The problem. Attention is blind to order: shuffle the tokens and the outputs shuffle with them. An image transformer must be told where each patch sits, in two dimensions, ideally in a way that still works at a resolution or aspect ratio it was not trained at. Three answers are in use:

  • A fixed 2-D sine-cosine table (DiT, PixArt): half the channels encode the row, half the column, at geometric frequencies. It is computed for one grid; the DiT code builds it at construction for one input size, which is why this page's FLOP counter had to rebuild DiT-XL/2 for every resolution.
  • A large table, center-cropped (SD3): one table for a 192 × 192 patch grid, cropped to the image's grid at run time (embeddings.py line 336), so any size up to 192 × 2 × 8 = 3,072 pixels per side has positions. For mixed aspect ratios the paper builds "a combination of extended and interpolated position grids" and center-crops them (section 5.3.2).
  • Rotary embeddings in 2-D or 3-D (FLUX, Qwen-Image, Z-Image, FLUX.2): rotate each query and key by angles proportional to the token's position, so their dot product depends only on the offset between two tokens. FLUX splits each 128-wide head into 16 channels for a third axis (time or reference image), 56 for the row and 56 for the column (axes_dim [16, 56, 56]); image token ids are (0, row, column) (pipeline_flux.py line 508) and the text tokens' ids are all zero, so text sits at "no position" and is told apart by its own weights. Qwen-Image's MSRoPE instead places the text "along the diagonal of the image" grid (Qwen-Image report, section 2.4). Z-Image uses 32/48/48 channels; FLUX.2 four axes of 32. There is no table to outgrow, which helps with new sizes but does not by itself make the model good at them (section 8).

RoPE itself (why rotating q and k makes attention depend on relative position, and how frequencies are chosen) is on Positional Encodings and the RoFormer paper page; here only the 2-D and 3-D split is new.

Fig. 8, step by step: FLUX's rotary positions on a small packed latent (3 × 4 image tokens, 3 text tokens drawn)

  1. Ids (0, row, column). Each image token gets a three-number id: the time or reference-image axis, then the row and column of its packed latent position. A 1024 × 1024 image is a 128 × 128 latent packed to 64 × 64 = 4,096 tokens.
  2. Rotate by row. 56 of each head's 128 channels are rotated, pair by pair, by angles proportional to the token's row (one channel pair drawn, at an illustrative frequency).
  3. Rotate by column. Another 56 channels turn with the column; the last 16 with the time axis, 0 for every token of a plain text-to-image call.
  4. Text sits at no position. The text ids are all zero (pipeline line 387: torch.zeros(prompt_embeds.shape[1], 3)), so rotary embedding leaves text unrotated; it is told apart by its own weights.
  5. Only offsets count. Rotating both q and k makes the score between two image tokens depend on their row and column offsets only: the two pairs drawn have the same offset, so they score alike wherever they sit. The bar in front is one 128-wide head split by axis: 16 time, 56 row, 56 column (axes_dims_rope).

8. Resolution and aspect ratio

The problem. A denoiser learns the statistics of the latent grids it was trained on: their size, their shape, and how much of a subject one position covers. SD 1.5 was fine-tuned at 512 × 512 (its model card: 595k steps at that size). Ask it for another size and nothing in the code stops you: the U-Net is convolutional and its attention takes any number of positions.

What the four sizes show. At 512, the training size, one puppy fills the frame. At 768 (2.25 times the area) one puppy still holds together, with more background. At 1024 (four times the area) the model draws four puppies: each region of the 128 × 128 latent is denoised with the statistics of a 64 × 64 training image, so the canvas fills with several subjects of the usual size; the U-Net's attention reaches the whole grid, but nothing in its training taught it what one large subject looks like at this scale. At 256 the puppy is cropped at the edge and its proportions are off: too few positions for the layout it learned. The same seed and settings throughout; no sampler change fixes this.

One prompt, one seed, four sizes: at four times the training area SD 1.5 draws four puppies

How production models handle it.

  • Train at the sizes you will sample. SDXL pretrained at 256 × 256, then 512, then fine-tuned on "different aspect ratios ... of ~1024 × 1024 pixel area" (Podell et al. 2023, section 2.5).
  • Aspect-ratio bucketing (from NovelAI's 2022 work, which SDXL and SD3 cite): sort the training images into buckets of similar shape, keep the pixel count as close to 10242 as the shape allows, with height and width in multiples of 64, and build each batch from one bucket (SDXL section 2.3, which also feeds the bucket's size to the model as a condition). For a transformer, equal area means a similar number of tokens, so the cost per batch stays level.
  • Tell the model what it is looking at. SDXL's micro-conditioning adds the original size, crop offsets and target size to the time embedding as Fourier features (pipeline line 734). The size condition kept the 39% of pretraining data smaller than 256 pixels that would otherwise be discarded; the crop condition targets SD 1.5's cut-off heads, which the paper blames on random crops: sampling at (0, 0) asks for an uncropped image, other values "simulate the amount of cropping" (section 2.2, Figures 4 and 5; vendor).
  • Shift the noise schedule with resolution. More pixels carry more redundant signal, so the same noise level destroys less of the image; SD3 shifts its timesteps by a factor of √(m / n) (m pixels at the new resolution, n at the base) and FLUX computes the shift from the image's token count (pipeline_flux.py line 73). Flow matching, section 11, owns the details.

9. What one image costs

The formula. One image = text encoder once (twice with guidance and a negative or empty prompt) + steps × passes per step × FLOPs per pass + one VAE decode. Passes per step is 2 with classifier-free guidance (the conditional and the unconditional prediction, batched together) and 1 for a guidance-distilled model (FLUX.1 [dev]) or a model sampled without guidance (FLUX.1 [schnell], Z-Image-Turbo). FLOPs per pass grow with the image tokens N (linear layers, convolutions) and with N2 (attention), so at high resolution attention takes over: counted here, attention scores are of SD 1.5's FLOPs at 512 pixels and at 2,048. A video clip multiplies the image tokens by its frames, so the N2 term grows with the square of the duration: the clip-length slider of Video and audio generation, section 4 ("Duration is the expensive axis"), shows it overtaking everything else.

One 1024 × 1024 image with each pipeline's default settings: steps × passes moves the total as much as model size

PipelineTokens (image + text)FLOPs per passSteps × passesDenoiser FLOPs per image

Steps and guidance from each pipeline's __call__ defaults in diffusers 0.41.0, except where the model card recommends otherwise (FLUX.1 [schnell] "1 to 4 steps": 4; FLUX.2 [klein] 4B card: 4 steps, guidance 1.0; Z-Image-Turbo card: 9 steps, "8 DiT forwards", guidance 0). SD 1.5 and DiT-XL/2 were trained at 512 and 256 and are included for scale. Text encoders and the VAE decode are not included. derived Try other sizes and settings in the Tokens and FLOPs calculator.

Measured here. One SD 1.5 U-Net pass on the laptop's GPU (float16, attention slicing, batch 1) at six sizes, against the counted FLOPs:

Where the time goes inside one pass (the same guided pass as the root diffusion runs' 0.610 s, hooked per kind of layer): The parameter view of section 2 would have predicted none of this. Seconds do not transfer to a datacenter GPU with a fused attention kernel; the FLOP shares do (closed block "What transfers", below).

Predict: you must halve the cost of SD3.5 Large images at 1024 pixels without retraining. Which change saves the most?

Time per pass grows faster than FLOPs: the laptop runs large attention less efficiently

10. Few steps: distillation

The problem. The cost formula's biggest lever is passes per image: 50 for SD 1.5 at the topic's settings, 100 for SDXL at its pipeline default, against one decode. Better solvers bring 1,000 steps down to 10 to 25 (Diffusion from zero, section 5), but no solver follows a curved path in one or two straight steps. Below about 8 steps you need a second model trained to jump: distillation, where a student learns to do in a few passes what the teacher (the original model plus its sampler) does in many. A student removes one of two things.

  • Remove the second pass per step: guidance distillation. Train a student that takes the guidance scale w as an input and outputs the guided prediction in one call (Meng et al. 2022). FLUX.1 [dev] is such a model ("Trained using guidance distillation", its model card), and it shows in the weights: the 10,229,760-parameter guidance embedder of section 6. Halves the cost at the same steps; negative prompts lose their slot, since there is no unconditional pass to replace.
  • Remove steps: four families of students.
    • Progressive distillation (Salimans and Ho 2022): a student does in one step what the teacher does in two; repeat, halving each round.
    • Consistency distillation (Song et al. 2023): train a map from any point on the sampling path straight to its end. Latent consistency models do it in SD's latent with guidance baked in (Luo et al. 2023); LCM-LoRA packs the result into a 67.5M-parameter LoRA that plugs into an unchanged SD 1.5 (Luo et al. 2023).
    • Adversarial distillation: add a GAN loss so one or two steps give sharp images. ADD (Sauer et al. 2023, SDXL-Turbo) judges decoded pixels with a frozen DINOv2 discriminator; LADD (Sauer et al. 2024) judges in the latent, with generative features of a pretrained latent diffusion model instead of a pixel-space discriminator, which enables "high-resolution multi-aspect ratio image synthesis": SD3-Turbo, and FLUX.1 [schnell] ("Trained using latent adversarial diffusion distillation", its card).
    • Distribution matching (DMD, Yin et al. 2023; DMD2, 2024): match the student's output distribution to the teacher's, using two score models.

Distilled students cut passes per image 7 to 100 times; FLOPs per pass stay the same

One square is one denoiser pass; blue conditional, orange the unconditional passes guidance adds. Teachers at the topic's settings (SD 1.5) or the diffusers pipeline defaults. Students: LCM-LoRA 4 steps, guidance off (measured on Diffusion from zero, section 7); SDXL-Turbo 1 step, guidance_scale=0.0 (card: "1 to 4 steps"); SD3-Turbo "four unguided sampling steps" (LADD); FLUX.1 [schnell] 4 steps (card: "1 to 4 steps"). [dev] and [schnell] share one 11.9B transformer, 74.38 TFLOP per pass at 1024: 28 passes are 2,083 TFLOP, 4 are 298. derived

What it costs. A student is a new model: training it takes compute and data (LCM about 32 A100 GPU hours), it is tied to its teacher's weights, and the few-step regime has its own failures. Measured on SD 1.5 by Diffusion from zero (section 7): "LCM-LoRA is sharp at 1 to 4 steps but drops the lighthouse; DPM-Solver++ needs 4 steps to keep it". Flow-based shortcuts (rectified flow, reflow, one-step distillation of a flow) are on Flow matching, sections 8 and 9.

Seven distillation methods: idea, steps and published result (reference)
Method (first version)IdeaStepsPublished result
Progressive distillation (Salimans and Ho, Feb 2022)Halve the steps repeatedly: a student does in one step what the teacher does in two; v-prediction introduced for it1 to 8CIFAR-10 FID 9.12 / 4.51 / 3.00 / 2.57 at 1 / 2 / 4 / 8 steps (Table 2)
Guidance distillation (Meng et al., Oct 2022)First teach a student, conditioned on the scale w, to output the guided prediction in one call; then distil steps1 to 41 to 4 steps on ImageNet 256 and LAION 512, "at least 10-fold" faster (abstract; the Figure 1 caption says at least 20x fewer steps)
Consistency models (Song et al., Mar 2023)Train a map from any point on the ODE path straight to its end (distilled from a teacher, CD, or trained alone, CT)1 or 2CD: CIFAR-10 FID 3.55 / 2.93, ImageNet 64 6.20 / 4.70 at 1 / 2 steps; CT: 8.70 / 5.83 and 13.0 / 11.1
Latent consistency models (Luo et al., Oct 2023)Consistency distillation in SD's latent space, guidance baked in (w = 8 in the tables)1 to 8LAION-Aesthetics 6+ at 512 px, FID 35.36 / 13.31 / 11.10 / 11.84 at 1 / 2 / 4 / 8 steps against DDIM's 183.29 / 81.05 / 22.38 / 13.83 (Table 1); about 32 A100 GPU hours
LCM-LoRA (Luo et al., Nov 2023)The same distillation as a LoRA on an unchanged base model2 to 867.5M trainable parameters on SD 1.5's 0.98B; run on Diffusion from zero
Adversarial diffusion distillation (Sauer et al., Nov 2023)Distillation loss plus a GAN discriminator on frozen DINOv2 ViT-S features; the SD-Turbo (from SD 2.1) and SDXL-Turbo model cards name it as their training method1 to 4ADD-M (SD 1.5 backbone) at 1 step: COCO FID-5k 19.7, CLIP 0.326, 0.09 s, against DPM-Solver at 25 steps 20.1 (Table 2); human raters prefer ADD-XL at 4 steps over SDXL at 50 steps
Distribution matching distillation (Yin et al., Nov 2023; DMD2 May 2024)Match the student's output distribution to the teacher's using two score models1 to 4ImageNet 64 one-step FID 2.62 (DMD), 1.28 (DMD2, longer training; teacher EDM 2.32 deterministic); SDXL-based DMD2 4 steps COCO-10k FID 19.32 against the 100-call teacher's 19.36

Every row is published (the papers' own numbers, vendor-reported, on the datasets named), as compiled and checked on Diffusion from zero on 2026-10-17. Later, latent-specific: LADD (Sauer et al., Mar 2024) replaces ADD's pixel-space DINOv2 discriminator with the teacher's latent features (SD3-Turbo, four unguided steps; FLUX.1 [schnell] per its card).

Depth: mistakes, rehearsal, what transfers

Common mistakes, each from a real run or a real config (9)

Reading attention_head_dim in an SD 1.x or 2.x config as the head width. In UNet2DConditionModel configs it is the number of heads (SD 1.5: 8 heads of width 40, 80 and 160; SDXL's [5, 10, 20]: heads of width 64). diffusers keeps the old name for "40,000+ configurations" and maps it at unet_2d_condition.py line 254. Transformer configs (SD3Transformer2DModel, FluxTransformer2DModel) mean what they say: 64 and 128.

Writing prompts longer than 77 tokens for a CLIP-conditioned model. Everything past position 77 is dropped, with only a logged warning (the real one is in section 3). SD 1.5 and SDXL never see the end of a long prompt; SD3 sees it through T5 only. Fixes: shorten, put what matters first, or use a long-prompt helper that encodes chunks of 75 and concatenates them (the model then sees several start and end tokens, which it was not trained on). A T5- or LLM-conditioned model accepts 256 to 512 tokens.

Sampling far from the training resolution. SD 1.5 at 1024 pixels (section 8) is a real run on this page: asked for one puppy on a canvas four times its training area, it drew four puppies of the usual size. It is not a bug in the sampler; it is the denoiser's learned statistics. Use a model trained near the target size and aspect ratio (bucketing), or generate at the native size and upscale (a second img2img pass at the high resolution is the common recipe).

Comparing models by parameter count when the question is cost. DiT-XL/8 and DiT-XL/2 have the same 675M parameters and differ 16 times in compute and 5 times in FID. FLUX.1 [dev] has 1.5 times SD3.5 Large's parameters but costs about 1.2 times as much per image because it needs one pass per step instead of two. Count FLOPs per pass, multiply by steps and passes (section 9).

Trusting a parameter count without knowing what was counted. Three cases found while counting for this page: SD3's checkpoints include a 192 × 192 position table that diffusers holds as a buffer (56.6M numbers for SD3 Medium, 89.7M for SD3.5 Large, section 5); diffusers' port of DiT-XL/2 has 749,826,464 parameters against the authors' 675,129,632, because its conversion script copies the timestep and class embedders into every one of the 28 blocks (convert_dit_to_diffusers.py line 34), 27 extra copies of 2,777,472 parameters, and holds the position table as a buffer where the authors' code has a frozen parameter (256 × 1,152 = 294,912 at 256 pixels): 27 × 2,777,472 − 294,912 = 74,696,832, the whole gap; and model cards round ("12 billion" for 11.9B). State what a number includes.

Running classifier-free guidance on a guidance-distilled model. FLUX.1 [dev]'s guidance_scale is an input to the network (an embedding, default 3.5), not the CFG weight; the diffusers pipeline runs one pass per step unless true_cfg_scale is set above its default 1.0 with a negative prompt, which doubles the cost and was not what the model was distilled for. [schnell] has no guidance embedder at all (10,229,760 fewer parameters, section 6).

Feeding a model text features from the wrong layer. SD 1.5 was trained on CLIP's last layer, SDXL on the penultimate layers of two encoders (line 414), Z-Image on Qwen3's second-to-last layer. The two layers differ: measured here on SD 1.5's encoder, the cosine between the last and penultimate layer's output is across the prompt's positions. "Clip skip" settings in user interfaces swap these; on a model trained with one, the other shifts every cross-attention input.

Running a DiT at a size its position table was not built for. The authors' DiT code builds its sine-cosine table for one latent size; giving it another fails in the patch embedding before attention is reached. The real error, from counting DiT-XL/2 at 1024 pixels on this page before rebuilding the model per size:
AssertionError: Input height (128) doesn't match model (32).
Rebuild (or interpolate) the table for the new grid; RoPE models (section 7) have no table to rebuild, but still need training at the new size.

Expecting a small transformer to beat a U-Net on a small budget. The tiny experiment in section 4: at equal training compute the topic's 1M-parameter U-Net beat a 4M-parameter DiT by a wide margin. DiT's advantage is in how it scales with compute and how well it fits modern hardware and systems, not in data efficiency at toy scale.

Interview rehearsal (optional, 9 questions)

Why do most image generators run diffusion in a VAE latent instead of on pixels? A denoiser runs 20 to 50 times per image, so its cost per pass dominates. An f = 8 VAE cuts positions 64 times (48 times fewer numbers for SD's 4 channels), and attention cost falls with the square: counted here, SD 1.5's U-Net would cost about 680 times more per pass on a 512 × 512 pixel grid. The price is a quality ceiling set by the decoder and the need to normalise the latent (scaling factor).

Where are a U-Net's parameters, and where are its FLOPs? Parameters at the low-resolution, high-channel levels (weights grow with channels squared); FLOPs at the high-resolution levels (cost grows with positions). For SD 1.5 at 512: the two 64 × 64 stages do 38% of the FLOPs with 3.4% of the weights, while up_blocks.1 (16 × 16) holds 258M parameters.

What is adaLN-Zero and why initialise it at zero? The conditioning vector (timestep plus class or pooled text) is mapped per block to a shift and scale for each LayerNorm and a gate on each residual branch. Zero-initialising that mapping makes every block the identity at the start, so a deep stack trains stably from a well-behaved function; in DiT's ablation it beat plain adaLN (FID 19.5 vs 25.2), cross-attention (26.1) and in-context tokens (35.2). Its cost: the modulation layer is about a third of each block's parameters, which PixArt cut with adaLN-single and FLUX.2 with shared modulation.

Cross-attention or joint attention (MMDiT) for text: what are the trade-offs? Cross-attention: text is read-only, cost N × T per layer, a cheap way to add text to any backbone. Joint attention: one softmax over image and text, so text tokens are updated by the image and both modalities interact symmetrically; cost (N + T)2 and a second set of weights per block (or shared weights in single-stream blocks). SD3 found MMDiT better than cross-attention DiT and UViT at matched settings; nearly every 2025 to 2026 open model uses joint attention.

Why did the DiT paper report Gflops rather than parameters? Because quality tracked compute per forward pass, not parameters: shrinking the patch size quadruples tokens and Gflops without changing the weights, and FID improved accordingly. Their "Gflops" are multiply-accumulates (counted here at exactly half the FLOPs).

FLUX.1 [dev] against [schnell]: what differs in the weights and in the cost? [dev] has a guidance embedder (10.2M parameters) because it was distilled to take the guidance scale as an input: one pass per step, default 28 steps. [schnell] was distilled further (latent adversarial diffusion distillation, per its card) to 1 to 4 steps without guidance. Same transformer otherwise: 19 double and 38 single-stream blocks.

How would you support many aspect ratios and resolutions? Bucketed training at roughly constant area (similar token counts per batch), size and crop conditioning or their equivalent, position encodings that extend (RoPE or a large cropped table), a resolution-dependent timestep shift, and progressive training from low to high resolution. Check by sampling at every bucket and at an unseen size.

Design question: a text-to-image service must return 1024 × 1024 images in about a second on one datacenter GPU. Sketch the model and the arithmetic. Work backwards from compute. If the GPU sustains S TFLOP/s on the denoiser, one second buys S TFLOP. A FLUX.1-sized model costs 74 TFLOP per pass at 1024 (counted), so even 4 passes need 300 TFLOP: plausible only with a few-step distilled model and a fast kernel. Levers in order of size: (1) steps and passes: a distilled few-step model (adversarial or consistency distillation) with guidance distilled in, 1 pass per step; (2) tokens: a deeper-compression VAE (f = 16 or 32 with more channels, as in Sana's DC-AE) cuts tokens 4 to 16 times; (3) attention cost: linear or windowed attention at high resolution; (4) model size: a 2 to 5B denoiser rather than 12B; (5) text encoder: a 2 to 4B LLM or T5, run once and cached for repeated prompts. Then measure: the calculator gives FLOPs, but kernel efficiency decides the seconds. Keep a quality check (a preference or VQA-based metric) in the loop, since every lever trades quality.

Why does SD 1.5's cross-attention put so much weight on the start token? CLIP's text encoder is causal, so the start token's output is the same constant for every prompt. Softmax attention has to put its weight somewhere; a position whose content no word concerns puts it on that constant slot, which acts as a no-op (an attention sink). Measured here: about of the 16 × 16 layers' cross-attention for the bicycle prompt.

What transfers from this laptop, and what does not (provenance)

Measured on Apple M1 Pro: SD 1.5 in float16 with attention slicing on the laptop's GPU (MPS), one process, peak memory ; the tiny models in float32 for 4 to 32 minutes each; all parameter and FLOP counts on CPU without weights. What transfers exactly: parameter counts, FLOPs per pass and their breakdowns (shape arithmetic, identical on any device), the cross-attention patterns up to float16 rounding, and the token counts behind every cost. What transfers in direction only: the tiny results (U-Net ahead of DiT at small compute, smaller patches better at equal steps; one seed each, a 28 × 28 dataset, a classifier-space FD). What does not transfer: seconds. MPS with attention slicing runs attention far less efficiently than a datacenter GPU with a fused attention kernel (FlashAttention), so the share of time spent in attention, the achieved TFLOP/s and the relative cost of the large-resolution passes all change; the FLOP shares on this page are the device-independent part.