How to build a diffusion language model
TL;DR Highlight
A guide to diffusion LLMs: fill and refine whole sequences in parallel instead of one token at a time.
Who Should Read
An LLM API developer frustrated by autoregressive speed and lack of error correction who wants to understand how diffusion LLMs work.
Core Mechanics
- Autoregressive LLMs have three limits
- A token cannot be revised once emitted, so early mistakes compound.
- Generation needs as many steps as tokens, so parallelism is hard.
- Causal attention never looks at future context.
- Diffusion LLMs refine a whole draft
- They start from a full-length draft and rewrite every position in parallel over several steps.
- Fewer or more steps trade speed against quality, and each step sees bidirectional context.
- By 2026 there are Mercury 2 (Inception Labs), Gemma Diffusion (Google), and Nemotron Diffusion (NVIDIA).
- Masked diffusion is a generative BERT
- Train a bidirectional transformer to fill in blanks at a random masking rate.
- Generation starts fully masked and repeats infilling and remasking.
- Unlike BERT the masking rate is randomized, and the post says this forms the basis of most open-source diffusion LMs.
- The loss is an averaged BERT loss
- The training loss is the BERT cross-entropy averaged over all masking rates and normalized by t.
- This ELBO (lower bound on likelihood) allows direct perplexity comparison with autoregressive models.
- On LM1B perplexity, MDLM beats earlier discrete diffusion (D3PM, SEDD, etc.) and closes much of the gap to autoregressive.
- The basic form is not production-ready
- It only generates fixed-length sequences.
- It lacks built-in iterative refinement (error correction).
- It is not fast without extra post-training.
- Block diffusion enables variable length
- It runs diffusion block by block, conditioned on earlier blocks.
- The Gemma Diffusion example uses 256-token blocks up to 1024 tokens.
- Finished blocks' keys and values can be cached like KV caching.
Community Reactions
- Running diffusion Gemma on GPUs was reported very fast in output tokens/sec and usable as a local model
- The commenter noted its whitepaper says it could have done better with more time and compute.
- Reimplementing diffusiongemma exposed a weakness, per one commenter
- When two positions must be coordinated but both teeter between valid states, they may not collapse to a matching pair.
- One commenter wondered about generating text as images with image diffusion, then OCRing it
- They guessed a single monospace font would make OCR close to template matching.
- A university student said deriving the ELBO was illuminating
- Naming the larger math structures made it simple, and ChatGPT helped fill gaps in understanding.
How to Apply
- Feed this post to an LLM to judge fit for your service
- Today, run the prompt below with your latency and error-correction requirements.
- Ask it to separate where parallel generation and iterative refinement help from where they do not.
- Benchmark Diffusion Gemma speed on a local GPU
- Compare output tokens/sec against your current autoregressive model on the same prompts.
- Separately check consistency on outputs needing matched pairs like brackets or key-value pairs.
- Use block size thinking for long outputs
- Add block diffusion models to candidates for variable-length generation tasks.
- Tune block size by GPU utilization and compare throughput.
Try It
# Paste into Claude or ChatGPT (simplified version of the paper's method: draft → full rewrite rounds)
Handle the task below in a diffusion style. Don't write left to right in one pass; make a full draft first, then refine all parts simultaneously over several rounds.
Task: {{document or code description to write}}
1) Round 0: Produce a rough full-length draft, leaving low-confidence parts as [MASK].
2) Rounds 1-3: Each round, look at context on both sides, fill the [MASK]s, and find and fix inconsistencies (mismatched names, brackets, numbers).
3) At the end, give the final version and a summary of what changed in each round.
Next to try: compare against a single-pass version of the same task and count the errors.Terminology
Related Papers
A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth
Install Unsloth Desktop, load a quantized Qwen model, and share a private ChatGPT-like AI on your home LAN.
Muru – AI-assisted Rust server for Python apps by mod_WSGI's creator
mod_wsgi's creator is building Muru, an AI-assisted Rust ASGI/WSGI server, documenting it in public
87% of the Anthropic power will come from gas and 11% from coal in 2028
Analysis of Anthropic's contracted data centers: 87% gas, 11% coal power in 2028
Anthropic’s Nasdaq debut
Anthropic listed on Nasdaq and closed its first day below its opening price.
OpenAI still has a WebRTC Problem
WebRTC drops late audio, hurting voice AI; MoQ retransmits and buffers instead
Gemini 4 Neon
Gemini 4 Neon cuts cost per task 32% versus Carbon, at $3 input and $15 output per million tokens
AI is killing All About Berlin
After Google AI Overviews, a Berlin guide site lost 70-75% of its traffic.
Not Everything Needs an LLM
PostHog used small decision models to skip 98.7% of expensive LLM calls