## How models generate images, video and audio

*Images, video and audio*

*Last edited: 13 November 2026*

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 words:** An 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.

*Interactive widget on the page: What these models share with LLMs and where they differ.*

### 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.

*Interactive widget on the page: From noise to image: the generator and sampler loop.*

*Interactive widget on the page: An LLM appends token after token, diffusion improves the whole grid at every step.*

- 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

*Interactive widget on the page: How many tokens an image, a clip or a speech recording takes.*

- 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

**Question:** How does a model that generates images, video or audio differ from an LLM, and what do they share?

**Short answer:** 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.

### Follow-up questions

- **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)](https://arxiv.org/abs/2112.10752)
- [Ho, Salimans: Classifier-Free Diffusion Guidance (2022)](https://arxiv.org/abs/2207.12598)
- [Kumar et al.: High-Fidelity Audio Compression with Improved RVQGAN, DAC (2023)](https://arxiv.org/abs/2306.06546)
- [Alibaba: Wan: Open and Advanced Large-Scale Video Generative Models (2025)](https://arxiv.org/abs/2503.20314)
- [OpenAI: Addendum to GPT-4o System Card: Native image generation (2025)](https://cdn.openai.com/11998be9-5319-4302-bfbf-1167e093f1fb/Native_Image_Generation_System_Card.pdf)

Interactive page: https://howaiworks.dev/image-video-audio-generation/
