一句话:提出 TreeCoder,把解码策略与约束函数作为可优化组件,通过树搜索系统性探索并自动调优 LLM 代码生成。
大语言模型虽能生成代码,但仅靠自然语言提示引导时,输出常违反语法或语义约束。本文提出 TreeCoder,一个用于探索 LLM 解码策略、约束与超参数的最通用、最灵活的框架,并将其用于代码生成,以便在解码阶段而非提示工程阶段保证正确性与结构。TreeCoder 把解码建模为在候选程序上的树搜索,将解码策略与约束函数(如风格、语法、执行约束)视为一等且可优化的组件,从而可用标准优化技术系统性地探索并自动调节解码配置。在 Python、SQL 与 Rust 上的实验表明,TreeCoder 在 CodeLlama、Mistral、DeepSeek、Qwen 等开源模型上一致提升准确率,且往往显著优于无约束基线。
Large language models (LLMs) have shown remarkable ability to generate code, yet their outputs often violate syntactic or semantic constraints when guided only through natural language prompts. We introduce TreeCoder, the most general and flexible framework to date for exploring decoding strategies, constraints, and hyperparameters in LLMs, and use it in code generation to enforce correctness and structure during decoding rather than relying on prompt engineering. TreeCoder represents decoding as a tree search over candidate programs, where both decoding strategies and constraint functions–such as style, syntax, execution–are treated as first-class, optimisable components. This design enables systematic exploration and automatic tuning of decoding configurations using standard optimisation techniques. Experiments on Python, SQL and Rust show that TreeCoder consistently improves accuracy across open-source models such as CodeLlama, Mistral, DeepSeek and Qwen, often significantly outperforming their unconstrained baselines.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@article{abs-2511-22277,
title = {TreeCoder: Systematic Exploration and Optimisation of Decoding and Constraints for LLM Code Generation},
author = {Henrijs Princis and Arindam Sharma and Cristina David},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {PLDI},
year = {2026},
doi = {10.1145/3808347}
}