What if an LLM could write the middle first?
When I watch a chatbot answer, I can read the first line while it’s still writing the second. That feels like a UI detail until I try to picture the reverse. What would it take for the model to fill in the middle of the
When I watch a chatbot answer, I can read the first line while it’s still writing the second. That feels like a UI detail until I try to picture the reverse. What would it take for the model to fill in the middle of the answer before it had finished the opening?
That’s how I think about the difference between autoregressive language models and diffusion language models. One builds a prefix. The other can work on several positions in a partially filled sequence. I find the difference easiest to see in the kind of code I’d ask a model to write.
The next token is an easy place to start
Suppose I give a model the start of a Python function and ask it to finish the body. A standard autoregressive (AR) decoder predicts the next token from the prompt and everything it has generated so far. It appends that token and repeats. If it names a variable total on one line, the next line can use the exact name it already picked.
I think of that as autocomplete in a loop. The model can stream each token as it goes, and a key-value (KV) cache lets it reuse attention keys and values from the prefix. A long answer still involves a long chain of decoding steps. Each one depends on the token the preceding step chose.
The middle gets interesting when the ending already exists
Now imagine my cursor is here:
def subtotal(prices):
# Fill in the missing line
return total
The return statement gives away one detail about the missing line. Whatever goes there should define total. A model with access to both sides of the gap can use that clue directly. This is called infilling, and AR models trained for fill-in-the-middle can do it too.
A masked diffusion language model takes the same idea further. During training, it sees sequences with some tokens hidden and learns to recover them from the visible context. At generation time, it can start with several masked positions, predict tokens for them in one pass, and then run another pass with some of those guesses filled in. Depending on the decoding method, it can leave uncertain positions blank or mask a previous guess again.
The bit I find most interesting is that guesses made together can disagree. Imagine the missing region spans two lines, one that assigns a variable and another that returns it. If both names are predicted in the same pass, the model could produce subtotal = sum(prices) and return total. Both look reasonable in isolation. The function breaks because they need to agree.
Another pass can help if the decoder revisits one of those choices. That extra pass also takes time. So when I hear that a model can predict multiple tokens at once, my first question is how much of that work survives to the final answer.
What the papers made me look at differently
ParallelBench looks at this dependency problem with tasks such as list operations, where several parts of an answer have to agree. The authors found that parallel decoding can lose quality when those dependencies are strong. I’d want examples like that in a benchmark for code or structured output. A throughput average would leave me wondering how often the resulting code actually runs. ParallelBench
One idea I like from Adaptive Parallel Decoding is to vary how many tokens the model fills at once. The paper uses a smaller AR model to help score whether proposed tokens fit together and reports higher throughput with little quality loss on its evaluated tasks. I’d want to see how often that approach can take bigger steps on my workload and what the extra scoring costs end to end. Adaptive Parallel Decoding
The training results gave me a separate question about which diffusion model I’d actually test. SEDD showed that discrete diffusion could be competitive with GPT-2 on reported language-modeling measures and could handle infilling. DiffuLLaMA and DiffuGPT explored starting from pretrained AR models and adapting them to diffusion. A separate scaling study found that different ways of corrupting the training text favored different trade-offs between model size and training data. Together, those results would make me check the training recipe alongside the decoding settings. SEDD · DiffuLLaMA and DiffuGPT · Scaling Behavior of Discrete Diffusion Language Models
What I’d try in a real project
| If I’m building… | Where I’d start |
|---|---|
| A chat interface or a tool that streams long answers | An AR model. I’d measure how soon the first useful text appears and how long the full response takes. |
| An editor that fills a gap in existing code | A fill-in-the-middle model. I’d compare an AR infilling model with a diffusion model and check whether the completed code passes its tests. |
| A tool that edits several known regions or fills a fixed layout | I’d try diffusion, then check how much refinement it needs and whether surrounding content stays intact. |
| A pipeline that outputs IDs or values that must agree across fields | I’d start with AR and measure cross-field consistency for both approaches. |
| A batch job where decoding time is the bottleneck | I’d compare both at the batch size I actually serve, including accelerator memory and throughput at the same quality target. |
For diffusion, I’d vary the number of refinement passes and how many tokens the decoder fills per pass. For something user-facing, I’d measure when the first usable output appears as well as when the whole response is ready. Those times can tell very different stories.
I’d start with the little Python example and make it harder. Add more gaps, put related names farther apart, then see how often the finished function runs and how long I had to wait. That’s the result I’d want before betting on parallel decoding in an editor.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.