AI 编程者就在我们中间:面向高效代码生成重新思考编程语言语法
AI Coders Are Among Us: Rethinking Programming Language Grammar Towards Efficient Code Generation
AI总结:
本研究针对现有编程语言语法适配人类阅读却增加LLM计算负担的问题,提出面向AI的语法概念,开发了首个Python的AI导向语法SimPy,可在保持甚至提升模型性能的同时显著减少token用量。
摘要:
随着我们步入大语言模型(LLM)时代,人工智能(AI)模型已成为继人类和机器之后编程语言的又一类重要受众。当前LLM已能在编程竞赛中表现出色,甚至能像开发者一样编写程序解决各类任务,包括数学问题。然而,现有程序的语法与排版都是为满足人类开发者的需求设计的——大量语法标记和格式标记的使用都是为了让代码更便于人类阅读。这种设计虽有其作用,但也给LLM带来了不必要的计算负担,因为它们使用或生成的每一个标记都会消耗计算资源。\n为提升推理效率、降低计算成本,我们提出了面向AI的语法概念,旨在以更契合AI模型工作机制的方式表示代码。采用面向AI语法编写的代码会舍弃格式,用最少的标记有效传递代码语义。为验证该概念的可行性,我们探索并实现了首个面向Python的AI导向语法,命名为SimPy。SimPy通过一系列启发式规则修改原始Python语法构建而成,用SimPy编写的程序与标准Python程序拥有完全相同的抽象语法树(AST)结构。这不仅能通过修改后的AST解析器执行程序,还能实现Python与SimPy编写的程序之间的无缝转换,让人类开发者与LLM在协作时可分别使用Python和SimPy。\n实验结果显示,在完成同一组代码相关任务时,与Python相比,SimPy可让CodeLlama和GPT-4的标记使用量分别减少13.5%和10.4%。此外,在这些任务中使用SimPy替代Python时,上述模型的性能能够保持甚至有所提升。
英文摘要:
Artificial Intelligence (AI) models have emerged as another important audience for programming languages alongside humans and machines, as we enter the era of large language models (LLMs). LLMs can now perform well in coding competitions and even write programs like developers to solve various tasks, including mathematical problems. However, the grammar and layout of current programs are designed to cater the needs of human developers -- with many grammar tokens and formatting tokens being used to make the code easier for humans to read. While this is helpful, such a design adds unnecessary computational work for LLMs, as each token they either use or produce consumes computational resources. To improve inference efficiency and reduce computational costs, we propose the concept of AI-oriented grammar. This aims to represent code in a way that better suits the working mechanism of AI models. Code written with AI-oriented grammar discards formats and uses a minimum number of tokens to convey code semantics effectively. To demonstrate the feasibility of this concept, we explore and implement the first AI-oriented grammar for Python, named SimPy. SimPy is crafted by revising the original Python grammar through a series of heuristic rules. Programs written in SimPy maintain identical AST structures to those in standard Python. This allows for not only execution via a modified AST parser, but also seamless transformation between programs written in Python and SimPy, enabling human developers and LLMs to use Python and SimPy, respectively, when they need to collaborate. In the experiments, compared with Python, SimPy enables a reduction in token usage by 13.5% and 10.4% for CodeLlama and GPT-4, respectively, when completing the same set of code-related tasks. Additionally, these models can maintain or even improve their performance when using SimPy instead of Python for these tasks.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。