arXiv:2604.17290cs.CLcs.AI2026-04被引 2

让大模型一次生成,就能高效衍生更多代码解法。

Probabilistic Programs of Thought

  • 用生成程序的下一个词概率构建概率程序,压缩海量可能解
  • 采样新程序无需额外显卡计算,仅需少量CPU开销
  • 适合需要快速探索多种代码解法的开发与推理场景

大型语言模型广泛用于代码生成和数学推理任务,需输出结构化内容。传统方法通过提示模型生成多个程序样本,但每次采样都需一次昂贵的GPU生成,当样本数n增大时成本急剧上升。本文提出一种称为「概率性思维程序」的测试时框架,利用模型生成程序中包含的下一个词概率分布,构建一个紧凑的概率程序,可表示指数级数量的确定性程序。在该概率程序上进行概率推理远比重复调用模型廉价,因此可在不增加任何额外GPU计算的前提下实现高效采样。我们在代码生成、代码理解及数学推理基准上验证了该方法,结果表明使用更少的LLM生成次数即可获得性能提升。

原文摘要 · Abstract (English)

LLMs are widely used for code generation and mathematical reasoning tasks where they are required to generate structured output. They either need to reason about code, generate code for a given specification, or reason using programs of thought. The typical approach to code generation is to prompt the model and generate samples until an appropriate program is obtained. Within this process, sampling $n$ programs from the language model requires $n$ GPU compute-intensive generations which becomes prohibitively expensive for larger values of $n$. In this work, we address this limitation by exposing the LLM's distribution within the generated programs themselves. We propose a novel test-time framework we dub probabilistic programs of thought to obtain more samples from the model with fewer LLM generations. Given a program generated by a model and the associated next-token probabilities, we build a probabilistic program that compactly represents exponentially many deterministic programs. Since performing probabilistic reasoning in this probabilistic program is much cheaper, our approach allows sampling new programs without any additional GPU compute and little CPU overhead. We instantiate our approach on benchmarks for code generation, code understanding and mathematical reasoning and report improvements in performance with fewer generations from the LLM.

代码生成概率推理高效采样

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。