Abstract
The rapid advancement of large language models (LLMs) has significantly improved code completion tasks, yet the trade-off between accuracy and computational cost remains a critical challenge. While using larger models and incorporating inference-time self-testing algorithms can significantly improve output accuracy, they incur substantial computational expenses. We introduce a novel framework combining model cascading and inference-time self-feedback algorithms to find multiple near-optimal self-testing options on the cost-accuracy tradeoff. Our approach leverages self-generated tests to both enhance accuracy and evaluate model cascading decisions. As a black-box inference-time method, it requires no access to internal model parameters. Experimental results show that our cascading approach reduces costs by an average of 26%, and up to 70% in the best case, across various model families and datasets.
Introduction
In the domain of AI-assisted coding, state-of-the-art models like the 34B parameter WizardCoder offer high capability but at significant financial and latency costs. To maximize accuracy, researchers often employ self-testing schemes (e.g., CodeT), where a model generates multiple solutions and unit tests, selecting the solution that passes the most tests. However, this approach multiplies inference costs because the model must perform many forward passes for a single prompt.
A key observation motivating this work is the "overlap phenomenon": a significant portion of problems solvable by large models can also be solved by their smaller counterparts. The challenge lies in identifying when a small model has succeeded. This paper proposes using self-testing not just for selection, but as a routing signal to decide when to escalate a task to a larger, more expensive model.
Methodology
The proposed Cascaded Black-Box Multi-Model Framework operates as a sequential filter across a model family, escalating only when necessary.
The process follows these steps:
- Generation: A prompt is sent to the smallest model in the family, which generates $k$ solutions and $k$ test cases.
- Self-Verification: Solutions are executed against the generated tests. A quality score is calculated based on the number of passing test lines.
- Thresholding: If the best solution-test pair exceeds a learned threshold $\theta$, the system stops and returns the code.
- Escalation: If the threshold is not met, the prompt is passed to the next larger model in the cascade, and the process repeats.
To optimize performance, we identify Pareto-optimal combinations of the number of solutions ($k$), test lines ($l$), and the escalation threshold ($\theta$) using a validation set.
Experimental Setup
We evaluated the framework on three standard Python benchmarks: HumanEval (164 problems), MBPP (427 problems), and APPS (introductory level). We tested three distinct model families: WizardCoder-Python-V1.0 (7B to 34B), WizardCoder-V1.0 (1B to 15B), and CodeGen-Mono (350M to 16B).
Results and Analysis
The cascading approach consistently outperformed single-model self-testing by staying on the Pareto frontier of the cost-accuracy trade-off across all tested families.
Key findings include:
- Significant Cost Efficiency: The framework achieved an average cost reduction of 26%. In the CodeGen-Mono family on HumanEval, cost savings reached a staggering 70% at equivalent accuracy levels.
- Robustness: The system provides a "menu" of options, allowing servers to choose the optimal plan based on dynamic budget or accuracy requirements.
Discussion and Insights
- Threshold Selection: Setting $\theta = 1.0$ (requiring a perfect pass rate) is often suboptimal because LLMs can generate incorrect tests. A threshold of 0.8–0.9 is typically more effective, accounting for "false negatives" in self-generated tests and preventing unnecessary escalation.
- Small Model Noise: If the base model's accuracy is extremely low (below 10%), the generated tests become too noisy to serve as a reliable routing signal. In such cases, it is more cost-effective to skip the smallest model entirely.
Conclusion
This work demonstrates that model cascading, guided by self-testing, is a highly effective strategy for reducing the cost of high-accuracy code generation. By treating self-testing as a verification signal for routing, we can exploit the capabilities of smaller models while maintaining the high performance of larger ones. Future work includes extending the framework to other programming languages and integrating it with techniques like speculative decoding.
Summary updated