Constrained Adaptive Rejection Sampling
- CARS is an adaptive rejection sampling method that efficiently preserves constrained target distributions by eliminating repeated evaluations of invalid proposals.
- It operates at both the token and sequence levels, enhancing constrained generation in language models while maintaining global posterior accuracy and reducing computational overhead.
- The approach bridges classical Monte Carlo techniques and modern constrained decoding, providing exact sampling and unbiased local normalizer estimates for improved performance.
Searching arXiv for the cited CARS papers and closely related context. arxiv_search(query="(Martino et al., 2015) OR (Lipkin et al., 7 Apr 2025) OR (Parys et al., 2 Oct 2025)", max_results=10) Constrained Adaptive Rejection Sampling (CARS) denotes adaptive rejection-based procedures that preserve a constrained target distribution while reducing repeated evaluation of invalid proposals. In the 2025 language-model literature, CARS refers to methods for exact or properly reweighted constrained generation under hard semantic or syntactic constraints, avoiding the full-vocabulary cost and posterior distortion associated with locally constrained decoding and token masking (Lipkin et al., 7 Apr 2025, Parys et al., 2 Oct 2025). The acronym also has an earlier and unrelated use in Monte Carlo sampling: “Cheap Adaptive Rejection Sampling,” a fixed-node variant of adaptive rejection sampling for univariate log-concave densities (Martino et al., 2015).
1. Constrained generation setting and target distributions
In constrained language-model generation, the basic objective is to sample complete strings that satisfy a global constraint . Writing the unconstrained autoregressive probability as , the constrained target is the posterior
Under prefix-based decoding, the local decision problem can be expressed through an oracle , indicating whether any valid completion begins with token after prefix . The ideal next-token law is then
Naïve token masking evaluates on every , renormalizes, and samples. For large vocabularies this is expensive, and the 2025 formulation explicitly characterizes locally constrained decoding as myopic because it can distort the global posterior over strings (Lipkin et al., 7 Apr 2025).
A related but distinct formulation considers the constrained distribution over full sequences 0,
1
This sequence-level perspective is central to the trie-based CARS construction, which operates by ruling out invalid prefixes while preserving the relative mass of all valid sequences (Parys et al., 2 Oct 2025).
A recurring misconception in this area is that enforcing validity during decoding is equivalent to sampling from the true conditional model. The cited works separate these notions sharply: masking-based methods enforce local admissibility, whereas CARS is designed either to sample exactly from the local constrained distribution 2 and provide unbiased normalizer estimates for downstream correction, or to sample exactly from the full constrained distribution 3 itself (Lipkin et al., 7 Apr 2025, Parys et al., 2 Oct 2025).
2. Token-level CARS and adaptive weighted rejection sampling
The 2025 adaptive weighted rejection-sampling formulation begins from simple rejection sampling at a single decoding step. One repeatedly draws 4 until 5. The accepted token is exactly distributed as 6, but the expected number of draws is 7, which becomes prohibitive when the valid mass 8 is small (Lipkin et al., 7 Apr 2025).
Adaptive rejection sampling (ARS) improves this by maintaining a rejection set 9 of already tested invalid tokens. At iteration 0, it samples from
1
and adds any newly rejected token to 2. This guarantees that each non-conforming token is tested at most once, with expected cost
3
The same work then defines CARS by augmenting ARS with an additional loop so that the procedure outputs both an exact token sample 4 and an unbiased estimator 5 of the local normalizer 6. In the single-loop 7 construction, the state variables are 8, 9, and 0; after rejection events, 1 counts rejects and 2 accumulates their prior mass. The returned estimator is
3
The paper states that 4 exactly and 5, via an auxiliary-variable / two-level RAVI analysis (Lipkin et al., 7 Apr 2025).
This unbiased local-normalizer estimate is the key addition that distinguishes token-level CARS from ordinary ARS in the sequential setting. In sequential Monte Carlo, the local importance-weight update is precisely 6. Replacing masking-based locally constrained decoding by CARS therefore allows the proposal to remain exact at the token level while using 7 to preserve unbiasedness for the global posterior over strings (Lipkin et al., 7 Apr 2025).
3. Trie-based sequence-level CARS
A later 2025 formulation titled “Constrained Adaptive Rejection Sampling” defines CARS at the level of complete sequences rather than individual next-token draws. The method maintains a finite set 8 of prefixes that are known invalid, meaning that they cannot lead to any 9. For each prefix 0, it stores a quantity
1
the total probability mass of completions of 2 that avoid any extension of 3. These values are stored in a trie over 4, and when a new invalid prefix is inserted the update propagates upward so that the recursive identity
5
remains valid (Parys et al., 2 Oct 2025).
Given the current trie, CARS samples from a reweighted distribution
6
This can be implemented left-to-right through
7
Any token with 8 is effectively masked out, but the masking is induced by accumulated structural knowledge about invalid prefixes rather than by exhaustively checking the full vocabulary at each step (Parys et al., 2 Oct 2025).
When a sampled sequence 9 is invalid, the algorithm performs “maximal pruning.” It finds the shortest prefix 0 of 1 that cannot extend to any 2, adds 3 to 4, and also adds each 5 such that 6 and 7. The paper’s pseudocode specifies that each such insertion sets 8 and updates the trie upward. According to the stated correctness argument, accepted samples remain exactly distributed as
9
because 0 and the relative weights of valid sequences continue to be proportional to 1 (Parys et al., 2 Oct 2025).
This formulation is exact in a stronger sense than local constrained decoding: it does not merely sample locally admissible continuations, but returns full sequences from the conditional law 2. The paper presents this as a middle ground between greedy constrained decoding, which enforces validity but distorts the distribution, and vanilla rejection sampling, which preserves fidelity but may waste many complete draws (Parys et al., 2 Oct 2025).
4. Theoretical properties and runtime behavior
The token-level and sequence-level CARS formulations share a common design principle: adaptive elimination of invalid mass improves efficiency without changing the intended constrained law. In the token-level setting, the runtime analysis compares three schemes. Simple rejection sampling has
3
ARS reduces this to
4
For CARS with 5, the expected number of evaluations is
6
which is still 7. The same analysis states that, in practice, sharply peaked “distractor” tokens often dominate the invalid mass, so ARS and CARS require only a handful of constraint checks per token, and that runtime improvements are greater for better models because larger 8 corresponds to smaller divergence between the constrained and unconstrained distributions (Lipkin et al., 7 Apr 2025).
The trie-based formulation emphasizes exactness and monotonicity at the sequence level. Each time an invalid prefix is added, the allowed mass 9 strictly decreases, so the acceptance rate improves monotonically. Sampling a sequence of length 0 requires 1 LM forward calls, one per next-token distribution. Trie updates after rejection may, in the worst case, add 2 nodes; updating each node’s 3 and propagating upward costs 4, yielding worst-case 5 work per rejection. The same source contrasts this with vanilla rejection sampling, which requires 6 LM calls on average when 7 is the true acceptance probability under rejection sampling (Parys et al., 2 Oct 2025).
Both formulations also identify low-mass regimes as a limiting case. The token-level paper notes that when 8 is extremely small, ARS and CARS may still need to exhaust nearly all non-conforming tokens, up to 9. It further states that cutoff thresholds introduced to avoid tiny 0 values make CARS biased, and it lists adaptive cutoffs, variance-controlled multi-loop schemes, batched and parallel CARS, and learned twist functions as open problems (Lipkin et al., 7 Apr 2025).
5. Empirical findings across domains
The empirical literature uses CARS in several distinct constrained-generation settings, but the reported comparisons are organized around a common baseline spectrum: unconstrained generation, locally constrained decoding with full-vocabulary masking, adaptive rejection-based constrained decoding, and more elaborate Monte Carlo corrections (Lipkin et al., 7 Apr 2025, Parys et al., 2 Oct 2025).
| Paper | Domains | Reported emphasis |
|---|---|---|
| (Lipkin et al., 7 Apr 2025) | Text-to-SQL, JSON, goal inference, molecular synthesis, pattern matching | Faster constrained token sampling and unbiased local weighting for SMC |
| (Parys et al., 2 Oct 2025) | Program fuzzing, molecular generation, PDDL planning | Exact constrained sequence sampling with adaptive prefix pruning |
In the adaptive weighted rejection-sampling study, pattern matching with 1 is reported as follows: slow LCD achieves 2 accuracy at 3 s/ex, fast LCD reaches 4 at 5 s/ex, and SMC-CARS with 6 particles gives 7 at 8 s/ex. For Text-to-SQL, fast LCD runs in 9 s at 0 accuracy, versus 1 s at 2 for unconstrained generation; SMC-CARS improves this to 3 accuracy with 4 in 5 s. For JSON generation, SMC-CARS reaches 6 accuracy, compared with 7 for twist-only and 8 for fast LCD, at runtime 9 s/ex. The same paper states that goal inference and molecular design show 00 speedups over slow LCD together with accuracy gains over unconstrained and simple baselines (Lipkin et al., 7 Apr 2025).
The trie-based sequence-level study reports three structured-generation domains. In program fuzzing with XML and no grammar prompt, RS and ARS time out at 01 draws, RSFT requires 02 draws for 03 valid seeds, and CARS requires 04 draws, described as 05 fewer. In the same setting, branch coverage after one hour of fuzzing is reported as 06 for CARS versus 07 for GCD. In molecular generation with Llama-3.1-8B, the numbers for 08 valid molecules are RS 09, ARS 10, CARS 11, GCD 12, and AWRS/MCMC 13; the paper states that CARS matches or exceeds ARS in quality metrics and uses 14 fewer draws than RS and 15 fewer than ARS. In PDDL planning with Qwen2.5-7B, RS/ARS achieve 16–17 valid and time out on larger domains, RSFT gives 18 valid, CARS gives 19 valid with 20 prefix validity, RSFT gives 21, ARS gives 22, and GCD gives 23 valid but only 24 prefix validity (Parys et al., 2 Oct 2025).
Taken together, these results support a consistent interpretation: exactness with respect to the constrained target need not imply the inefficiency of naïve rejection sampling, and validity alone need not imply preservation of the model’s constrained distribution. The empirical contrast with GCD, full-vocabulary masking, RS, and approximate MCMC-style methods is especially pronounced in large-vocabulary or low-acceptance regimes (Lipkin et al., 7 Apr 2025, Parys et al., 2 Oct 2025).
6. Relation to earlier “CARS” in classical Monte Carlo
Before the constrained-generation usage, the acronym CARS was introduced for “Cheap Adaptive Rejection Sampling,” a method for drawing from a univariate log-concave target density
25
with 26. The method fixes in advance an integer 27 and a set of support points 28. At each 29, it constructs the tangent line
30
and defines the global upper hull
31
The resulting proposal 32 is piecewise exponential, and the acceptance probability at iteration 33 is
34
Unlike classical ARS, which adds every rejected sample and therefore increases proposal complexity over time, Cheap Adaptive Rejection Sampling keeps 35 fixed. When a proposal 36 is rejected, it identifies the closest node
37
forms
38
and performs the swap only if the new normalizer 39 is smaller than the current 40. This “swap-if-it-helps” rule makes 41 non-increasing, so 42 is non-decreasing and converges to a limiting 43, the best achievable acceptance rate with 44 tangent lines. The per-iteration cost remains 45, uniformly in 46, in contrast to standard ARS where the number of nodes grows and the per-iteration cost scales like 47 (Martino et al., 2015).
The reported experiments illustrate the intended trade-off. For a zero-mean Gaussian target with 48 and initial 49, ARS typically grows to 50 nodes with 51 and normalized CPU time 52, whereas CARS with fixed 53 remains at 54 and CPU time 55; with 56, CARS reaches 57 and CPU time 58. For a 59 density on 60, ARS with 61 and initial 62 grows to roughly 63 nodes with 64, whereas CARS keeps 65 and 66, with CPU time up to 67–68 lower for large 69 (Martino et al., 2015).
This earlier usage is conceptually distinct from constrained language-model CARS. The shared acronym reflects a common adaptive-rejection theme, but the objects being adapted are different: tangent-line envelopes for continuous log-concave densities in the 2015 method, and invalid-token or invalid-prefix sets for constrained discrete generation in the 2025 methods. A plausible implication is that the later terminology emphasizes a methodological analogy rather than a direct algorithmic inheritance (Martino et al., 2015, Lipkin et al., 7 Apr 2025, Parys et al., 2 Oct 2025).