Manuscript Offprint

arXiv:2608.25761

Beam Search, Self-Consistency, and the Limits of Inference-Time Scaling for Grammar-Constrained Text-to-SQL in Small Language Models

Ty Chermsirivatana, John MacCormick

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

ABSTRACT

One common trade-off in the use of large language models involves reducing the size of the model while increasing the amount of computation at inference time, for example by using a wider beam search. In this paper, we examine the constrained case of this “model size vs. inference compute” trade-off, in which the model outputs are constrained by a strict grammar at inference time. Our results demonstrate that the constrained trade-off behaves differently from the unconstrained trade-off. We investigate the task of converting a prose query into an equivalent SQL query (text-to-SQL). Performance is evaluated on the Spider text-to-SQL benchmark, using the Qwen2.5-Instruct model family ranging in size from 0.5B to 7B parameters, all at 4-bit precision. We experiment with two approaches to varying inference compute: (i) beam search with a variable number of beams; and (ii) sample+vote, i.e., sampling several constrained outputs and then voting on their execution results, where the number of samples is varied. On the 1034-example development set, we find that: (a) both beam search and sample+vote improve accuracy, especially on smaller model sizes; (b) the “model size vs. inference compute” trade-off is not advantageous in this experiment, because moving to a larger model size typically results in higher accuracy than increasing inference compute on the same model size; (c) beam search outperforms sample+vote at a matched inference budget. This latter result is of particular interest since it contrasts with the findings of the unconstrained trade-off.

1 Introduction

Many deployed systems require a language model to emit structured output such as SQL, schema-conformant JSON, or function-call arguments, where the output is useful only if it parses and runs. A common safeguard is grammar-constrained decoding. Each time a token is generated, any token that would make the output inconsistent with a formal grammar is masked [Geng et al., 2023, Willard and Louf, 2023]. This guarantees syntactic validity and, with a schema-aware grammar, prevents references to nonexistent tables, columns, or objects.

Separately, inference-time scaling spends more compute at generation time rather than enlarging the model, for example by widening beam search or by sampling many candidate outputs and aggregating them. The most influential aggregation method for reasoning tasks is self-consistency (or sample+vote), which samples several solutions and returns the most frequent final answer. In unconstrained settings, this approach can substantially outperform greedy decoding [Wang et al., 2023].

We investigate the cost-benefit trade-off of combining these two ideas. For example, a developer might use grammar constraints to ensure that a small model produces valid output, then employ additional inference-time computation in an attempt to approach the accuracy of a larger model. This strategy trades the higher memory and per-token computational requirements of a larger model for repeated or more extensive decoding with a smaller one. This strategy may be attractive when the larger model exceeds the memory capacity of the available hardware or requires a more expensive accelerator, particularly for local deployment.

Our experiments show that this strategy has limited utility in the grammar-constrained setting studied here. We evaluate four models from the Qwen2.5 family (0.5B, 1.5B, 3B, and 7B parameters) at fixed 4-bit precision on the full Spider development set of 1,034 examples, using execution accuracy as the evaluation metric and comparing beam width and sampling budget at matched cost. Our findings for this task and model family are as follows: (i) wider beams yield only modest improvements, and the gains shrink with model size, from approximately 0.15 in absolute execution accuracy for the 1.5B model to approximately 0.05 for the 7B model; (ii) sample+vote never outperforms beam search at a matched budget, contrary to prior results on unconstrained reasoning tasks, suggesting that the benefits of self-consistency do not transfer to grammar-constrained decoding in this setting; and (iii) additional inference-time computation does not in general substitute for parameters: at a budget of eight beams, it closes between 50% and 76% of the gap to the next larger model size, and only one of the three steps on the ladder, 1.5B to 3B, is fully bridged.