Description and operation · Text-to-image model

Qwen-Image-2.1-Turbo

Over fall break, I worked on quantizing a model. This guide collects my learning, with interactive explainers built with help from Claude.

This model makes an image from a text prompt. It has three parts. Each part does one task. This manual tells you what each part does, why the model needs it, and how much memory it uses.

Total weights (bf16)
32.4 GB
Parts
3
Denoising steps
8
Guidance (CFG)
1.0
Default size
2048 × 2048

1.General

A computer cannot "draw" from words directly. The model does this work in three stages:

PartTaskSize (bf16)Runs per image
Text encoder
Qwen3-VL, 36 layers
Changes the prompt into numbers that hold its meaning.17.53 GB1
Transformer
DiT, 32 layers
Changes random noise into a clean image, in small steps. It reads the prompt numbers at each step.14.23 GB8
VAE
autoencoder
Changes the transformer's compressed result into pixels.0.68 GB1

Why three parts? Each task needs a different skill. The text encoder knows language. The transformer knows how images look. The VAE knows how to pack pixels into a small space and unpack them again. If one network did all three tasks, it would be larger and slower.

The last column is important for this manual. The transformer runs 8 times. The other parts run only once. Thus the transformer controls the speed. The text encoder is the largest part. Thus it controls the memory.

Figure 1The data path from prompt to image

Select a stage to see what it does and the shape of the data that it makes. The prompt in Figure 2 sets the token count.

2.Text encoder TE

A. Function

The transformer cannot read words. It can only use numbers. The text encoder changes each word into a list of 4,096 numbers. This list is a vector. Words with similar meanings get similar vectors.

The text encoder is Qwen3-VL, a full language model with 8.8 billion parameters. Why use such a large model? A large language model knows grammar, layout words and spelling. Thus the image model can follow long prompts and write correct text in the image. Qwen3-VL also has a vision part. In edit mode, it reads your input image together with the prompt.

B. Tokens

First, a tokenizer cuts the prompt into pieces. A piece is a token. A short word is usually one token. A long or rare word becomes two or more tokens. The vocabulary has 151,936 tokens. Each token has an ID number.

Figure 2Tokens and vectors
Show vectors:
Token vectors (48 of 4,096 values shown)

Each row is one token. Each column is one value of its vector. Orange is a positive value. Blue is a negative value. The tokenizer and the values are an illustration. The real tokenizer uses byte-pair encoding, and the real values come from the trained model.

C. Context

Before the encoder, each token has a fixed vector. The word "bank" always gets the same vector. The 36 layers use attention. Attention lets each token look at the other tokens. After the layers, the vector of "bank" holds the meaning of its sentence. Compare the two sentences below.

Figure 3One word, two meanings

The similarity is the cosine of the angle between the two "bank" vectors. 1.00 means the same vector. The numbers are an illustration of the effect, not values from the real model.

NOTE

The transformer uses the output of the text encoder, not the token IDs. Both models use vectors of 4,096 values. Thus the transformer's context_in_dim is 4096.

3.VAE VAE

A. Function

A 2048 × 2048 image has 4.2 million pixels. Each pixel has 3 colour values. That is 12.6 million numbers. The transformer cost increases with the square of the number of tokens. Thus the transformer cannot work on pixels directly.

The VAE (variational autoencoder) solves this problem. It has two halves:

  • The encoder packs each 16 × 16 block of pixels into 64 numbers. The model uses the encoder in edit mode, to read your input image.
  • The decoder unpacks the 64 numbers into a 16 × 16 block of pixels. The model uses the decoder at the end of each generation.

The packed data is the latent. The transformer works only on the latent. One latent cell is one image token for the transformer.

Figure 4Pixels and the latent
Image · 256 × 256 × 3196,608 values
Latent · 16 × 16 × 6416,384 values
Move the pointer over the image or the latent.

Each latent cell shows its 64 values as an 8 × 8 pattern. The latent is not a small picture. Its 64 channels hold colour, edges and texture together. The values here are an illustration.

Figure 5Supported sizes and their token counts
RatioPixels (W × H)Pixel valuesLatent gridLatent valuesImage tokens

The VAE reduces the data 12 times (16 × 16 × 3 = 768 values become 64). All seven presets give about 16,500 image tokens.

CAUTION

Do not quantize the VAE to a low bit width. It is small (0.68 GB), so you save almost no memory. Errors in the decoder go directly into the pixels.

4.Transformer DiT

A. Function

The transformer is a diffusion transformer (DiT) with 7.1 billion parameters. It starts with random noise in the shape of the latent. Then it removes the noise in 8 steps. At each step, it reads the prompt vectors from the text encoder.

The model uses flow matching. A noise level σ (sigma) goes from 1 to 0. At level σ, the latent is a mix of the clean latent x₀ and noise ε:

xσ = (1 − σ) · x₀ + σ · ε

At each step, the transformer predicts a direction v. The direction points from the clean latent to the noise. The sampler then moves the latent one step toward the clean latent:

x ← x + (σnext − σ) · v

The checkpoint has a fixed list of 8 σ values. Use the slider to see each step.

Figure 6The 8 denoising steps
Latent at this step
Prediction of the result
σ schedule (from the checkpoint)

The left panel shows xσ with the real σ values. For clarity, it mixes pixels, not latent values. The centre panel shows the clean image that the model predicts at that step (illustration). Look at the schedule: σ stays near 1 for 5 steps. The last 3 steps remove most of the noise. The first steps set the layout. The last steps add the detail.

B. One transformer block

The transformer has 32 blocks of the same design. Each block gets two groups of tokens: the image tokens from the latent and the text tokens from the text encoder. The block puts the two groups together. Thus each image token can look at the words of the prompt.

The block also gets the current σ value. A small network changes the scale and shift of the data in each block for this σ. This is AdaLN (adaptive layer normalization). With it, one set of weights can do all 8 steps.

Figure 7Data flow through the transformer
Image tokens16,384 × 4096
Text tokensT × 4096
Noise level σ1 value → AdaLN
↓
× 32 blocks
AdaLNscale and shift from σ
Joint attention32 heads × 128 = 4096
AdaLNscale and shift from σ
MLP4096 → 12288 → 4096
↓
Direction vsame shape as the latent

Attention and MLP layers hold almost all of the 7.1 billion parameters. These are the layers that quantization makes smaller.

C. Prefix KV cache

In attention, each token makes three vectors: a query (Q), a key (K) and a value (V). A token uses its query to look at the keys of other tokens. Then it takes their values.

In this model, the text tokens cannot look at the image tokens (causal_condition: true). Thus the K and V of the text tokens do not change between steps. The model calculates them at step 1 and keeps them in a cache. Steps 2 to 8 use the cache again. Click a row in the grid.

Figure 8Which token looks at which token
Text looks at text
Image looks at image
Image looks at text
Blocked: text does not look at image

The grid shows 5 text tokens and 12 image tokens. A real 2048 × 2048 image has 16,384 image tokens. Rows are the tokens that look (queries). Columns are the tokens that they look at (keys).

D. Why the model is "Turbo"

A typical base diffusion model uses about 50 steps. It also uses classifier-free guidance (CFG). With CFG, the transformer runs two times at each step: one time with the prompt and one time without it. The model then moves the result away from the "no prompt" output.

The Turbo checkpoint is distilled from Qwen-Image-2.1. During training, it learned to copy the result of the slow model in 8 steps. It also learned to follow the prompt without CFG. Thus the guidance value is 1.0, and the transformer runs one time per step.

Figure 9Transformer runs for one image
Typical base model
50 steps × 2 (CFG)
100 runs
Turbo
8 steps × 1
8 runs

The base model values are typical for this class of model. They are not measured values of Qwen-Image-2.1.

5.Memory on a 24 GB Mac

On Apple silicon, the CPU and the GPU use the same memory. macOS does not give all of it to the GPU. On a 24 GB Mac, the default GPU limit is approximately 16 to 18 GB. The weights in bf16 are 32.4 GB. Thus you must make the weights smaller, load the parts one at a time, or do both.

Which part do you quantize?

  • TE The text encoder runs one time per image. It is the largest part. Use 4-bit. The quality loss is small, and you save about 12.6 GB.
  • DiT The transformer runs 8 times, and its errors add up across the steps. Use 8-bit for best quality, or 6-bit to save more.
  • VAE Keep it in bf16.
Figure 10Memory calculator

Dashed lines: the approximate default GPU limit (17 GB) and the total memory (24 GB). Weight sizes use the real parameter counts. 4-bit and 6-bit include the cost of the group scales. Working memory values are estimates.

NOTE

You can increase the GPU limit with sudo sysctl iogpu.wired_limit_mb=20480. The value goes back to the default when you restart the Mac. Keep some memory for macOS and your other applications.

WARNING

Do not set the GPU limit near the total memory. If macOS has too little memory, the system can stop responding and you can lose unsaved work.

6.Terms

Token
One piece of input for a transformer. A text token is a part of a word. An image token is one latent cell.
Vector
A list of numbers. In this model, most vectors have 4,096 values.
Attention
The operation that lets each token use information from other tokens.
Latent
The compressed form of the image. The VAE makes it, and the transformer works on it.
σ (sigma)
The noise level. 1 is only noise. 0 is a clean latent.
Flow matching
A training method. The model learns the straight direction from data to noise.
CFG
Classifier-free guidance. Two runs per step that push the result toward the prompt. The Turbo model does not need it.
Distillation
Training a model to copy the output of a slower model with less work.
KV cache
Stored keys and values that the model uses again instead of calculating them again.
bf16
A 16-bit number format. It uses 2 bytes for each weight.
Quantization
Storing weights with fewer bits, for example 8 or 4, plus a scale for each group of weights.