Attention-Based Sampler for Diffusion Language Models

Yuyan Zhou, Kai Syun Hou, Weiyu Chen, James Kwok

TL;DR

Diffusion large language models (dLLMs) break the left-to-right chains of traditional autoregressive models, allowing us to generate text in any order—or even in parallel. The catch? Deciding which masked words to reveal first is actually an NP-hard problem, and our current guesswork leaves both accuracy and speed on the table. This paper proves mathematically that the secret to optimal generation order is already hiding inside the Transformer's attention matrix, leading to a training-free algorithm that makes dLLMs significantly faster and smarter.

What Problem Does This Paper Address?

Standard autoregressive language models (like GPT) write the way an old typewriter prints: strictly left-to-right, one token at a time. That creates a massive speed bottleneck and forces an unnatural constraint on tasks like coding or math, where the crux of an idea might appear at the end of a line rather than the beginning.

Diffusion LLMs (dLLMs) fix this by starting with a block of [MASK] tokens and iteratively unmasking them in whatever order makes the most sense. This raises a fundamental question: In what order should we unmask tokens to maximize the likelihood of generating the best sequence?

Right now, existing dLLMs rely on local, greedy heuristics—like unmasking whichever token has the highest predicted probability (confidence) or lowest uncertainty (entropy). While intuitive, these token-level guesses ignore global dependencies across the sequence, leading to suboptimal generation trajectories and degraded quality when decoding multiple tokens in parallel.

Methods

Instead of inventing another heuristic, the authors frame token-ordering as a formal optimization problem. They define the Permutation Dependency Gap (PDG): the difference between an "ideal" world (where predicting a token uses the context of all other tokens in the block) and reality (where the model only sees tokens unmasked so far).

Minimizing this gap directly is equivalent to the weighted linear ordering problem, which is NP-hard because every pair of tokens depends on their relative order. To make this tractable, the authors construct an optimal approximation based solely on a token's expected sampling rank. When the dust settles on the math, a remarkably clean rule emerges: you minimize the gap by unmasking tokens in descending order of their attention-matrix column sums.

Figure 1: Overview of the Attn-Sampler algorithm. Our approach dynamically determines the sampling order for a masked sequence by leveraging the self-attention mechanism. We compute the column sums of the attention matrix as a proxy for token importance; tokens with higher cumulative attention scores are prioritized and decoded earlier in the sampling process.

From this insight, the authors build Attn-Sampler, a training-free inference algorithm:

  • Sequential Sampling: Pass the masked sequence through the Transformer, remove the diagonal of the attention matrix (averaged across all layers and heads), sum the columns to get each token's "total attention" (how much other tokens attend to it), and unmask the highest-scoring token.
  • Parallel Sampling (Dynamic Attention Thresholding): Static top-$k$ or fixed-cutoff rules break down when sequence dependencies shift. Instead, Attn-Sampler splits masked tokens into high-confidence candidates (top probability $\ge \tau$, e.g., $0.9$) and low-confidence non-candidates. It finds the maximum attention score among the uncertain non-candidates and uses that number as a dynamic bar. Every high-confidence candidate whose attention score clears that bar gets decoded simultaneously.

Datasets

Because Attn-Sampler is entirely training-free, datasets are used strictly for evaluation across existing open-weight dLLMs (Fast-dLLM v2 1.5B & 7B, and LLaDA-1.5 8B). No new benchmarks are introduced; the authors test on four standard reasoning and coding suites:

  • Mathematical Reasoning: GSM8K and MATH.
  • Code Generation: HumanEval and MBPP.

Key Insights and Ideas

  • Attention column sums measure global "anchor" value: Summing a column of the attention matrix tells you how heavily the rest of the sequence relies on that specific token. Decoding high-column-sum tokens first plants the most important structural anchors early, giving subsequent predictions much richer context.
  • Why confidence and entropy samplers fall short: The authors prove mathematically that traditional confidence- and entropy-based samplers only pick the same optimal tokens as Attn-Sampler under hyper-strict conditions (e.g., ideal confidence equals 1, and error vectors align perfectly with negative confidence gradients). Because real-world generation violates these assumptions, local uncertainty heuristics inevitably make suboptimal choices.
  • Every layer and head counts: Ablation studies show that pulling attention solely from early layers yields mediocre results (82.26% on GSM8K using Layer 1), whereas averaging across all 28 layers and heads hits peak accuracy (84.23%). High-level semantic routing distributed throughout the whole network is vital for picking the right order.

Key Results

Attn-Sampler consistently beats six state-of-the-art sampling baselines (including Confidence, Entropy, Margin, Fast-dLLM, EB-Sampler, and KLASS) across all models and benchmarks.

  • Superior Accuracy: On Fast-dLLM v2 7B, sequential Attn-Sampler averages 57.67% across all four tasks—beating standard confidence sampling by +3.01% and the strongest baseline (entropy) by +1.10%, including a +2.44% jump on HumanEval. Parallel Attn-Sampler essentially ties sequential quality (57.66% average) and actually beats sequential on HumanEval (58.54%) and GSM8K (84.23%). Similar gains hold on LLaDA-1.5 8B and the smaller 1.5B model.
  • 3x Speedup Without Sacrificing Quality: On GSM8K (Fast-dLLM v2 7B), standard top-confidence sampling crawls at 35 tokens/sec (TPS) for 82.7% accuracy. Parallel Attn-Sampler hits 107 TPS (3.06$\times$ faster) while maintaining 82.6% accuracy. At 94 TPS, it pushes accuracy up to 84.2%, defining a dominant Pareto frontier over existing parallel samplers.
Figure 2: Comparison of throughput vs. ac- curacy across various parallel sampling meth- ods. Our Attn-Sampler defines a superior Pareto front compared to existing state-of-the-art paral- lel samplers.

Limitations and Future Work

Not explicitly discussed in a dedicated section by the authors. However, two structural boundaries are apparent from the formulation:

  • Simplified Theoretical Model: The mathematical proof connecting the Permutation Dependency Gap to attention column sums is derived using a first-order Taylor approximation on a single-layer, single-head Transformer—though empirical ablations confirm the principle scales cleanly when averaged across deep, multi-head architectures.
  • Hyperparameter Sensitivity: While the parallel threshold is dynamic, partitioning tokens into the initial candidate pool still relies on a static probability cutoff ($\tau$, varied between $0.7$ and $0.9$ to trade speed for accuracy). Exploring fully parameter-free thresholding or integrating attention-guided ordering into dLLM training could be natural next steps.

Summary updated

Abstract

Auto-regressive models (ARMs) have established a dominant paradigm in language modeling. However, their strictly sequential sampling paradigm imposes fundamental constraints on both inference efficiency and modeling flexibility. To address these limitations, diffusion-based large language models (dLLMs) have been proposed, offering the potential for parallel sampling and flexible language modeling. Despite these advantages, current dLLMs sampling strategies rely primarily on token level information, which fails to account for global sequence structure and often yields suboptimal results. In this paper, we study the sampling order selection problem from the perspective of log-likelihood maximization. We show that this problem is NP-hard and propose an optimal sampling-rank-based approximation that makes the objective computationally tractable. We further prove that the tractable objective is optimized by sampling tokens in descending order of their attention-matrix column sums. This finding provides a principled justification for attention-guided sampling and offers a theoretically grounded alternative to greedy search. We instantiate this theoretical insight in a new training-free sampling algorithm, termed Attn-Sampler, and further propose dynamic attention thresholding for practical acceleration. Extensive experiments across multiple benchmarks validate the effectiveness of our proposed method, demonstrating that it achieves superior generation quality while enhancing the sampling parallelism.
BibTeX
@inproceedings{zhou2026attention,
  author = {Yuyan Zhou and Kai Syun Hou and Weiyu Chen and James Kwok},
  title = {{Attention-Based Sampler for Diffusion Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=lspyzSyqOj},
}
Figure