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.
- Predict a probability distribution over the codebook for every masked position at once.
- Sample a token for each position and record its confidence score.
- Keep the most confident tokens and re-mask the rest according to the schedule.
- 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.
| Component | Role | Typical choice |
|---|---|---|
| Visual tokenizer | Maps pixels to discrete codes and back | VQGAN with a 16x downsampling factor |
| Bidirectional transformer | Predicts codes for masked positions | Encoder-style transformer, 24 or more layers |
| Mask schedule | Sets how many tokens stay masked per step | Cosine schedule |
| Confidence sampler | Chooses which predictions to keep | Sampled probability with added Gumbel noise |
| Conditioning signal | Steers content | Class label or text embedding |
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.
| Schedule | Tokens committed early | Typical effect |
|---|---|---|
| Cosine | Few | Best quality in most reported experiments |
| Linear | Moderate | Acceptable quality, slightly weaker layout |
| Square or cubic | Very few | Good structure, can waste late steps |
| Square root or logarithmic | Many | Early errors propagate, lower fidelity |
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.
| Property | Masked generative transformer | Autoregressive transformer | Diffusion model |
|---|---|---|---|
| Representation | Discrete tokens | Discrete tokens | Continuous pixels or latents |
| Context direction | Bidirectional | Left to right only | Global |
| Steps for one image | About 8 to 24 | One per token, often 256 or more | About 20 to 50 with modern samplers |
| Native inpainting | Yes, mask the region | Awkward, order is fixed | Yes, with masking tricks |
| Main weakness | Committed tokens are not revised | Slow sequential decoding | Higher compute per step |
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.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Blurry or blocky detail | Weak tokenizer or small codebook | Train a stronger VQGAN or use more tokens |
| Repeated objects or parts | Too many tokens committed per step | Increase steps or use a cosine schedule |
| Low diversity | Sampling temperature too low | Raise early temperature or add Gumbel noise |
| Early mistakes persist | Committed tokens are frozen | Use a variant that allows token re-masking |
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.