Three ways to generate an image from one transformer

L3SeniorTrade-off12 minSystem designML depth

RolesLLM Product EngineeringInference Engineering

The question

Your team needs one open model for answering questions about images, text-to-image generation and inpainting, with a usable generation latency. One candidate generates images one code at a time; another denoises continuous patches; a third stays with discrete codes and fills them in parallel over a few passes. Compare the three on passes, training complexity and what comes for free.

Answer it first, aloud or on paper. Then open the answer.

The answer

Show short answer

Next-token generation over codes needs one pass per code, 1024 to 4096 passes per image, with one simple loss. Continuous diffusion in a shared transformer needs about 20 passes, but it trains two losses on different scales. Masked discrete decoding keeps codes and one cross-entropy loss, predicts all masked positions at once and commits the most confident ones each pass, so an image takes about 16 passes; inpainting is free, because the training objective is to fill masked codes from the rest. For a product that wants all three tasks in one open model at a usable latency, the masked discrete design is the fit, and the continuous design is the pick when fidelity is paramount.

Show full answer

How masked discrete decoding works

Training samples a masking ratio uniformly, masks that share of an image's codes, and trains the transformer to recover them. That generalizes next-token prediction: for text only the last position is masked, for an image a random subset is. At inference, start from a fully masked grid, predict every masked position in parallel, keep the most confident predictions, re-mask the rest, and repeat on a schedule. A cosine schedule, the mask ratio as the cosine of pi times the step over twice the total steps, concentrates the work at mid-range ratios where predictions are most informative.

The attention mask

Text tokens are causal. Image codes attend to every other code of the same image, so a masked position can see all of its neighbors. Text attends to prior images, and image codes attend to prior text.

The comparison

DesignPasses per imageLossesFree extras
Next-token over codesone per code, 1024 to 4096one cross-entropyvideo with a 3D tokenizer; one stack for everything
Continuous diffusion in the transformerabout 20cross-entropy plus a diffusion loss on patchesthe highest fidelity, no quantizer
Masked discrete decodingabout 16one cross-entropy on masked positionsinpainting; one checkpoint for answering, writing and generating

Per pass, the masked design is cheaper than continuous diffusion, because it emits discrete logits rather than a continuous regression at every patch.

What the masked design pays

It keeps the tokenizer ceiling of every discrete design: the image can be no better than the quantizer's reconstruction. Unmasking everything in one pass fails, because the codes are predicted independently and the result is incoherent; the schedule exists so that committed codes condition the rest.

Inpainting for free

Mask the codes of a region, feed the rest plus a text prompt, and predict the masked ones. No new objective and no new head: the training task was exactly this.

Follow-ups

  1. L3SeniorWhy can the model not unmask everything in one pass?

    Show expected answer

    each masked position is predicted from a marginal that ignores the others, so the sampled codes do not agree; committing the confident ones first gives the rest conditioning.

  2. L3SeniorWhy does a cosine schedule beat a linear one?

    Show expected answer

    it spends more steps at the mid-range ratios where each prediction is most informative, while a linear schedule plateaus earlier.

  3. L4StaffWhere does the per-step cost differ between masked discrete and continuous diffusion?

    Show expected answer

    both are full transformer passes, but the discrete head emits logits over the codebook while the continuous head regresses a velocity for every patch; the discrete pass is cheaper per step.

  4. L4StaffWhat would make you give up the one-model simplicity for a specialist?

    Show expected answer

    a fidelity requirement above the tokenizer ceiling, or a latency budget that even sixteen full passes cannot meet, where a dedicated continuous generator wins.

Wrong answers

Show the wrong answers that interviewers hear
  • “Masked decoding is diffusion, so it needs a noise schedule.”

    It is discrete: positions are masked, not noised, and the schedule sets how many codes to commit per pass.

  • “Next-token generation is the fastest because each pass is small.”

    Each pass is a full transformer pass over the sequence, and there are thousands of them per image.

  • “Inpainting needs a separate model.”

    The masked objective is inpainting; masking a region at inference is the task the model trained on.

Taught in

The Show-o lesson walks the masked decoding, the schedule and the task list, the Emu3 lesson gives the per-code cost, and the Transfusion lesson gives the continuous alternative.