Implementation of Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammars.
What this repo gives you: a reliable CFG-constrained decoding algorithm tailored for diffusion LLMs (dLLMs), plus evaluation code on C++ / JSON / SMILES structured generation tasks.

Diffusion LLMs generate tokens non-autoregressively, so intermediate outputs often contain placeholder (e.g., [MASK]). Classic CFG-constrained decoding assumes complete prefixes, which breaks in the diffusion setting.
LAVE solves this by:
This implements the paper’s notion of reliable constraint:
At every decoding step, the current intermediate output remains extendable — i.e., it can still be completed into at least one valid sentence in the target language.
We recommend using a virtual environment.
cd constrained-diffusion
python3 -m venv venv
source venv/bin/activate
cd rustformlang_bindings
pip install maturin
maturin build --release
pip install .
cd ..
pip install -e .
We evaluate CFG-constrained decoding on three representative structured-generation tasks:
| Task | Benchmark | What it tests |
|---|---|---|
| C++ | HumanEval-CPP (CPP-Bench) | CFG-compliant code generation |
| JSON | JSON-Mode-Eval-Extended (JSON-Bench) | CFG derived from JSON Schema, information extraction |
| SMILES | SMILES-Eval (SMILES-Bench) | CFG-compliant chemical string generation |
Download sources (paper uses these benchmarks):
https://huggingface.co/datasets/zai-org/humaneval-xhttps://huggingface.co/datasets/eth-sri/json-mode-eval-extendedhttps://huggingface.co/datasets/eth-sri/smiles-evalpython eval/dllm/run_dllm.py
Evaluation is decoupled from inference. Assuming inference outputs are in results/:
For SMILES evaluation, install extra deps:
pip install rdkit partialsmiles
Then run:
bash eval/check_all_individually.sh results/*
Models evaluated in the paper
Experiment hyperparameters
L = 256T = 128= 0.2= 32N = 10, τ = 5Metrics
syntactic@k: at least one of k samples is CFG-validfunctional@k: at least one of k samples is functionally correct79 followers · starred May 2026
Implementation of Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammars.
What this repo gives you: a reliable CFG-constrained decoding algorithm tailored for diffusion LLMs (dLLMs), plus evaluation code on C++ / JSON / SMILES structured generation tasks.

Diffusion LLMs generate tokens non-autoregressively, so intermediate outputs often contain placeholder (e.g., [MASK]). Classic CFG-constrained decoding assumes complete prefixes, which breaks in the diffusion setting.
LAVE solves this by:
This implements the paper’s notion of reliable constraint:
At every decoding step, the current intermediate output remains extendable — i.e., it can still be completed into at least one valid sentence in the target language.
We recommend using a virtual environment.
cd constrained-diffusion
python3 -m venv venv
source venv/bin/activate
cd rustformlang_bindings
pip install maturin
maturin build --release
pip install .
cd ..
pip install -e .
We evaluate CFG-constrained decoding on three representative structured-generation tasks:
| Task | Benchmark | What it tests |
|---|---|---|
| C++ | HumanEval-CPP (CPP-Bench) | CFG-compliant code generation |
| JSON | JSON-Mode-Eval-Extended (JSON-Bench) | CFG derived from JSON Schema, information extraction |
| SMILES | SMILES-Eval (SMILES-Bench) | CFG-compliant chemical string generation |
Download sources (paper uses these benchmarks):
https://huggingface.co/datasets/zai-org/humaneval-xhttps://huggingface.co/datasets/eth-sri/json-mode-eval-extendedhttps://huggingface.co/datasets/eth-sri/smiles-evalpython eval/dllm/run_dllm.py
Evaluation is decoupled from inference. Assuming inference outputs are in results/:
For SMILES evaluation, install extra deps:
pip install rdkit partialsmiles
Then run:
bash eval/check_all_individually.sh results/*
Models evaluated in the paper
Experiment hyperparameters
L = 256T = 128= 0.2= 32N = 10, τ = 5Metrics
syntactic@k: at least one of k samples is CFG-validfunctional@k: at least one of k samples is functionally correct79 followers · starred May 2026