Constrained Adaptive Rejection Sampling

Paweł Parys, Sairam Vaidya, Taylor Berg-Kirkpatrick, Loris D’Antoni
Proceedings of the 43rd International Conference on Machine Learning, PMLR 306:97322-97352, 2026.

Abstract

Language Models (LMs) are increasingly used in applications where generated outputs must satisfy strict semantic or syntactic constraints. Existing approaches to constrained generation fall along a spectrum: greedy constrained decoding methods enforce validity during decoding but distort the LM’s distribution, while rejection sampling (RS) preserves fidelity but wastes computation by discarding invalid outputs. Both extremes are problematic in domains such as program fuzzing, where both validity and diversity of samples are essential. We present Constrained Adaptive Rejection Sampling (CARS), an approach that strictly improves the sample-efficiency of RS without distributional distortion. CARS begins with unconstrained LM sampling and adaptively rules out constraint-violating continuations by recording them in a trie and subtracting their probability mass from future draws. This adaptive pruning ensures that prefixes proven invalid are never revisited, acceptance rates improve monotonically, and the resulting samples exactly follow the constrained distribution. In experiments on a variety of domains—e.g., program fuzzing and molecular generation—CARS consistently achieves higher efficiency—measured in the number of LM forward passes per valid sample—while also producing stronger sample diversity than both Greedy Constrained Decoding (GCD) and methods that approximate the LM’s distribution.

Cite this Paper


BibTeX
@InProceedings{pmlr-v306-parys26a, title = {Constrained Adaptive Rejection Sampling}, author = {Parys, Pawe{\l} and Vaidya, Sairam and Berg-Kirkpatrick, Taylor and D'Antoni, Loris}, booktitle = {Proceedings of the 43rd International Conference on Machine Learning}, pages = {97322--97352}, year = {2026}, editor = {Zhang, Tong and Dudik, Miroslav and Jaggi, Martin and Agarwal, Alekh and Li, Sharon and Schuurmans, Dale and Zhu, Jerry and Berkenkamp, Felix and Dong, Hanze and Bietti, Alberto}, volume = {306}, series = {Proceedings of Machine Learning Research}, month = {06--11 Jul}, publisher = {PMLR}, pdf = {https://raw.githubusercontent.com/mlresearch/v306/main/assets/parys26a/parys26a.pdf}, url = {https://proceedings.mlr.press/v306/parys26a.html}, abstract = {Language Models (LMs) are increasingly used in applications where generated outputs must satisfy strict semantic or syntactic constraints. Existing approaches to constrained generation fall along a spectrum: greedy constrained decoding methods enforce validity during decoding but distort the LM’s distribution, while rejection sampling (RS) preserves fidelity but wastes computation by discarding invalid outputs. Both extremes are problematic in domains such as program fuzzing, where both validity and diversity of samples are essential. We present Constrained Adaptive Rejection Sampling (CARS), an approach that strictly improves the sample-efficiency of RS without distributional distortion. CARS begins with unconstrained LM sampling and adaptively rules out constraint-violating continuations by recording them in a trie and subtracting their probability mass from future draws. This adaptive pruning ensures that prefixes proven invalid are never revisited, acceptance rates improve monotonically, and the resulting samples exactly follow the constrained distribution. In experiments on a variety of domains—e.g., program fuzzing and molecular generation—CARS consistently achieves higher efficiency—measured in the number of LM forward passes per valid sample—while also producing stronger sample diversity than both Greedy Constrained Decoding (GCD) and methods that approximate the LM’s distribution.} }
Endnote
%0 Conference Paper %T Constrained Adaptive Rejection Sampling %A Paweł Parys %A Sairam Vaidya %A Taylor Berg-Kirkpatrick %A Loris D’Antoni %B Proceedings of the 43rd International Conference on Machine Learning %C Proceedings of Machine Learning Research %D 2026 %E Tong Zhang %E Miroslav Dudik %E Martin Jaggi %E Alekh Agarwal %E Sharon Li %E Dale Schuurmans %E Jerry Zhu %E Felix Berkenkamp %E Hanze Dong %E Alberto Bietti %F pmlr-v306-parys26a %I PMLR %P 97322--97352 %U https://proceedings.mlr.press/v306/parys26a.html %V 306 %X Language Models (LMs) are increasingly used in applications where generated outputs must satisfy strict semantic or syntactic constraints. Existing approaches to constrained generation fall along a spectrum: greedy constrained decoding methods enforce validity during decoding but distort the LM’s distribution, while rejection sampling (RS) preserves fidelity but wastes computation by discarding invalid outputs. Both extremes are problematic in domains such as program fuzzing, where both validity and diversity of samples are essential. We present Constrained Adaptive Rejection Sampling (CARS), an approach that strictly improves the sample-efficiency of RS without distributional distortion. CARS begins with unconstrained LM sampling and adaptively rules out constraint-violating continuations by recording them in a trie and subtracting their probability mass from future draws. This adaptive pruning ensures that prefixes proven invalid are never revisited, acceptance rates improve monotonically, and the resulting samples exactly follow the constrained distribution. In experiments on a variety of domains—e.g., program fuzzing and molecular generation—CARS consistently achieves higher efficiency—measured in the number of LM forward passes per valid sample—while also producing stronger sample diversity than both Greedy Constrained Decoding (GCD) and methods that approximate the LM’s distribution.
APA
Parys, P., Vaidya, S., Berg-Kirkpatrick, T. & D’Antoni, L.. (2026). Constrained Adaptive Rejection Sampling. Proceedings of the 43rd International Conference on Machine Learning, in Proceedings of Machine Learning Research 306:97322-97352 Available from https://proceedings.mlr.press/v306/parys26a.html.

Related Material