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
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.
| Design | Example | How the image is held | How text gets in | Parameters | FLOPs 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 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).
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
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.
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.
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
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.
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.
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).
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).
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.
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
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:
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:
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:
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):
| Model | Sequence for attention | Pooled / global vector | Note |
|---|---|---|---|
| SD 1.5 | CLIP ViT-L last layer, 77 × 768 | not used | cross-attention in the U-Net |
| SDXL | CLIP 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-Σ, Sana | T5-XXL encoder (PixArt) or Gemma 2 2B (Sana), up to 300 tokens | none: time only, through one shared modulation (section 4) | cross-attention in a DiT |
| SD3, SD3.5 | CLIP-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 modulation | joint attention (section 5) |
| FLUX.1 | T5-XXL, 512 tokens (the diffusers default, padded) | CLIP-L pooled, 768, into modulation | double 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) | none | only 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.
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).
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
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.
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.
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.
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 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.
| Denoiser | Parameters | Tokens | FLOPs per pass | Steps | Training compute | FD, s = 1 | FD, s = 1.5 | Accuracy, 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
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.
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
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)
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).
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.
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
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.
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.
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:
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)
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.
How production models handle it.
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.
| Pipeline | Tokens (image + text) | FLOPs per pass | Steps × passes | Denoiser 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).
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.
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.
| Method (first version) | Idea | Steps | Published 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 it | 1 to 8 | CIFAR-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 steps | 1 to 4 | 1 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 2 | CD: 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 8 | LAION-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 model | 2 to 8 | 67.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 method | 1 to 4 | ADD-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 models | 1 to 4 | ImageNet 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).
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.
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.
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.
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.
Eleven denoisers instantiated from their configs without weights (PyTorch's meta device), every parameter sorted by the kind of layer it belongs to, and one pass counted at the resolution you pick. Pick two to compare. Extends Reading sections 2, 4, 5 and 6.
| Denoiser | Parameters | Modulation share | Image tokens | Text tokens | FLOPs per pass | Attention-score share | Check |
|---|
Counting: src/arch/params.py (parameters, by name patterns listed in the script; fused single-stream layers split by their row and column counts), src/arch/flops_all.py (one pass, batch 1, no classifier-free-guidance batching, the pipeline's default text length, on meta tensors under FlopCounterMode). Attention-score share: the batched matrix multiplications (aten.bmm, the QKT and attention-times-V products) as a share of all FLOPs; Sana's linear attention and cross-attention are its only bmm. Configs: the Hub repos pinned in the root's Model map (src/map/inputs/), FLUX.2 [klein] 4B and DiT-XL/2 fetched here, FLUX.1 from Black Forest Labs' public code and SD3 from the paper's depth rule (both repos are gated); "Check" says which total each count was verified against; * marks a size outside the counted grid (DiT-XL/2 was counted up to 1024), from the fitted formula. derived
What one image costs in denoiser compute, for any of the eleven denoisers on this page at any size: tokens from the VAE factor and patch, FLOPs per pass from the counted formula, then steps and passes. Extends Reading section 9.
The formula: FLOPs(N, T) = k0 + k1N + k2T + k3N2 + k4NT + k5T2, N = image tokens (or the U-Net's top-level latent positions), T = text tokens, with the six coefficients fitted to counts on meta tensors at 10 square sizes and 1 to 5 text lengths per model (src/arch/flops_all.py). It reproduces every counted point to within 10−12 relative, except Z-Image (2%: its code pads both sequences to multiples of 32). Non-square sizes use the same N; for a U-Net that is exact for the convolutions and the attention. Not included: the text encoder, the VAE decoder, and anything the formula cannot see (kernel efficiency: attention FLOPs run at very different speeds depending on the kernel). Throughput is yours to set: the default is the effective rate measured here for SD 1.5's U-Net at 512 × 512 in float16 on the M1 Pro's GPU; a datacenter GPU's sustained rate must be measured, and its vendor peak (NVIDIA lists 989 TFLOPS of dense BF16 for an H100 SXM, H100 page) is an upper bound no denoiser reaches. derived
This page's tabs, the parent topic and its labs, the sibling pages, the knowledge base pages this one leans on, the papers and code behind it and the best outside resources, each with an approximate time. Outside sources are marked maker (by the people who built the method or model) or third-party. Links checked on 2026-10-17; distillation links added 2026-10-24.
Why latents, the U-Net read from its config, text conditioning with SD 1.5's recorded cross-attention, DiT, MMDiT, double and single streams, positions, resolution, cost, few-step distillation; mistakes and rehearsal in closed blocks. Reading: 39 min, plus 15 in closed details
Eleven denoisers counted from their configs: parameters by kind of layer, config values, FLOPs per pass at three sizes, two side by side. 10 min
Any of the eleven at any size, text length, steps and guidance: tokens, FLOPs per pass and per image, time at a throughput you set. 5 min
The map of the topic and which page owns what; its Model map sends one prompt through six real pipelines and lists every generator's release, licence and size. The SD 1.5 timings reused here are the topic's diffusion runs (root src/diff/out); the SD VAE and its scaling factor are on Autoencoders and VAEs, section 11. see the page
The VAE half of latent diffusion: nine generator VAEs on the same images, scaling and shift factors, the SDXL float16 NaNs. about 40 min
The objective and the sampling loop this page's denoisers run in: schedules, ε/x0/v prediction, samplers, guidance (sections 1 to 6), and the measured LCM-LoRA run quoted in section 10. about 36 min
SD3's and FLUX's objective, timestep sampling and the resolution shift mentioned in section 8. about 43 min
Patch embeddings, position interpolation and CLIP's text-image training: the other side of the text encoders used here. about 34 min
Generating images with one transformer that also reads text: the alternative to a separate denoiser. about 37 min
The same denoisers over space-time patches: tokens per second of video. about 31 min
FID, CLIPScore, preference: how the quality claims quoted here were measured. about 27 min
The LDM / Stable Diffusion paper page: the f sweep, cross-attention conditioning, a live toy of latent against pixel diffusion, and a recipe card from LDM to FLUX.1. about 19 min
The U-Net denoiser's origin in diffusion and the ε objective. about 25 min
Patchify, position embeddings and why transformers need data: DiT's starting point. about 23 min
The text encoder of SD 1.5 and SDXL. about 27 min
The text encoder of Imagen, PixArt, SD3 and FLUX.1. about 23 min
Sinusoidal, learned and rotary encodings in depth; the 2-D and 3-D split in section 7 builds on it. about 40 min
Rotary position embedding from the source. about 22 min
Why attention's FLOP share and its time share differ on a datacenter GPU. about 26 min
The maths of VAEs and diffusion behind the objectives. about 23 min
Serving, batching and kernels for language models; much of it applies to serving a denoiser. about 34 min
Patchify, adaLN-Zero, Gflops against FID; Table 4 is reproduced in section 4. 45 min
MMDiT, QK-normalisation, flexible text encoders, resolution-dependent shift. 60 min
Redistributing a U-Net's blocks, micro-conditioning, multi-aspect training. 30 min
Cross-attention DiT, adaLN-single, a cheap training recipe. 30 min
32× DC-AE, linear attention, a decoder LLM as text encoder. 30 min
The only published description of FLUX.1's architecture (section 2). 25 min
A 20B MMDiT with a VLM text encoder and MSRoPE. 40 min
The original; the paper page above walks it. 60 min
The architecture's origin, in medical segmentation. 20 min
Frozen T5-XXL as the text encoder; scaling the encoder over the denoiser. 40 min
One pass per step instead of two: what FLUX.1 [dev] does. 30 min
Consistency distillation in SD's latent; LCM-LoRA follows from it. 30 min
Adversarial distillation in the latent: SD3-Turbo, and the method behind FLUX.1 [schnell]. 30 min
Editing images by controlling cross-attention maps, the idea behind the red/blue comparison. 30 min
SD's U-Net; read with its config beside it. 30 min
Double and single stream blocks, 3-D RoPE. 30 min
The whole DiT in about 370 lines. 20 min
FLUX.1's reference code: model.py and modules/layers.py. 20 min
The three-network picture drawn step by step. 20 min
The pipeline written out by hand: text encoder, U-Net loop, VAE. 20 min
The maths with the architectures in context; updated over time. 45 min
Scripts, recorded outputs and source references: src/ in this page's folder (README.md first; inputs/source_lines.json lists every file and line quoted, located by pattern). Built 17 October 2026; rebuilt to the teaching contract 24 October 2026.