Masked generative transformer

Also known as: MaskGIT

On this page 7

A masked generative transformer is a generative model that produces images, video or audio by predicting masked discrete tokens in parallel with a bidirectional transformer, then keeping the most confident predictions and re-masking the rest over a small number of refinement steps. In generative AI, the approach is best known through MaskGIT, introduced by Google researchers in 2022, and it offers an alternative to both autoregressive image generation and diffusion models.

The core idea borrows from masked language modeling in BERT: the model learns to fill in hidden tokens using context from every direction. Instead of writing an image token by token in raster order, a masked generative transformer drafts the whole canvas at once and sharpens it in roughly 8 to 16 iterations, which makes decoding much faster than sequential sampling.

How a masked generative transformer works

A masked generative transformer works in two stages: a tokenizer turns pixels into a grid of discrete codes, and a transformer learns to generate that grid. The tokenizer is usually a VQGAN or VQ-VAE, which compresses a 256 by 256 image into, for example, a 16 by 16 grid of 256 tokens drawn from a codebook of about 1,024 to 8,192 entries.

During training, the model samples a masking ratio from a schedule, replaces that share of tokens with a special mask token, and learns to predict the original codes with a cross-entropy loss computed only on masked positions. Because the transformer attends in both directions, each prediction uses the full visible context rather than only earlier tokens.

Generation reverses the process. The canvas starts fully masked, and each iteration follows the same short loop.

  1. Predict a probability distribution over the codebook for every masked position at once.
  2. Sample a token for each position and record its confidence score.
  3. Keep the most confident tokens and re-mask the rest according to the schedule.
  4. Repeat until no masked positions remain, then decode the tokens back to pixels.

The table below summarizes the main components and the role each one plays in the pipeline.

ComponentRoleTypical choice
Visual tokenizerMaps pixels to discrete codes and backVQGAN with a 16x downsampling factor
Bidirectional transformerPredicts codes for masked positionsEncoder-style transformer, 24 or more layers
Mask scheduleSets how many tokens stay masked per stepCosine schedule
Confidence samplerChooses which predictions to keepSampled probability with added Gumbel noise
Conditioning signalSteers contentClass label or text embedding
Components of a masked generative transformer

The mask schedule and iterative decoding

The mask schedule is the function that decides what fraction of tokens remains masked after each iteration, and it strongly affects quality. A cosine schedule keeps most tokens masked in early steps and commits many tokens late, so the first decisions fix only the global layout while later steps fill in texture.

Decoding also uses temperature annealing on the confidence scores. Adding randomness early prevents the sampler from locking in the same safe tokens, while lowering the temperature later lets the model commit to high-confidence detail. Classifier-free guidance can be applied as in diffusion models to strengthen prompt adherence.

The following table compares common schedule shapes and how each one behaves in practice.

ScheduleTokens committed earlyTypical effect
CosineFewBest quality in most reported experiments
LinearModerateAcceptable quality, slightly weaker layout
Square or cubicVery fewGood structure, can waste late steps
Square root or logarithmicManyEarly errors propagate, lower fidelity
Mask schedule shapes and their effects

The number of steps is a direct speed and quality trade-off. Too few steps force the model to sample many tokens independently in one pass, which produces incoherent textures and duplicated parts; beyond roughly 12 to 20 steps, extra iterations bring little improvement.

Comparison with autoregressive and diffusion models

A masked generative transformer sits between autoregressive transformers and diffusion models: it shares the discrete token space of the former and the iterative refinement of the latter. The table below contrasts the three families on properties that matter when choosing an architecture.

PropertyMasked generative transformerAutoregressive transformerDiffusion model
RepresentationDiscrete tokensDiscrete tokensContinuous pixels or latents
Context directionBidirectionalLeft to right onlyGlobal
Steps for one imageAbout 8 to 24One per token, often 256 or moreAbout 20 to 50 with modern samplers
Native inpaintingYes, mask the regionAwkward, order is fixedYes, with masking tricks
Main weaknessCommitted tokens are not revisedSlow sequential decodingHigher compute per step
Masked generation compared with neighboring approaches

Because every step evaluates the full transformer over all positions, the total compute is not always lower than for a well-distilled diffusion model. The practical advantage is the small number of sequential steps, which reduces latency on parallel hardware.

Variants and applications

The masked generative approach has been extended well beyond class-conditional image synthesis. Muse applied it to text-to-image generation with a frozen large language model as the text encoder, and MAGVIT and Phenaki adapted it to video by tokenizing space and time together. Similar masked token modeling appears in audio generation systems.

  • Inpainting and outpainting: mask only the region to change and let the model regenerate it consistently with the visible context.
  • Class-conditional synthesis: generate ImageNet-style images from a label in a handful of steps.
  • Text-to-image: condition on text embeddings through cross-attention.
  • Video and audio: predict tokens over space-time or time-frequency grids.

Limitations and common mistakes

The main limitation is that output quality is capped by the tokenizer: if the VQ codebook cannot represent fine texture, the transformer cannot generate it. A second issue is the conditional independence assumption within each step, since tokens sampled in the same iteration do not see one another.

SymptomLikely causeRemedy
Blurry or blocky detailWeak tokenizer or small codebookTrain a stronger VQGAN or use more tokens
Repeated objects or partsToo many tokens committed per stepIncrease steps or use a cosine schedule
Low diversitySampling temperature too lowRaise early temperature or add Gumbel noise
Early mistakes persistCommitted tokens are frozenUse a variant that allows token re-masking
Typical problems and remedies

Explained without jargon

Think of a jigsaw puzzle where the picture is cut into a few hundred pieces. A masked generative transformer starts with an empty board. It guesses every piece at once, keeps only the guesses it is most sure about, and throws the rest back.

Then it guesses again, now with more pieces in place. After about eight to twelve rounds, the board is full. This is much faster than placing pieces one at a time in a fixed order. The finished pieces are then turned back into a normal image.

A typical use case

A product team at an online furniture retailer wants to replace the background of catalog photos while keeping each sofa untouched. Their pipeline tokenizes each 512 by 512 photo into a 32 by 32 token grid, masks every token outside the product outline, and asks a text-conditioned masked generative transformer to fill the region from a prompt such as a bright living room with oak flooring.

With 12 decoding steps and a cosine schedule, each image is ready in well under a second on a single data center GPU, so the team can generate several background options per product and let an editor choose. When a test run with only four steps produced duplicated lamps and broken floor lines, the engineers raised the step count and lowered the late-step temperature, which restored coherent, catalog-ready backgrounds without retraining the model.