Home / Chapter 9 · Images, video and audio
    Last edited · 10 min read

    Use with AI

    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

    LLMImages and videoAudio

    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

    How the output is produced

    From noise to image: the generator and sampler loop

    Random noiserandom noisein the shape of the grid, not the image
    prompttext encoderturns the prompt into vectors once

    generator in a loopat every step it gets the whole grid, the noise level and the prompt vectors

    1. Pure noisestart
    2. Noise with a barely visible outline of a lighthouseafter step 4
    3. A lighthouse and a cliff emerge from the noiseafter step 8
    4. An almost finished image of a lighthouse with a trace of noiseafter step 16

    the sampler subtracts part of the predicted noise and feeds the grid back in, up to step 20

    autoencoder’s decoderturns the grid into pixels only after the last step
    A red lighthouse on a cliff above a stormy seafinished image512×512 pixels

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

    Token count and the cost of generation

    How many tokens an image, a clip or a speech recording takes

    tokens for the transformer
    pages of English text with the same number of tokens

    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.

    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

    Report an error · Suggest a fix