Meta Large Language Model Compiler: Foundation Models of Compiler Optimization

📄 arXiv: 2407.02524v1 📥 PDF

作者: Chris Cummins, Volker Seeker, Dejan Grubisic, Baptiste Roziere, Jonas Gehring, Gabriel Synnaeve, Hugh Leather

分类: cs.PL, cs.AI

发布日期: 2024-06-27


💡 一句话要点

提出Meta LLM Compiler,用于代码优化任务的基础模型,提升编译器性能。

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 大型语言模型 编译器优化 代码生成 LLVM-IR 汇编语言

📋 核心要点

  1. 现有方法训练LLM进行代码优化成本高昂,需要大量算力和数据。
  2. Meta LLM Compiler基于Code Llama,通过海量LLVM-IR和汇编代码训练,提升编译器理解能力。
  3. 实验表明,微调后的模型在代码大小优化和反汇编任务中表现出色,接近自动调优搜索的性能。

📝 摘要(中文)

大型语言模型(LLMs)在各种软件工程和编码任务中展现了卓越的能力。然而,它们在代码和编译器优化领域的应用仍未被充分探索。训练LLMs需要大量的GPU时间和广泛的数据收集,成本高昂。为了解决这个问题,我们推出了Meta LLM Compiler,这是一套专门为代码优化任务设计的强大、开放的、预训练模型。LLM Compiler建立在Code Llama的基础上,增强了对编译器中间表示(IRs)、汇编语言和优化技术的理解。该模型在包含5460亿个LLVM-IR和汇编代码token的庞大语料库上进行了训练,并经过指令微调以解释编译器行为。LLM Compiler以定制的商业许可证发布,允许广泛重用,并提供70亿和130亿参数两种尺寸。我们还展示了模型的微调版本,证明了其在优化代码大小以及将x86_64和ARM汇编反汇编回LLVM-IR方面的增强能力。这些模型实现了自动调优搜索77%的优化潜力,以及45%的反汇编往返(14%的精确匹配)。本次发布旨在为学术研究人员和行业从业者提供一个可扩展、经济高效的基础,以进一步研究和开发编译器优化。

🔬 方法详解

问题定义:论文旨在解决编译器优化中缺乏高效、可扩展的LLM基础模型的问题。现有方法训练LLM进行代码优化需要消耗大量资源,并且缺乏专门针对编译器IR和汇编语言的预训练模型。这限制了LLM在编译器优化领域的应用。

核心思路:论文的核心思路是利用Code Llama作为基础模型,通过大规模的LLVM-IR和汇编代码进行预训练,并进行指令微调,从而使模型能够更好地理解编译器行为和优化技术。这样可以降低训练成本,并提供一个可重用的基础模型。

技术框架:Meta LLM Compiler的技术框架主要包括以下几个阶段:1) 基于Code Llama构建基础模型;2) 使用包含5460亿个token的LLVM-IR和汇编代码语料库进行预训练;3) 进行指令微调,以提高模型对编译器行为的理解;4) 提供70亿和130亿参数两种尺寸的模型;5) 提供微调后的模型,用于代码大小优化和反汇编任务。

关键创新:论文的关键创新在于:1) 提出了Meta LLM Compiler,这是一个专门为代码优化任务设计的预训练LLM;2) 使用大规模的LLVM-IR和汇编代码进行预训练,使模型能够更好地理解编译器IR和汇编语言;3) 通过指令微调,提高了模型对编译器行为的理解。与现有方法相比,Meta LLM Compiler提供了一个可重用、可扩展的基础模型,降低了训练成本。

关键设计:论文的关键设计包括:1) 使用Code Llama作为基础模型,利用其在代码理解方面的优势;2) 构建包含5460亿个token的大规模LLVM-IR和汇编代码语料库,保证模型的训练数据质量;3) 设计合适的指令微调策略,提高模型对编译器行为的理解;4) 提供不同尺寸的模型,以满足不同应用场景的需求;5) 针对代码大小优化和反汇编任务进行微调,提高模型的性能。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,微调后的LLM Compiler在代码大小优化方面达到了自动调优搜索77%的优化潜力,在x86_64和ARM汇编反汇编回LLVM-IR的任务中,实现了45%的反汇编往返(14%的精确匹配)。这些结果证明了LLM Compiler在编译器优化任务中的有效性。

🎯 应用场景

该研究成果可应用于编译器自动优化、代码生成、漏洞检测、逆向工程等领域。通过利用LLM Compiler,可以显著提升编译器优化效率,降低开发成本,并为软件安全提供更强大的支持。未来,该模型有望成为编译器设计和开发的重要工具。

📄 摘要(原文)

Large Language Models (LLMs) have demonstrated remarkable capabilities across a variety of software engineering and coding tasks. However, their application in the domain of code and compiler optimization remains underexplored. Training LLMs is resource-intensive, requiring substantial GPU hours and extensive data collection, which can be prohibitive. To address this gap, we introduce Meta Large Language Model Compiler (LLM Compiler), a suite of robust, openly available, pre-trained models specifically designed for code optimization tasks. Built on the foundation of Code Llama, LLM Compiler enhances the understanding of compiler intermediate representations (IRs), assembly language, and optimization techniques. The model has been trained on a vast corpus of 546 billion tokens of LLVM-IR and assembly code and has undergone instruction fine-tuning to interpret compiler behavior. LLM Compiler is released under a bespoke commercial license to allow wide reuse and is available in two sizes: 7 billion and 13 billion parameters. We also present fine-tuned versions of the model, demonstrating its enhanced capabilities in optimizing code size and disassembling from x86_64 and ARM assembly back into LLVM-IR. These achieve 77% of the optimising potential of an autotuning search, and 45% disassembly round trip (14% exact match). This release aims to provide a scalable, cost-effective foundation for further research and development in compiler optimization by both academic researchers and industry practitioners.