CURE: Counterfactual Unsafe-token Re-masking for Diffusion Large Language Model Test-time Alignment

Lichao Wang, Mingquan Zhang, Xian Zhang, Juntao Dai, Chi Harold Liu, Yaodong Yang, Jingwei YiNeurIPS 2026

TL;DR

Unlike traditional chatbots that write left-to-right, Diffusion Language Models (DLMs) generate text all at once by iteratively filling in blanks—meaning innocent-looking words like "the" or "by" appearing early on can quietly steer the whole response toward harmful compliance. This paper introduces CURE, a surgical test-time defense that spots these "gateway" tokens mid-generation, erases them, and lets the model naturally rewrite its way to a safe refusal. Better yet, it drops jailbreak success rates to near zero while adding just 0.7% in compute overhead, without ever modifying the base model.

What Problem Does This Paper Address?

Standard causal language models (like GPT) commit to words sequentially from left to right; once a jailbreak tricks them into starting with "Sure, here is...", they are often locked into a harmful trajectory. Masked Diffusion Language Models (DLMs) work differently: they start with a sequence of [MASK] tokens and unmask groups of words in parallel over dozens of denoising steps, looking both forward and backward for context.

This parallel nature creates a sneaky vulnerability. Jailbreaks don't need an obvious prefix anymore; scattering seemingly harmless structural markers, formatting tokens, or function words across a partially denoised draft can act like gravitational anchors, pulling the remaining blanks toward an unsafe answer.

Figure 1: Comparison between uncertainty-based denoising and CURE. (A) Standard uncertainty- based denoising can retain seemingly benign early tokens that pull the trajectory toward unsafe compliance. (B) CURE re-masks risk-inducing tokens from the early state and enables the DLM to denoise toward a safe refusal.

At the same time, DLMs have a built-in superpower: intermediate drafts are editable. Existing DLM defenses either fine-tune the whole model (expensive and often hurts general intelligence) or regenerate giant blocks of text when trouble is detected (slow and clunky). The authors ask: Can we pinpoint and re-mask only the exact tokens causing future risk, right in the middle of generation?

Methods

CURE (Counterfactual Unsafe-token Re-masking) keeps the base DLM completely frozen and pairs it with a tiny, fast safety value model.

Overview of CURE's value model, spine-tree rollout training, and surgical test-time re-masking.
  1. Spine-Tree Rollouts (Data Collection): How do you know if a half-finished draft will turn toxic? Checking every possible future from every step is computationally impossible. Instead, the authors sample 4 main trajectories ("spines") per prompt, pick 16 checkpoints along each, and branch out 8 completions from each checkpoint. An external safety judge scores the final texts, giving a soft probability of how "safe" each intermediate state actually is.
  2. Cached Cross-Attention Value Model: Rather than running a separate neural network from scratch at every step, CURE taps into the 8th-layer hidden features already computed by the generator DLM during its normal forward pass. A lightweight cross-attention readout head looks at these cached features (plus a time-progress indicator) to predict future safety.
  3. Counterfactual Token Auditing: At each denoising step, CURE audits newly proposed and uncertain tokens by playing "what if?" using attention masks. For a suspect token $i$, it checks two views: necessity (does safety jump if we hide token $i$?) and sufficiency (how risky is token $i$ all by itself?). Because token features are cached, testing these counterfactuals just means flipping zeros and ones in an attention mask—zero extra backbone passes required. High-risk, uncertain tokens get re-masked and suppressed so the DLM picks safer words on the next step.

Datasets

  • Training: 2,000 harmful prompts sampled from BeaverTails to generate the spine-tree Monte Carlo trajectories.
  • Safety Evaluation: Five jailbreak benchmarks covering both standard attacks (WildJailbreak, JBB-Behaviors, HarmBench) and diffusion-specific structural attacks (PAD-AdvBench, DIJA-AdvBench). No new benchmarks are introduced.
  • Utility Evaluation: MMLU (general knowledge) and GSM8K (math reasoning) to ensure the model doesn't become overly cautious or lose capability.

Key Insights and Ideas

  • Ordinary words are the culprits: Auditing intermediate states revealed that the top 10 "unsafe" tokens—accounting for 31.6% of risky triggers—are mundane words like the, a, to, and, I, of, that, and colons (:). They aren't toxic in isolation, but in specific positions under bidirectional attention, they build the grammatical scaffolding of compliance. Reinserting these innocent-looking tokens into clean runs spiked attack success rates by over 20 percentage points!
  • Mask-flipping beats re-encoding: Approximating counterfactuals by simply masking cached intermediate features instead of re-running the DLM cuts compute overhead by 52.7$\times$ (0.84 vs. 44.25 TFLOPs) while sacrificing less than 1% in defense performance.

Key Results

Tested across three DLM backbones (LLaDA-8B-Instruct, Dream-v0-Instruct-7B, and LLaDA-1.5), CURE dominates the safety–utility–efficiency trade-off:

  • Near-zero jailbreak success: Macro-average Attack Success Rate (ASR) drops from 47.20% to 1.36% across all models and benchmarks (e.g., down to 0.06% on Dream-7B). On diffusion-native attacks like DIJA, ASR plummets by over 93–99 percentage points.
  • Preserved (and even slightly higher) utility: Unlike rival defenses that tank benchmark accuracy, CURE sits squarely on the Pareto frontier—preserving ~68–70% average accuracy on MMLU and GSM8K (and nudging LLaDA-8B-Instruct utility up from 65.68% to 68.48%).
CURE sits in the upper-right Pareto frontier on LLaDA-8B-Instruct, maximizing safety without sacrificing utility.
  • Featherweight compute: CURE adds just 0.7% extra TFLOPs (0.84 TFLOPs), whereas competing test-time defenses like DIFFUGUARD and SRIGuard add 103.1% and 200.0% overhead, respectively.

Limitations and Future Work

  • Approximate Counterfactuals: Because CURE reuses cached features without re-running the Transformer backbone, hiding a token in the readout mask doesn't erase its contextual influence on neighboring tokens' representations—making it an approximation rather than a strict causal deletion.
  • Future Directions: While specific failure cases are deferred to the appendix, the authors highlight a broader conceptual shift: treating the editable intermediate states of diffusion language models not just as a decoding quirk, but as an active, lightweight interface for test-time alignment without touching pretrained weights.

Summary updated

Abstract

Diffusion language models (DLMs) generate text through iterative denoising, enabling parallel decoding, bidirectional conditioning, and editable intermediate states. Under harmful prompts, however, intermediate denoising states can contain risk-inducing tokens that are seemingly benign but increase the probability of an unsafe final response by shaping how the remaining masked positions are completed. Since committed tokens in DLMs can still be re-masked and rewritten, safety control can be applied during denoising by removing a small set of risk-inducing tokens before they drive subsequent generation toward unsafe responses. Existing DLM defenses mainly rely on model-level alignment, trajectory-level detection, or block-level repair, often requiring training cost, extra inference passes, or coarse regeneration. We propose CURE, a counterfactual value-driven test-time alignment method that keeps the base DLM fixed and selectively re-masks risk-inducing tokens. CURE trains a time-conditioned safety value model to estimate whether a partially denoised state will lead to an unsafe final response. During inference, CURE constructs counterfactual readout views that remove or isolate targeted tokens, estimates their contribution to future unsafe response, and re-masks only high-risk tokens for later rewriting. Across three DLMs and five jailbreak benchmarks, \tta reduces macro-average ASR from 47.20\% to 1.36\%, preserves utility on MMLU and GSM8K, and incurs only a 0.7\% increase in computational cost, achieving a strong safety–utility–efficiency trade-off. Code is available at \url{https://github.com/wlc2424762917/CURE}.
BibTeX
@inproceedings{wang2026cure,
  author = {Lichao Wang and Mingquan Zhang and Xian Zhang and Juntao Dai and Chi Harold Liu and Yaodong Yang and Jingwei Yi},
  title = {{CURE: Counterfactual Unsafe-token Re-masking for Diffusion Large Language Model Test-time Alignment}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=XF2UgJwAIj},
}
Figure