Home / Chapter 9 · Images, video and audio
Last edited · 10 min read
How models generate images, video and audio
Many image, video and audio models are built on a transformer, as LLMs are, but they often produce their output differently. An LLM appends token after token, while a typical image or video model starts from random noise and improves the whole output at once over many steps, which is called diffusion; audio models work one way or the other.
In plain wordsAn LLM works like someone writing a letter: word by word, never going back. An image or video model works like a painter who is handed a canvas spattered with random dots and reworks all of it at once, round after round: first the blotches, then the shapes, finally the details. A speech model often writes like an LLM, except that instead of words it appends numbers describing short pieces of sound.
What these models share with LLMs and where they differ
What a token is
The index of a piece of text in the model’s vocabulary.
A vector of numbers describing a patch of the image, e.g. a 16×16 pixel square, and in video the same patch of the picture in several consecutive frames. There is no vocabulary: the model does not pick a token from a list, it computes the token’s values.
Usually a code: the index of a vector in a neural codec’s codebook, a learned table of vectors. A neural codec is a trained counterpart of MP3. One frame, a short stretch of the recording, is described by several codes.
How the output is produced
Token by token; each one is final as soon as it is produced.
The whole output at once, from noise, in a few dozen steps; fast variants need only a few. It is final only after the last step.
Often in order as in an LLM, sometimes all at once like an image.
How the prompt works
It is the start of the text, and the model appends the continuation.
A separate model, the text encoder, reads the prompt once, and the vectors it computes steer every step. A separate parameter, the guidance scale, controls how strongly the prompt influences the output (see “Image generation”).
For speech generation, the prompt contains the text to be spoken and often a voice sample; the model continues that sample in the same voice, as an LLM continues a text. For music generation the prompt is a description, as with images.
What limits one call
The context window: a token limit for the prompt and the answer.
The size of the output: resolution and clip length, fixed before the start. The text encoder also has its own prompt limit.
It depends on the model: a context window as in an LLM, or a length fixed before the start. Longer recordings are split into segments.
Where the randomness is
Sampling at every token, temperature.
The starting noise, determined by a number called the seed; some samplers (the algorithms that perform a step) also add fresh random noise at every step.
As in an LLM or as in an image model, depending on the model.
The images and video column describes typical diffusion models. Models in all three columns usually use a transformer with attention. They are trained on huge datasets, then tuned on selected examples and on human preferences (see “Training”).
A compressed representation instead of pixels
- The generator, the network that produces the output in a loop, usually works not on pixels but on a compressed representation of them: an array of numbers (a tensor), called the grid below. Fewer numbers mean a lower cost for every generator step. A separate network, the autoencoder, converts between the image and the grid (publications call it a VAE and the grid a latent): its encoder turns an image into a grid, and its decoder turns a grid into an image. The autoencoder works like a lossy codec such as JPEG. In audio this role is usually played by a neural codec.
- The difference from JPEG: an overcompressed JPEG shows blurry blocks, while the autoencoder’s decoder draws in plausible details that were not in the representation. Small text, small faces and fast motion are lost most easily.
- The representation has three levels, shown here for FLUX.1 (2024). The image is 1024×1024 pixels with 3 numbers each (RGB), about 3.1 million numbers in total. The grid is 128×128 cells with 16 numbers each, about 262,000 numbers, 12 times fewer; one cell corresponds to an 8×8 pixel square. The FLUX.1 generator, a transformer, joins cells into 2×2 squares, so it gets 64×64 = 4,096 tokens, each for a 16×16 pixel square. This resembles a tokeniser merging characters into a token (see “Tokens”), except that here the merging is fixed and yields a vector, not a number.
Three levels of image representation in FLUX.1. The highlighted square is the same part of the image: 16×16 pixels, 2×2 grid cells, one token. The drawn lattices are schematic; real grids have more cells.
How the output is produced
- Diffusion is a loop. The generator gets a noisy grid and predicts a noise value for every number stored in it. The sampler, the algorithm that performs each step, uses a predefined schedule of noise levels to decide how much predicted noise to subtract from the grid. It then passes the updated grid back to the generator for the next step. The name is the same as in LLMs but the role differs: there the sampler draws a token, here it performs a denoising step.
- For an ordinary model one step is not enough: a prediction made from pure noise corresponds only to an averaged, blurry image. Each further step starts from a less noisy grid, so it can resolve finer details, like successive approximations in an iterative method. The first steps produce the layout of the image and the last ones the details, a bit like a progressive JPEG loading, except that here the details are not waiting in a file: the model makes them up as it goes.
From noise to image: the generator and sampler loop
generator in a loopat every step it gets the whole grid, the noise level and the prompt vectors
start
after step 4
after step 8
after step 16
the sampler subtracts part of the predicted noise and feeds the grid back in, up to step 20
finished image512×512 pixelsAn actual 20-step run of Stable Diffusion 1.5 (2022), also shown in “Image generation”. The grid contains only numbers, so this figure uses the decoder to visualise it. Newer models have a larger grid and a transformer in place of the convolutional network (U-Net), but the same loop; video adds a time dimension to the grid. How the generator learns to predict noise is covered in “Image generation”.
An LLM appends token after token, diffusion improves the whole grid at every step
LLM: for readability one word is one token here; a real tokeniser splits some words into several pieces (see “Tokens”). Diffusion: the same generation in Stable Diffusion 1.5; the decoder shows the grid, and the red 8×8 lattice stands in for its 64×64 cells. The percentage is the share of noise in the variance of the grid entering the step. The schedule sets it, here with 20 noise levels, one per step. It is not the fraction of cells that are noisy: every cell is a mix of image and noise.
- The generator sees the whole output at once, so the first frame of a clip can adapt to the last; an LLM, which only writes forward, cannot do that. For a model that improves the whole output at once this has two consequences. It has no KV cache for the output: every step changes all cells, so no part of the output is a fixed prefix (only the prompt vectors, computed once, stay fixed). It also has no counterpart of time to first token (see “The generation loop and KV cache”): the preview that services show along the way is a prediction of the whole image (the decoded grid after subtracting all of the predicted noise), not a finished part.
- Autoregression, appending in order as an LLM does, has caught on in audio: the model predicts one code after another, with a KV cache and temperature (see “The next token”). A recording has a natural order in time and often has to be played before the whole of it exists. Video has an order in time too, but a second of 720p video is ten to twenty thousand tokens and a second of speech only hundreds of codes, so appending video token by token would take too long (models that append whole chunks of frames are covered in “Video generation”). The first parts of the audio can be played earlier if the generator and decoder work in short chunks. Details are in “Voice, speech and music”.
- In images autoregression is less common. An image consists of thousands of tokens with no natural order. Appending them one by one takes thousands of consecutive network passes, which a GPU cannot compute in parallel, while diffusion processes all tokens at once in 20–50 steps. That is why most open image models use diffusion. Autoregression is used too: OpenAI described image generation in GPT-4o (2025), which started the GPT Image line, as autoregressive. OpenAI does not disclose the architecture of the newer GPT Image models.
- Is this the same kind of model as an LLM? Both can use the same transformer block, the repeating unit of the network: Movie Gen (Meta, 2024) was built using Llama 3’s transformer block. A diffusion model differs in that it sees the whole output at once, predicts numbers instead of picking a token, and repeats its loop over noise levels, not over positions. More and more often one model combines autoregression with diffusion: the open HunyuanImage 3.0 (Tencent, 2025) writes text token by token and creates the image by diffusion. The label “natively multimodal” in a service’s description does not say whether the model creates an image autoregressively or by diffusion.
- The text encoder reads the prompt, so the encoder determines how much of the prompt reaches the generator. Many services rewrite your prompt with an LLM before generating, because newer generators were trained on long, precise descriptions. When the output strays from the prompt, check whether the service returns the rewritten prompt.
Token count and the cost of generation
How many tokens an image, a clip or a speech recording takes
Numbers computed from published grid dimensions and codec parameters: the image as in FLUX.1, video as in Wan 2.1 (2025; 720p, 16 frames per second), speech as in the DAC codec (2023; about 86.1 frames per second of 9 codes each, about 775 codes per second; this codec stores audio across the full band a human can hear; speech-only codecs use fewer codes per second). How many network passes a recording takes depends on the generator. Other models compress differently, so this is an order of magnitude, not a constant, and the slider goes beyond the sizes these models were trained on. A page of English text is about 500 words, about 650 tokens.
- At a fixed size and duration the token count does not depend on the content: a blank wall and a crowd in a square at the same resolution take the same number of tokens. In text the token count depends on the content. “Image tokens” in price lists are a separate billing unit that need not match the generator’s token count.
- The compute cost of a diffusion model is the number of steps times the cost of a step (classic guidance computes two predictions at every step, with the prompt and without it; see “Image generation”), and the cost of a step grows with the token count. The cost of attention alone, where every token looks at every other token, grows with the square of the token count. Many tokens computed at once make good use of the GPU, much as prefill does (see “Why the GPU is idle”). Time depends mainly on resolution, length and the number of steps. Fast variants such as FLUX.1 schnell are separate versions of the model, trained (distilled) down to 1–4 steps (see “Distillation”).
Check yourself
How does a model that generates images, video or audio differ from an LLM, and what do they share?
The generator is usually built on a transformer, as an LLM is, but it works on a compressed representation. A separate network creates and reads that representation: an autoencoder for images and video, and often a neural codec for audio. The compression is lossy. An image token is a vector of numbers for a patch of the image, and in audio a token is usually the index of a vector in the codec’s codebook; how many tokens there are depends on size and duration. Image and video models usually generate by diffusion: they start from noise and improve the whole output at once over many steps, and the guidance scale controls how strongly the prompt influences the output. Audio models often append codes in order as an LLM does. Playback can start before generation ends if the generator and decoder work in short chunks.
Po polsku
Generator zwykle opiera się na transformerze, tak jak LLM, ale pracuje na skompresowanym zapisie. Taki zapis tworzy i odczytuje osobna sieć: autoenkoder dla obrazu i wideo, a często kodek neuronowy dla dźwięku. Kompresja jest stratna. Token obrazu to wektor liczb dla kawałka siatki, a w dźwięku zwykle numer ze słownika kodeka; ich liczba zależy od rozmiaru i czasu trwania. Modele obrazu i wideo zwykle generują dyfuzją: zaczynają od szumu i w wielu krokach poprawiają cały wynik naraz, a siłę promptu ustawia skala guidance. Modele dźwięku często dopisują kody po kolei jak LLM. Odtwarzanie może ruszyć przed końcem generowania, jeśli generator i dekoder działają krótkimi kawałkami.
Follow-up questions (4)
- The cost of image generation in your product is growing faster than you assumed. What do you check?
- Resolution, the number of steps and the number of attempts per accepted image. The compute cost is steps times the cost of a step (classic guidance computes two predictions per step, with the prompt and without it), the token count grows with the square of the image’s side length, and the cost of attention grows faster still. In an API, also check how the provider bills input text, reference images and the quality level. It helps to generate drafts at the lowest resolution the model handles well, to use a faster variant with fewer steps, and to upscale only the image you pick.
- Why does a diffusion video model have no context window in the LLM sense?
- Because it does not append an answer to a prompt. The whole clip is one sequence of tokens that the model improves at every step. The prompt arrives from the text encoder as separate vectors, and in a model that generates the whole clip at once it is not a prefix that the output is appended to. The counterpart of the window is the token count of the whole clip, limited by the cost of attention and by the length of the clips used in training.
- When can speech start playing before generation ends, and when do you have to wait for the whole utterance?
- Audio can be played earlier if the generator and decoder work in chunks. Autoregression alone is not enough: VALL-E (2023) generates the first code for each frame in sequence, then fills in the remaining codes across the whole utterance. A model that denoises the whole recording at once delivers its output only after the last step. Denoising can also run in chunks, as in CosyVoice 2, and then there is no need to wait for the whole utterance. So for live conversation pick a model that generates and decodes in chunks; for a recording generated from a single text, you can use a model that generates the whole recording.
- Is a higher guidance scale the same as a lower temperature?
- The effect is similar, because the output is closer to the prompt and less varied, but the mechanism differs. Temperature changes the distribution a token is sampled from. Classic guidance needs two predictions at every step, with the prompt and without it, and amplifies the difference between them. Models with distilled guidance, such as FLUX.1 dev, get a similar effect with one prediction per step. Too high a scale gives oversaturated colours or stiff motion, not the repetitions that a low temperature gives. More in “Image generation”.
Sources
- Rombach et al.: High-Resolution Image Synthesis with Latent Diffusion Models (2021)
- Ho, Salimans: Classifier-Free Diffusion Guidance (2022)
- Kumar et al.: High-Fidelity Audio Compression with Improved RVQGAN, DAC (2023)
- Alibaba: Wan: Open and Advanced Large-Scale Video Generative Models (2025)
- OpenAI: Addendum to GPT-4o System Card: Native image generation (2025)