Meta Large Language Model Compiler: Foundation Models of Compiler Optimization

Chris Cummins, Volker Seeker, Dejan Grubisic, Baptiste Rozière, Jonas Gehring, Gabriel Synnaeve, Hugh LeatherarXiv 2024 · DOI

Introduction

Compiler optimization is a critical yet complex domain of computer science, traditionally relying on hand-tuned heuristics or machine learning models that use simplified, often "lossy," representations of code. These traditional methods frequently overlook granular details such as specific type information or constant values, leading to sub-optimal machine code generation. While modern Large Language Models (LLMs) excel at high-level programming languages, they historically struggle with low-level representations like LLVM Intermediate Representation (IR) and Assembly, often producing "hallucinated" optimizations that compromise program integrity.

Meta AI has introduced LLM Compiler, a suite of open-source models (available in 7B and 13B parameter sizes) designed to address these challenges. By treating code as a lossless text representation, these models aim to master the relationship between high-level logic and low-level compiler transformations.

Training Methodology

The development of LLM Compiler follows a rigorous multi-stage pipeline built upon the Code Llama foundation. This process ensures the model transitions from understanding general code to mastering specific compiler-level tasks.

The multi-stage training pipeline for LLM Compiler, progressing from foundation models to specialized downstream tasks.
  1. Massive Pre-training: The models were first exposed to a 401-billion-token corpus of LLVM-IR and assembly code. This stage established a foundational understanding of low-level language syntax and structure.
  2. Compiler Emulation: To move beyond simple pattern matching, the models were fine-tuned to emulate the behavior of a compiler. Given unoptimized code and a sequence of optimization passes, the model learned to predict the resulting optimized output.
  3. Downstream Fine-Tuning (FTD): Specialized versions were created for two primary tasks: Flag Tuning (selecting optimal compiler flags to minimize binary size) and Disassembly (reverting x86_64 and ARM assembly back into LLVM-IR).

Autotuning and Verification

A core innovation of this research is the use of an "autotuning" framework to generate high-quality training data and evaluate performance. The researchers compared the LLM's predictions against a brute-force autotuner that performed billions of compilations to find near-optimal settings.

The autotuning process used to generate training labels and the subsequent inference flow for code optimization.

To ensure the functional correctness of the model's output, Meta developed PassListEval. This tool integrates suggested optimizations with a real compiler and subjects the resulting binary to unit tests (such as HumanEval-X). This verification step is crucial, as it filters out optimizations that might otherwise break the program's logic.

Key Results and Insights

The LLM Compiler demonstrates significant improvements over both traditional heuristics and general-purpose LLMs:

  • Optimization Efficiency: The FTD version achieved 77% of the optimization potential identified by exhaustive brute-force searching. It provided a 5.26% reduction in binary size over the standard LLVM -Oz (optimize for size) flag.
  • Superiority over GPT-4: In flag tuning tasks, LLM Compiler significantly outperformed GPT-4 Turbo, which frequently produced larger binaries or non-functional code.
  • Disassembly Capabilities: The model achieved a 45% round-trip success rate in disassembly tasks, demonstrating a deep understanding of the mapping between assembly and intermediate representations.

Limitations and Future Directions

Despite its success, the model faces challenges regarding the context window. Large programs must often be truncated, limiting the model's ability to perform comprehensive whole-program optimizations. Furthermore, because LLMs are probabilistic, their outputs require mandatory verification by a compiler and test suite before production use.

Future research will likely expand from optimizing for code size to optimizing for execution latency, a more hardware-dependent and complex metric. By releasing these models as open-source, Meta aims to provide a foundation for further research into automated, AI-driven compiler optimization.

Summary updated

BibTeX
@misc{cummins2024meta,
  author = {Chris Cummins and Volker Seeker and Dejan Grubisic and Baptiste Rozière and Jonas Gehring and Gabriel Synnaeve and Hugh Leather},
  title = {{Meta Large Language Model Compiler: Foundation Models of Compiler Optimization}},
  year = {2024},
  eprint = {2407.02524},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.02524},
}
Figure