Large Language Model (LLM) based code generation is predominantly formulated as a strictly monotonic process, appending tokens linearly to an immutable prefix. This formulation contrasts to the cognitive process of programming, which is inherently interleaved with forward generation and on-the-fly revision. While prior works attempt to introduce revision via post-hoc agents or external static tools, they either suffer from high latency or fail to leverage the model's intrinsic semantic reasoning. In this paper, we propose Stream of Revision, a paradigm shift that elevates code generation from a monotonic stream to a dynamic, self-correcting trajectory by leveraging model's intrinsic capabilities. We introduce specific action tokens that enable the model to seamlessly backtrack and edit its own history within a single forward pass. By internalizing the revision loop, our framework Stream of Revision allows the model to activate its latent capabilities just-in-time without external dependencies. Empirical results on secure code generation show that Stream of Revision significantly reduces vulnerabilities with minimal inference overhead.
翻译:基于大型语言模型(LLM)的代码生成主要被表述为一个严格单调的过程,即线性地向不可变的前缀追加标记。这种表述与编程的认知过程形成对比,后者本质上是前向生成与即时修正交织进行的。尽管先前的研究尝试通过事后代理或外部静态工具引入修正,但它们要么存在高延迟问题,要么未能充分利用模型内在的语义推理能力。本文提出“修正流”,这是一种范式转变,通过利用模型的内在能力,将代码生成从单调的流提升为动态、自校正的轨迹。我们引入了特定的动作标记,使模型能够在单次前向传播中无缝回溯并编辑自身的历史记录。通过内化修正循环,我们的框架“修正流”使得模型能够即时激活其潜在能力,而无需外部依赖。在安全代码生成上的实证结果表明,“修正流”以最小的推理开销显著减少了漏洞。