LLaDA

A language model that writes a whole answer at once: start fully masked, fix the surest words first, and match LLaMA3 8B on many tests.

Large Language Diffusion Models shows that the skills of a chatbot do not need the left-to-right habit. A diffusion model trained from scratch at 8 billion parameters can learn them too.

Press Run on each partner. The autoregressive model writes one word per pass. LLaDA starts with every word masked and fixes the surest ones first. Drag the steps, then run it again. Then we build, piece by piece, how it trains and how it writes.

You need a rough idea of what a probability is (a number from 0 to 1 that says how likely something is) and what a token is (a piece of text that a model counts). We build the rest from zero.

Based on Large Language Diffusion Models by Shen Nie, Fengqi Zhu, Zebin You, Xiaolu Zhang, Jingyang Ou, Jun Hu, Jun Zhou, Yankai Lin, Ji-Rong Wen and Chongxuan Li (Renmin University of China and Ant Group, NeurIPS 2025). This is one of the assigned readings for MIT MMAI lecture 10, Modern Generative AI.

Write the same answer

4

Toy: the twelve words and each word’s confidence are made up to show the order of work. The paper’s knob is the number of sampling steps (Sec. 2.4). Its Fig. 5 uses 32, 64, 128 and 256 steps for a 256-token answer, which is 8, 4, 2 and 1 tokens per pass.

Chapter 0

Why Write One Word at a Time?

See what the left-to-right habit costs, and what question the paper asks about it

Imagine you write a birthday card. You know the last line before the first word: “Love, Sam”. You write it first. Then you fill the gaps, and you change a word in the middle when it does not fit. Writers work in any order they like.

Most chatbots cannot. A chatbot writes its first word, then its second, then its third. It never goes back. This habit has a name. A model that predicts each new token from the tokens on its left is an autoregressive model (ARM). A token is a piece of text that a model counts, such as a short word or a part of a long one.

GPT and LLaMA are autoregressive. The habit is so common that many people treat it as the cause of what these models can do. The paper in this lesson asks a plain question. Is the left-to-right habit really the cause?

The question, and the paper’s answer

The authors name three skills that make a large language model useful. The first is scalability: more data and more compute give a better model, in a smooth and predictable way. The second is in-context learning: the model picks up a new task from a few examples in its prompt. The third is instruction following: the model does what you ask.

Their claim is that none of these three needs the left-to-right habit. They come from a deeper rule that all these models obey: fit the true distribution of text by maximum likelihood. Chapter 1 explains that rule. The left-to-right chain is only one way to write it down.

To test the claim, they build LLaDA, short for Large Language Diffusion with mAsking. They train it from scratch at 8 billion parameters on 2.3 trillion tokens. That took 0.13 million H800 GPU hours. Then they fine-tune it on 4.5 million prompt and answer pairs. LLaDA writes in a different way, and it still competes with LLaMA3 8B on many tests.

What does “diffusion” mean for words?

You may know diffusion from image models. They add noise to a picture until only static is left. Then they learn to take the noise away, step by step, and a clean picture appears.

Words cannot hold a little noise. A word is one thing or another. So text diffusion uses a different kind of damage: hide the word. A hidden word is replaced by a special mask token, written M. A fully hidden sentence is the text version of static. The model learns to fill the masks back in, and a whole answer appears from M M M M.

That is the whole idea. The rest of the lesson makes each part exact, one mechanism per chapter.

Who may read what

Pick a word to hide. Teal chips are the words the chosen model may read to guess it. Switch between the two models and watch the readable words change.

Illustrative: one made-up line of six words. The rule is the paper’s. An autoregressive model reads only the tokens before the one it predicts. LLaDA’s mask predictor is a Transformer with no causal mask, so it reads every token that is not masked (Sec. 2.2).

Try the last word. The autoregressive model has five words to read, and the mask predictor has the same five. Now try the first word. The autoregressive model has to guess it from nothing. The mask predictor reads the other five. That difference is the first thing the paper wants you to see.

Is it only a toy difference? The paper says no. A model that sees both sides can answer questions that run against the grain of the text. Chapter 8 measures this on a poem task, where LLaDA beats GPT-4o when it must write the line before a given line.

The road

The lesson follows the paper in order. Each chapter explains one part of the instrument at the top of the page.

  1. The goal is a distribution: why any order of writing can reach the same probability.
  2. The forward process: how masking destroys a sentence, one random hide per token.
  3. The mask predictor and its loss: what the network learns, and why the loss divides by t.
  4. Training, step by step: pre-training and fine-tuning with tensor shapes.
  5. The reverse process: writing an answer by remasking the least sure words.
  6. Samplers and length: left to right, blocks, or all at once.
  7. Scaling and benchmarks: what the tables show against LLaMA.
  8. The reversal curse: what a two-sided model fixes, and what it still lacks.
  9. Field guide: numbers, a checklist, the core as code.
What does the paper claim about the left-to-right (autoregressive) habit?

Chapter 1

The Goal Is a Distribution, Not an Order

Learn the one rule every language model obeys, and see why it never named a direction

A weather forecaster says: “Rain on Monday is 50% likely. If it rains Monday, rain on Tuesday is 60% likely.” Multiply those two numbers and you get the chance of two wet days in a row: 30%.

You could also work backwards. Start from Tuesday, then ask about Monday. The factors differ, and the product is the same 30%. The order of the questions does not change the answer. Hold on to this picture, because the whole paper rests on it.

What a language model is trying to do

Think of all the text people write as a huge bag of sentences. Some sentences are common, and some are rare. The bag has a shape: a distribution, which gives every possible text a probability. Call the true one p_data. Nobody knows it exactly. We only hold samples from it.

A language model is our guess at that shape. Call the guess p_θ, where θ stands for the model’s weights. Training should make the guess close to the truth. The usual way to say that is maximum likelihood: choose the weights that make the real text look as unsurprising as possible.

maxθ
Search over weights θ for the setting that makes the next quantity as large as possible.
Epdata(x)
An average over real texts x drawn from the true distribution. In practice: an average over your training set.
log pθ(x)
The log of the probability the model gives to the real text x. A model that is not surprised by x scores high.
KL(pdata ‖ pθ)
The KL divergence: the extra surprise the model pays, on average, for not knowing the truth. It is zero only when the two distributions match. This is Eq. (1) in the paper.

The two sides of the arrow are the same goal seen from two sides. Making real text likely and making the model close to the truth are one task. The paper calls this the generative modeling principle.

The chain rule, and the order it hides

A sentence is long, and its probability is a tiny number. We cannot store a table with one entry per sentence. The chain rule of probability breaks one hard question into easy ones. For a text of L tokens, ask for the first token, then the second given the first, and so on.

pθ(x)
The model’s probability for the whole text x, a list of L tokens.
pθ(x1)
The chance of the first token, with nothing before it.
∏i=2L
Multiply the factors for token 2 up to token L.
pθ(xi | x1, …, xi−1)
The chance of token i given every token to its left. The bar reads “given”. This is Eq. (2) in the paper, the autoregressive form.

Look at what Eq. (2) chose. It chose the order 1, 2, 3, and so on. That is a convention. The chain rule holds for any order of the positions. Try it on a three-token toy.

Same number, any order

Each token is a or b. The table of eight joint probabilities is fixed. Pick a text and an order. The three factors multiply to the same joint probability every time.

Illustrative toy, not from the paper: eight joint probabilities that sum to 1 (aaa 0.20, aab 0.05, aba 0.10, abb 0.15, baa 0.05, bab 0.15, bba 0.10, bbb 0.20). Every factor is computed live from that table by summing the matching rows.

Take “a b b” in the order 1, 2, 3. The first factor is the chance that token 1 is a: 0.50. Given that, the chance token 2 is b is 0.25 out of 0.50, which is 0.50. Given both, the chance token 3 is b is 0.15 out of 0.25, which is 0.60. The product is 0.50 × 0.50 × 0.60 = 0.15.

Now pick 3, 2, 1. You get different factors, and the same 0.15. So the left-to-right chain is a choice of bookkeeping. It is not a law of nature.

What the paper takes from this

The introduction makes three moves. First, scalability comes from the interplay of the Transformer, the model size, the data size, and a property called Fisher consistency. In plain words: with enough data, a big enough network and perfect training, maximum likelihood recovers the true distribution. That promise comes from Eq. (1), not from Eq. (2).

Second, in-context learning and instruction following look like properties of any conditional generative model on structured language tasks. Third, the authors point out that diffusion transformers already scale well on images and video, which supports the same view.

There is also a hint of what is coming. Appendix A.2 describes an any-order autoregressive model (AO-ARM). It is trained on all orders at once, with one shared network and mask tokens for the missing positions. The paper proves that its loss equals the LLaDA loss in Chapter 3. That is why LLaDA reads in both directions even though its sampler never uses a fixed order.

In the toy device, the order 3, 2, 1 gives different factors from 1, 2, 3 but the same product. What does this tell you?

Chapter 2

The Forward Process: Hiding Words at Random

Turn a clean sentence into a partly hidden one with a single dial, and see why the dial is drawn fresh each time

You print a sentence on a sheet of paper. Then you drop ink on the sheet, one drop on each word, at random. After a few drops, some words are hidden. After many drops, all of them are. The sheet goes from readable to blank.

The forward process is exactly that, in math. It is called “forward” because it moves from clean text toward nothing. A model never runs it at test time. We use it to make training examples: a clean sentence goes in, and a damaged copy comes out.

One dial, one coin per token

The dial is a number t between 0 and 1. Call it the mask ratio, or the “time” of the process. At t = 0 nothing is hidden. At t = 1 everything is. In between, each token flips its own coin. With probability t it becomes M, and with probability 1 − t it stays.

The coins are independent. One token’s fate does not change another’s. That makes the math easy, because the probability of a whole damaged sentence is a product over tokens.

qt|0(xt | x0)
The chance of seeing damaged text xt when the clean text was x0 and the dial is at t.
∏i=1L
Multiply over all L positions. The product is allowed because the coins are independent. This is Eq. (7).
qt|0(xti | x0i)
The rule for one token i. The superscript i picks the position. This is Eq. (8).
1−t, t
Keep the token with chance 1 − t. Replace it with the mask M with chance t. Nothing else can happen: a token never turns into a different word.

Play with the dial. The device uses one fixed random number per word. A word is hidden when its number is below t. So when you raise t, hidden words stay hidden, and new ones join them. Press New draw to get fresh numbers.

Turn the mask dial

Drag t from 0 to 1. Purple M chips are hidden. The line below plots the expected share hidden, which is t itself, and your sentence as a dot.

0.50

Illustrative: the twelve words and the random numbers are made up, and seeded so the page looks the same on every visit. The rule (each token hidden with probability t, independently) is the paper’s Eq. (8). The 15% marker is the fixed ratio that BERT uses (Sec. 2.1).

At t = 0.50 you expect 6 of 12 words hidden, but any one draw can land on 4 or 8. This spread is real. With few tokens, the actual share of masks wanders from t. Appendix A.2 says the loss that uses independent coins needs over 1000 Monte Carlo draws (repeated random masks, averaged) to settle for evaluation. A second form, which hides exactly l tokens, needs only 128. We meet that second form again in Chapter 3.

Why the dial is not fixed

You may know BERT, an older model that also hides words and learns to fill them. BERT hides a fixed share, about 15%. LLaDA draws t from a uniform distribution on [0, 1] for every training sequence. Sometimes it hides 5% of a sentence. Sometimes it hides 95%.

The paper says this “subtle difference” has large consequences at scale. Here is why. At generation time, LLaDA starts at t = 1, with every word hidden, and walks the dial down to 0. To do that, the model must know how to fill masks at every level of damage. A model trained only at 15% would not know what to do with a blank page.

There is a second reason. The varied ratio makes the loss a bound on the true likelihood (Chapter 3). A fixed ratio gives no such link. The paper also notes that MaskGIT, an image model, used a heuristic loss without the 1/t factor and had no tie to maximum likelihood.

Why the schedule is a straight line

Image diffusion has a noise schedule, a rule for how fast noise grows. LLaDA’s schedule is the simplest one: the mask chance grows linearly with t. The authors give a reason in Appendix A.1. They assume the information in a text is proportional to its number of tokens on average. So losing information at a steady rate means hiding tokens at a steady rate.

One more fact is worth keeping. At t = 1 every token is M, so x1 is a single known point: the fully masked sequence. This is the clean starting line for generation. It needs no sampling and no special data. You always begin from the same blank page.

Why does LLaDA draw a new mask ratio t for every training sequence, instead of fixing it at 15% like BERT?

Chapter 3

The Mask Predictor and Its Loss

Read what the network sees and predicts, then see why its loss divides by t

A teacher hands you a worksheet: a paragraph with some words blanked out. Your job is to write every missing word. The teacher marks only the blanks. Words that were printed are not marked, because copying them is free.

That worksheet is one training example for LLaDA. The student is the mask predictor: a network that takes a partly hidden text and, for every hidden position, gives a probability for each word in the vocabulary. Write it pθ(· | xt).

What goes in, what comes out

The input is xt, a list of L token ids in which some ids are the mask id. For the 8B model, L is 4096 in pre-training. The output has one row per position. Each row holds V scores, one per vocabulary word. Here V is 126,464. After a softmax, each row is a probability distribution.

The network is an ordinary Transformer with one change. A GPT-style Transformer hides future tokens with a causal mask, so each position can look left only. LLaDA removes that mask. Every position can look at every other position. This is the bidirectional reading from Chapter 0.

The paper builds it like LLaMA: RMSNorm for stable training, SwiGLU for the feed-forward layers, and RoPE for position. One more choice is worth a note. LLaDA uses plain multi-head attention, with 32 key and value heads, instead of the grouped version (8 heads) in LLaMA3. The reason is that LLaDA does not use a KV cache, the stored keys and values that save work for a left-to-right model. With no cache to shrink, grouping buys nothing. Attention then holds more weights, so the paper trims the feed-forward width from 14,336 to 12,288 to keep the total near 8 billion (8.02B against 8.03B for LLaMA3).

Does the network need to be told t? No. The number of M tokens already tells it how damaged the input is. Appendix A.1 shows the best prediction depends only on the unmasked tokens, so the model is time-free: xt goes in, and nothing else.

The loss

We want the predicted word at each masked position to match the original. The measure is cross-entropy: the negative log of the probability the model gave to the correct word. If the model gave the right word 0.9, the loss is 0.105. If it gave 0.1, the loss is 2.30.

L(θ)
The loss to minimise. This is Eq. (3) in the paper.
Et, x0, xt
Average over the random dial t (uniform on 0 to 1), over clean texts x0, and over the random masks xt. In training this is one random draw per sequence.
1/t
A weight that grows as fewer tokens are hidden. The next section explains it.
∑i=1L
Add up over all positions in the sequence.
1[xti = M]
The indicator: 1 if position i is hidden, 0 if not. It switches off the loss on printed words.
log pθ(x0i | xt)
The log probability the model gives to the true word at position i, after reading the damaged text.

The paper then states Eq. (4): this loss is an upper bound on the model’s negative log-likelihood. In symbols, −E[log pθ(x0)] ≤ L(θ). Pushing the loss down therefore pushes the true likelihood up. That one line is what ties LLaDA back to the goal in Chapter 1. The proof is in the cited works (Shi, Sahoo and Ou), and the paper does not repeat it.

Why divide by t?

Here is the reason, with a worked example. Say a sentence has 12 tokens, and the model’s loss on each one is a fixed number. Add them all and you get 12.7. That is the total cost of getting the whole sentence right.

At t = 0.25, about 3 tokens are hidden. Say their losses are 2.3, 0.4 and 0.9, which add to 3.6. At t = 0.75, about 9 are hidden, and the sum is near 9.5. The raw sums change a lot with t, only because more tokens are inside the sum.

Divide by t. Then 3.6 / 0.25 = 14.4, and 9.5 / 0.75 = 12.7. Both land near the full-sentence 12.7. On average, the hidden share is t, so the sum is about t times the total, and dividing by t restores the total. With the weight, every mask ratio contributes on the same scale. Without it, the loss would mostly come from heavily masked examples.

Cancel the shrink

Pick t, then press Draw 300 masks. Dots show the average of 300 random masks. The yellow line is the raw sum. The warm line is the sum divided by t.

0.25

Illustrative toy: twelve per-token losses (0.4, 1.1, 2.3, 0.3, 0.9, 2.1, 0.4, 0.8, 2.6, 0.5, 0.7, 0.6, total 12.7) held fixed. In a real model the loss of a token rises as more of its neighbours are hidden, so the weighted loss is not flat. The 1/t factor is the paper’s Eq. (3).

In the real model each token’s loss does change with t, because a token with more hidden neighbours is harder to guess. So the weighted loss is not flat. It rises toward t = 1. The weight still does its job: it makes the sum comparable across t, and it makes the loss a bound on the likelihood.

Algorithm 1 in the appendix also divides by L, the sequence length, which only rescales the loss. The training loop is three lines: draw a text, draw t, mask the text, and take a gradient step on this loss.

In LLaDA’s loss, what does the 1/t factor do?

Chapter 4

Training, Step by Step

Follow one batch through pre-training and through fine-tuning, with the shape of every tensor

Picture a print shop that makes worksheets all day. A clerk picks a page of text. A machine blanks out some words, a different share each time. A student fills the blanks, and a marker counts the errors on the blanks only. Then the student gets feedback and the next page arrives.

LLaDA trains like that. There are two phases: pre-training on a huge pile of raw text, then supervised fine-tuning (SFT) on prompt and answer pairs. The code for both is nearly the same.

Pre-training, one batch

The corpus has 2.3 trillion tokens. It is about 61% English, 28% code and 11% Chinese, plus math and multilingual text. Cleaning included PDF text extraction, removal of duplicates, filtering of harmful content, and a fine-tuned BERT model that scores quality. The authors say they used no special tricks beyond the usual recipe, and that data mixes were set with scaled-down autoregressive models.

Documents are joined and cut into rows of exactly 4096 tokens. In 1% of cases, the row gets a random length drawn uniformly from 1 to 4096. This helps the model handle texts of any length later.

  1. Draw a batch. The batch holds 1280 rows. The tensor x0 has shape [1280, 4096]: 5,242,880 token ids.
  2. Draw t. Each row gets its own t from a uniform distribution on (0, 1]. Shape [1280].
  3. Mask. Each token becomes the mask id with chance t. The result xt still has shape [1280, 4096].
  4. Predict. The Transformer returns logits of shape [1280, 4096, 126464]. Each position holds one score per vocabulary word.
  5. Score. Take the log probability of the true token at each masked position, add them up, and divide by t. Positions that were not masked contribute zero.
  6. Update. Compute the gradient and take an AdamW step.

That is Algorithm 1 from the paper. One sequence of 4096 positions and 126,464 vocabulary words makes about 518 million logits. A local batch of only 4 rows sits on each GPU, which shows how big the logit tensor is.

The learning rate follows a Warmup-Stable-Decay shape. It climbs from 0 to 4 × 10−4 over the first 2000 iterations. It stays there for 1.2 trillion tokens. Then it drops to 1 × 10−4 for the next 0.8 trillion tokens. Over the last 0.3 trillion it slides down to 1 × 10−5. The optimizer is AdamW with weight decay 0.1. The 8B run was done once, with no tuning. The paper reports a cost of 0.13 million H800 GPU hours.

Fine-tuning, one batch

Pre-training gives a model that continues text. SFT teaches it to answer. Each example is a pair (p0, r0): a prompt and a response. The rule is simple. Leave the prompt alone, and mask only the response.

LSFT
The fine-tuning loss. This is Eq. (5) in the paper.
E
Average over prompt and response pairs, over t, and over the random masks of the response.
1/t
The same weight as in pre-training.
∑i=1L′ 1[rti = M]
Sum over the L′ response positions that are masked. L′ changes from pair to pair.
log pθ(r0i | p0, rt)
The model reads the clean prompt and the damaged response, and scores the true response token.

This matches pre-training exactly. Glue p0 and r0 into one clean sequence, and the masks happen to fall only on the response half. So the same code runs both phases. The step through below shows both.

Build a training example

Choose pre-training or fine-tuning, then press Next step four times. Watch where the masks may land, and which positions the loss reads.

Illustrative: twelve tokens, t fixed at 0.5 and the masks drawn from fixed random numbers. The shapes at full size are the paper’s (L = 4096, V = 126,464, batch 1280). The 518 million figure is 4096 × 126,464.

Two details that make answers the right length

A fine-tuning batch needs rows of equal length, but answers differ. The fix is padding with a special end-of-sequence token, |EOS|. Short pairs get extra |EOS| tokens on the right. The padding counts as part of the response, so it is masked and scored like any other token.

This is a clever trick. The model learns that after the answer ends, the right thing to write is |EOS|, again and again. At sampling time, the |EOS| tokens are cut off. So the model decides the length of its own answer by choosing where |EOS| begins.

Multi-turn chats get one more rule. A dialogue of n turns becomes n single-turn pairs. Pair k has all earlier turns inside its prompt. The training code picks one pair at random. That gives the model its chat memory with no new machinery.

The SFT set has 4.5 million pairs: 1 million written by people and 3.5 million made by other models. The run is 3 epochs. The rate rises from 0 to 2.5 × 10−5 in 50 iterations, stays flat, and falls to 2.5 × 10−6 over the last 10% of iterations. Batch size is 256. Like pre-training, it was run once without tuning.

In supervised fine-tuning, how does LLaDA treat the prompt, and how does it learn when to stop?

Chapter 5

The Reverse Process: Writing by Remasking

Turn a blank page of M tokens into an answer, and see why the order of filling matters

A crossword solver starts with an empty grid. She does not fill it in reading order. She fills the clues she is sure of first. Those letters then make the hard clues easier. By the end, the grid is full, and the last clues were the ones she could only solve with help.

LLaDA writes the same way. The reverse process runs the dial from t = 1 (every position is M) down to t = 0 (no M left). At each stop, the mask predictor guesses every hidden word. The sampler keeps the guesses it trusts and hides the rest again.

The rule for one step

The paper defines the exact reverse rule in Appendix A.1. Suppose the dial moves from t down to s. Take one position.

Why s / t? Look back at the forward process. A token was hidden with probability t at time t and with probability s at time s. Given that it is hidden at t, the chance it is still hidden at s is s / t. The reverse rule must undo exactly that. Then the reverse process follows the forward one in distribution, and the final text is a true sample from the model.

In practice the code does it in two stages. First, predict all hidden positions at once. Then re-hide a share s / t of those fresh predictions. What is left is rs. This is what “remasking” means.

Which predictions to re-hide?

In principle, the choice should be random. It keeps the process exactly faithful to the math. Algorithm 4 in the paper does this. The authors found a better practical rule, borrowed from the image model MaskGIT: low-confidence remasking. The model’s confidence at a position is the probability it gave to the word it predicted. Algorithm 5 re-hides the predictions with the lowest confidence and keeps the highest.

Count it out for a 12-word answer (the answer length L is a setting you choose) and N = 4 steps. The dial stops at t = 1, 0.75, 0.5, 0.25 and ends at 0. After each step the number of fixed tokens is nun = ⌊L(1 − s)⌋, so 3, 6, 9 and 12. Each step fixes 3 more words. With N = 12, each step fixes 1. With N = 1, one pass fixes all 12 and nothing is rechecked.

In the device, a made-up predictor gives each hidden word a confidence. The confidence goes up as more neighbours get fixed. The number 72 is special: it depends on 48 and 24 being fixed first. Run it with random remasking and low-confidence remasking, and compare when 72 is committed.

Fill the grid

Choose a remasking rule and a number of steps. Press Next step or Run all. Each chip shows the pass that fixed it. A red ring marks a word fixed at confidence under 0.40.

4

Toy: the confidences are made up (a word’s confidence is its base value plus a share of the remaining gap, equal to the share of words already fixed, and 72 stays at 0.12 until 48 and 24 are fixed). The two rules and the count ⌊L(1 − s)⌋ are the paper’s Algorithms 4 and 5. Random order changes with each press of Reset.

Set N to 4 and run both rules. Low-confidence remasking fixes 72 in the last pass, after its two inputs. Random remasking may fix it early at confidence 0.12. A real model would then have to guess a sum before it saw the numbers. That is the intuition. The paper measures it.

What the paper measured

Table 9 compares the two rules on LLaDA 8B Base, with generation length and steps both set to 256. Low-confidence wins on every benchmark, and the gap on GSM8K is huge.

Remasking ruleBBHGSM8KMathHumanEvalMBPP
Random32.121.39.211.621.0
Low-confidence45.070.030.332.940.2

The authors guess that low-confidence remasking acts like the annealing trick used in autoregressive models. Annealing means lowering the temperature, which makes output safer and less varied. Re-hiding shaky guesses has the same flavour. The model commits only to words it is sure of. The cost is less diversity.

A second hyperparameter is the answer length. The sampler starts from a mask sequence of a fixed size, so you must pick L before you begin. Chapter 6 shows that the results barely depend on this choice.

With a 12-word answer and N = 4 steps, how many words are fixed after each pass, and which guesses are kept under low-confidence remasking?

Chapter 6

Samplers and Length: One Model, Many Ways to Write

Compare left to right, in blocks, and all at once, and see what each knob does to the score

You have a worksheet with 64 blanks. You can fill it row by row from the top. You can fill one block of 8 blanks, then the next block. Or you can scan the whole page and fill the easiest blanks first. The worksheet is the same in every case. Only your plan changes.

Here is a useful fact about LLaDA. The plan is a choice made at sampling time. Nothing in training fixes it. The same weights can write in any of these ways, with no extra training. Appendix B.4 compares four plans.

Four plans

The block length L′ is a dial between two extremes. L′ = 1 is autoregressive writing. L′ = whole answer is pure diffusion. Every setting in between mixes the two.

Explore the scores. The base model uses five benchmarks, with block lengths 2, 4, 8 and 32. The instruct model uses seven benchmarks, with block length 32 for efficiency.

Compare the samplers

Choose a model, then a benchmark. Bars are the paper’s scores for each sampler. The best bar is green.

All numbers are from the paper: Table 7 (LLaDA 8B Base; generation length 1024 for the fixed-length rows) and Table 8 (LLaDA 8B Instruct; block length 32). The instruct block diffusion row is the original dynamic-length form; the other rows have a fixed length.

Three patterns stand out. First, block diffusion beats autoregressive sampling on the base model, and the score rises as blocks get longer. Second, the fixed-length version (block diffusion LLaDA) is better still, and it hardly cares about L′. Third, pure diffusion has the best overall score.

The instruct model breaks the autoregressive plan

Switch the device to the instruct model and pick GSM8K. Autoregressive sampling scores 0. The reason is specific. Every SFT answer is a full sentence that ends before the padding. Given a length, the instruct model tries to write a complete answer inside it. Asked to write one token at a time, it ends the answer at once. The base model avoids this, because its pre-training text is cut off at random lengths and it can continue from any prefix.

The |EOS| padding from Chapter 4 causes a second problem, even for pure diffusion. Many masked positions near the end get a high-confidence guess of |EOS|. Low-confidence remasking then keeps them early, and the answer comes out too short. The authors set the confidence of |EOS| to zero for HumanEval, MBPP, GSM8K, Math and GPQA. This keeps the share of |EOS| tokens in a normal range. Without it, the paper reports extremely short outputs and lower scores.

Block diffusion LLaDA gets round the problem in another way. It reaches 78.6 on GSM8K and 42.2 on Math, against 69.4 and 31.9 for pure diffusion in Table 2. The GSM8K figure uses block length 8. The authors credit the |EOS| padding for the gap.

Length is a setting, and it barely matters

The sampler starts with a mask sequence of a length that you pick. Is the answer sensitive to that choice? Table 10 says no. With 256, 512 or 1024 positions on LLaDA 8B Base, the scores stay close.

Generation lengthBBHGSM8KMathHumanEvalMBPP
25645.070.030.332.940.2
51250.470.830.932.939.2
102449.770.331.435.440.0

The explanation is in the training. Both phases use variable lengths: the 1% random-length rows, and the |EOS| padding. The model knows how to stop early. A larger canvas simply holds more |EOS|. The paper still lists the fixed length as a limitation and hopes for an adaptive one.

Guidance: one more lever

Appendix A.2 adds classifier-free guidance (CFG), a trick from image diffusion. It runs the mask predictor twice, once with the prompt and once with the prompt replaced by masks. It then pushes the output toward what the prompt adds: p̃(r0 | p0, rt) ∝ pθ(r0 | p0, rt)1+w / pθ(r0 | m, rt)w. The knob w sets the strength. On ARC-C it lifts LLaDA 8B Base from 45.9 to 47.9, and on Hellaswag from 70.5 to 72.5. The paper keeps CFG out of the main tables, so the comparison with autoregressive models stays fair.

LLaDA 8B Instruct scores 0 on GSM8K when sampled left to right, one token at a time. What is the paper’s explanation?

Chapter 7

Scaling and Benchmarks: The Race Against LLaMA

Read what each figure and table shows, what it leaves out, and how far the claim reaches

Two runners enter a race. One trained for 15 trillion steps and the other for 2.3 trillion. Even if the second runner finishes close, you learn two different things. You learn she is fast. You also learn that the comparison is not clean. Both facts matter when you read this paper’s results.

The authors answer three questions with numbers. Does LLaDA scale as compute grows? How does the 8B model compare with LLaMA on standard tests? How fast is it? We take them in order.

Question 1: does it scale? (Figure 3)

Figure 3 plots six tasks against pre-training compute. The tasks are MMLU, CMMLU, ARC-C, PIQA, GSM8K and HumanEval. Compute is counted in FLOPs, the number of arithmetic operations spent on training. It runs from 1020 to 1023 FLOPs on a log axis. For each task there are two lines: LLaDA and an autoregressive baseline trained by the authors on the same data.

The paper counts compute with the common formula 6ND: six times N, the non-embedding parameters, times D, the training tokens. For LLaDA 8B, N is 6.98 billion and D is 2.3 trillion. So 6 × 6.98 × 109 × 2.3 × 1012 = 9.6 × 1022 FLOPs, close to 1023.

What the figure shows: LLaDA’s curves track the autoregressive baselines overall. On MMLU and GSM8K, LLaDA climbs faster. On PIQA, the weakest task, the gap narrows with scale. The authors choose not to fit curves, because outliers would make a fit misleading.

The comparison has limits, and the paper says so. At the 1B scale, the two models share architecture, data and settings. At larger scale, the baselines differ slightly in size: a 7B ARM against the 8B LLaDA. Direct comparisons stop below 1023 FLOPs, because the budget went to the largest LLaDA. The authors also note an earlier study (Nie et al.) that found masked diffusion needs about 16 times more compute than an autoregressive model for the same likelihood. They argue that likelihood is an indirect measure of downstream skill, and that LLaDA optimises only a bound, so the two are not directly comparable.

Question 2: how does the 8B model score? (Tables 1 and 2)

Table 1 compares pre-trained models under one protocol: LLaDA 8B Base (2.3T tokens), LLaMA3 8B Base (15T) and LLaMA2 7B Base (2T). Use the device to see the bars.

Read the tables

Choose base or instruct models, then a benchmark. The longest bar wins. The gap between LLaDA and LLaMA3 is printed in the read-out.

All scores are from the paper’s Tables 1 and 2, in each table’s own few-shot setting. LLaMA models were re-evaluated by the authors under one protocol. Instruct LLaDA used SFT only. The LLaMA instruct models also had reinforcement-learning alignment.

Read Table 1 as a whole. LLaDA 8B Base beats LLaMA2 7B on nearly all of the 15 tasks. It is on par with LLaMA3 8B overall. It leads on math (GSM8K 70.3 against 48.7) and on Chinese (CMMLU 69.9 against 50.7). It trails on BBH, Hellaswag and PIQA. The authors link the strong and weak spots to data differences, and say these are hard to judge because the LLaMA data is closed.

They also check for leakage on GSM8K. The scaling curve already shows LLaDA ahead of its own baseline on GSM8K, which used the same data. A second check on unseen problems follows in Chapter 8.

Table 2 compares post-trained models. LLaDA used only SFT. The others also used reinforcement learning. LLaDA 8B Instruct lands a little behind LLaMA3 8B Instruct on most tests, and ahead on a few (ARC-C 88.5 against 82.4, Math 31.9 against 29.6). MMLU fell after SFT, from 65.9 to 65.5. The authors blame the quality of the SFT data.

Question 3: how fast and how big? (Figure 5, Table 11)

The sampler takes N steps for an answer of L tokens, so it fixes L / N tokens per pass. Fewer steps mean faster output and lower quality. Figure 5 sets L = 256 and N = 32, 64, 128 and 256, which is 8, 4, 2 and 1 tokens per pass. It measures throughput in tokens per second on one A100-80GB, with batch size 1 and bfloat16.

On GSM8K and Math, LLaDA matches LLaMA3 8B at 1.5 and 1.8 times the throughput, even though LLaMA3 uses a KV cache and LLaDA uses no inference tricks. On HumanEval the two match when throughput is matched. On MBPP, LLaDA falls behind. The KV cache helps LLaMA3 less on HumanEval, because the prompts are short: 132 tokens on average, against 894 for GSM8K.

Memory is close. For 512 input and 512 output tokens, LLaDA uses 17.03 GB, LLaMA3 without a cache 16.70 GB, and with a cache 16.32 GB. At 2048 output tokens, LLaDA 18.52 GB, LLaMA3 without a cache 20.00 GB, with a cache 16.73 GB. The authors state that their goal is not a model faster than autoregressive ones. They want to show that diffusion can reach these skills at scale.

Which reading of Table 1 matches the paper?

Chapter 8

The Reversal Curse, and What Is Still Missing

See what a model that reads both ways can do on a backwards question, then list what the paper leaves open

Ask a friend: “Who wrote the line that comes after ‘Two roads diverged in a yellow wood’?” She answers easily. Now ask for the line that comes before it. She stumbles. The facts are the same, and the direction changed. Many language models behave like this friend.

This failure has a name: the reversal curse (Berglund et al.). A model trained on text of the form “A is B” often fails to answer “B is A”. The paper counts it as a sign that the left-to-right habit generalises poorly.

The test

The authors follow a protocol from Allen-Zhu and Li. They build 496 pairs of consecutive lines from famous Chinese poems. The model gets one line and must write the next line (forward) or the previous line (reversal). There is no fine-tuning. Two examples from Appendix B.9, translated: given “窈窕淑女”, write the next line, and the answer is “君子好逑”. Given “不拘一格降人才”, write the previous line, and the answer is “我劝天公重抖擞”.

An autoregressive model that read these poems in order always saw the earlier line first. It learned many forward steps and few backward ones. LLaDA saw masks everywhere, so a line with its neighbour hidden is a routine training case.

Forward against reversal

Choose a test. Warm bars are the forward task, and blue bars the reversed one. The gap between each pair is printed below.

All numbers are from the paper. Table 4: 496 poem pairs, zero-shot. Table 12: 100 synthetic math problems per step count, base models, arithmetic modulo 5, four-shot with a system prompt, from the iGSM generator of Ye et al.

The poem table is clear. GPT-4o scores 82.7 forward and 34.3 in reversal, a gap of 48.4 points. Qwen2.5-7B Instruct scores 75.9 and 38.0, a gap of 37.9. LLaDA 8B Instruct scores 51.8 and 45.6, a gap of only 6.2. LLaDA is below both on the forward task, which the authors expect, since those models used far more data and compute. In the reversal task, LLaDA wins by a wide margin.

Why the symmetry appears

Recall the any-order autoregressive model from Chapter 1. It learns the chance of any token given any subset of the others. The paper proves, in Appendix A.2, that this objective equals the LLaDA loss. A model trained on masks at every ratio therefore learns conditionals in all directions, even though its sampler never uses them as a fixed order.

“Write the previous line” is one such conditional: predict the left tokens given the right ones. For an autoregressive model it is an unnatural question. For LLaDA it is another mask pattern. The authors add that they designed nothing special for reversal. They say LLaDA treats tokens uniformly, with no inductive bias toward a direction, which gives balanced results.

The authors tie their math lead to the same flexibility, as a hypothesis (Sec. 3.1). Appendix B.8 tests unseen math problems from iGSM, a generator of grade-school problems with a controlled number of steps. At 4, 5 and 6 solution steps, LLaMA3 8B Base scores 38, 35 and 34, and LLaDA 8B Base scores 64, 41 and 44. This is the authors’ check against leakage, since the iGSM problems are new. It does not show why LLaDA wins. The reason stays a hypothesis.

How far does the evidence reach?

A careful reader should keep the scope in mind. The reversal result rests on one task, 496 Chinese poem pairs. The iGSM check uses 100 questions for each step count. Both are small. The scaling comparison stops below 1023 FLOPs. These notes are ours, not the authors’, and they sit beside the claims the paper makes itself.

The paper’s own limitations section lists these open items:

The last point connects to the lecture this paper belongs to. Multimodal use is the reason it sits in a course on multimodal AI. Masked token prediction is already the engine of several image generators, and the paper names MaskGIT and Muse as parallel work.

Why does LLaDA show a much smaller gap between forward and reversal poem completion than GPT-4o?

Chapter 9

Field Guide: LLaDA on One Page

Review the argument, keep the numbers and the code, and find where to go next

You can now rebuild the paper from memory. The authors ask whether the left-to-right habit is the source of what large language models can do. They build LLaDA to test it, and they get a model that competes with LLaMA3 8B on many tests and does not suffer the reversal curse. Here is the whole story in one place.

The one-paragraph summary

A language model must fit the true distribution of text by maximum likelihood, and the left-to-right chain is only one way to write that down. LLaDA uses a masked diffusion model instead. The forward process hides each token with probability t, with t drawn uniformly from 0 to 1. A Transformer with no causal mask, the mask predictor, learns to restore the hidden tokens. Its loss counts only the hidden positions and divides by t, which makes it an upper bound on the negative log-likelihood. Fine-tuning keeps the prompt clean and masks the response, with |EOS| padding that teaches the length. To write, LLaDA starts from a fully masked response, predicts every hidden token each step, and remasks the least confident guesses. The paper trains an 8B model on 2.3 trillion tokens, tests it against LLaMA, and shows balanced forward and reversal scores.

The numbers that matter

WhatNumberWhy it matters
Pre-training of LLaDA 8B2.3T tokens; 0.13M H800 GPU hoursSimilar cost to an autoregressive model of the same size and data
Fine-tuning4.5M pairs (1M human, 3.5M synthetic); 3 epochsPlain SFT, no reinforcement learning
Model shape32 layers, width 4096, 32 heads, FFN 12,288, vocabulary 126,464; 8.02B parameters (6.98B non-embedding)Same size class as LLaMA3 8B
Sequence length4096 in pre-training; 1% of rows get a random lengthTeaches variable-length writing
Compute6 × 6.98B × 2.3T = 9.6 × 1022 FLOPsThe scale of the comparison with autoregressive baselines
Mask ratio and loss weightt ~ U(0, 1]; weight 1/tMakes the loss a bound on likelihood
Remasking, GSM8Krandom 21.3; low-confidence 70.0Which guesses you keep matters a great deal
Samplers, base GSM8Kautoregressive 63.1; pure diffusion 70.3The sampler is chosen at run time
Base vs LLaMA3 8BMMLU 65.9 vs 65.4; GSM8K 70.3 vs 48.7; CMMLU 69.9 vs 50.7; BBH 49.7 vs 62.1On par overall; strong in math and Chinese
Speed at matched quality1.5 times (GSM8K), 1.8 times (Math) the throughput of LLaMA3 8B with a KV cacheSteps trade quality for speed
Poem reversalLLaDA 45.6 against GPT-4o 34.3 and Qwen2.5-7B 38.0Symmetric reading; forward score is lower (51.8)
iGSM, 4 / 5 / 6 stepsLLaDA 64 / 41 / 44; LLaMA3 38 / 35 / 34A check on unseen math

Checklist: can you do these from memory?

The core as code

Here is the whole method in about forty lines of NumPy. It assumes a model that maps token ids of shape [B, L] to logits of shape [B, L, V], and the usual softmax helpers. It follows Algorithms 1, 2 and 5 from the appendix.

pythonimport numpy as np
MASK = -1                                  # a reserved id; shown as M in this lesson

def forward_mask(x0, t, rng):
    """Eq. 7 and 8: hide each token with probability t, independently."""
    hide = rng.random(x0.shape) < t[:, None]         # [B, L] booleans
    return np.where(hide, MASK, x0), hide

def pretrain_loss(model, x0, rng):
    B, L = x0.shape                                  # [1280, 4096] in the paper
    t = 1.0 - rng.random(B)                          # t in (0, 1], one per row
    xt, hide = forward_mask(x0, t, rng)
    logits = model(xt)                               # [B, L, V], no causal mask, no t input
    logp = log_softmax(logits)                       # softmax over the vocabulary V
    nll = -np.take_along_axis(logp, x0[..., None], -1)[..., 0]   # [B, L]
    return ((nll * hide).sum(1) / t / L).mean()      # Eq. 3; the 1/L is Algorithm 1

def sft_loss(model, prompt, resp, rng):              # same code, prompt stays clean
    x0 = np.concatenate([prompt, resp], axis=1)      # resp is padded with EOS
    t = 1.0 - rng.random(len(x0))
    xt, hide = forward_mask(x0, t, rng)
    hide[:, :prompt.shape[1]] = False                # never mask the prompt
    xt = np.where(hide, MASK, x0)
    logp = log_softmax(model(xt))
    nll = -np.take_along_axis(logp, x0[..., None], -1)[..., 0]
    return ((nll * hide).sum(1) / t / resp.shape[1]).mean()      # Eq. 5

def generate(model, prompt, L=256, N=64):
    P = len(prompt)
    x = np.concatenate([prompt, np.full(L, MASK)])   # the response starts fully masked
    for k in range(1, N + 1):                        # t goes from 1 down to 0
        probs = softmax(model(x[None])[0, P:])       # [L, V], every position at once
        guess, conf = probs.argmax(-1), probs.max(-1)
        masked = x[P:] == MASK
        conf = np.where(masked, conf, np.inf)        # fixed words are never revisited
        keep = np.argsort(-conf)[: int(L * k / N)]   # the surest L(1 - s) positions
        new = np.where(masked, guess, x[P:])
        out = np.full(L, MASK)                       # remask everything else
        out[keep] = new[keep]
        x[P:] = out
    return x[P:]                                     # cut at the first EOS afterwards

Where it sits in the field

The paper places LLaDA among several lines of work. Continuous diffusion on word embeddings scaled poorly: a 1B model may need 64 times the compute of an autoregressive one (Gulrajani and Hashimoto). Discrete diffusion began with Austin et al. in 2021. Lou et al. showed masked diffusion matching autoregressive models at GPT-2 scale. Shi, Sahoo and Ou gave the theory behind the loss in Chapter 3. Nie et al. (the same group) studied scaling laws. Gong et al. converted an autoregressive model into a diffusion one. Block diffusion (Arriola et al.) blends the two, and Mercury is a closed-source diffusion model for code. On images, MaskGIT and Muse already predict masked tokens. LLaDA’s contribution is scale and a clean test of the claim.

Keep going

The takeaway. The skills of a large language model come from fitting the data distribution at scale, and the left-to-right order is one way to do it. Hide tokens at every ratio, train one Transformer to restore them, and write by fixing the surest words first. The same weights then chat, learn from examples, and read the poem in either direction.

Credit

This lesson teaches Large Language Diffusion Models by Shen Nie, Fengqi Zhu, Zebin You, Xiaolu Zhang, Jingyang Ou, Jun Hu, Jun Zhou, Yankai Lin, Ji-Rong Wen and Chongxuan Li, of Renmin University of China and Ant Group (NeurIPS 2025, arXiv 2502.09992). All figures, tables and quotes come from that paper. The toy devices are marked as illustrative. Any mistake in the retelling is ours.

Now press Present or Teach and explain LLaDA out loud, from memory: why the order does not matter, what the forward process hides, why the loss divides by t, and how a blank page becomes an answer. Then go back to the two writers at the top, set LLaDA to 12 steps and then to 1, and explain what changes.

LLaDA: Large Language Diffusion Models
Read the paper · Project page · MMAI lecture 10 · MIT MMAI schedule · Back to Gleams