REASONING COMPILER: LLM-Guided Optimizations for Efficient Model Serving

Annabelle Sujun Tang, Christopher Priebe, Rohan Mahapatra, Lianhui Qin, Hadi Esmaeilzadeh

Executive Summary The REASONING COMPILER is a novel framework that leverages Large Language Models (LLMs) and Monte Carlo Tree Search (MCTS) to discover optimal transformations for neural network code. By treating compilation as a context-aware "reasoning" task rather than a blind stochastic search, it achieves up to 10.8x better sample efficiency and higher speedups than industry-standard tools like Apache TVM.

The Challenge of Compiler Optimization

Serving large-scale models (like Llama 3 or DeepSeek) is computationally expensive. To make these models run efficiently, engineers rely on neural compilers to optimize the underlying code—making critical decisions about how to tile data in memory, fuse operations together, or parallelize loops.

The primary challenge is that the "search space" for these optimizations is exponentially large and highly interdependent. A decision made early in the compilation process might render a highly effective optimization impossible later on. Current state-of-the-art compilers, such as Apache TVM, rely on "black-box" methods like evolutionary search or random trials. These methods are essentially "blind"—they do not understand why a certain transformation worked; they simply iterate until they find a better configuration. Consequently, they are incredibly slow and sample-inefficient.

The REASONING COMPILER Approach

To address these inefficiencies, the authors introduce the REASONING COMPILER, shifting the paradigm from blind searching to context-aware reasoning. The framework combines two powerful mechanisms:

  1. Monte Carlo Tree Search (MCTS): Known for its success in complex decision-making tasks (like AlphaGo), MCTS provides a structured way to explore the optimization decision tree. It effectively balances "exploration" (trying new transformations) and "exploitation" (refining paths that already show promise).
  2. LLM-Guided Proposals: Instead of selecting a random transformation at each step, the framework queries an LLM (such as GPT-4o or Llama 3).
Architecture of the REASONING COMPILER framework

The LLM is provided with a prompt containing the current source code, the history of previous transformations (the "trace"), performance feedback, and a list of available moves. Using Chain-of-Thought (CoT) reasoning, the LLM analyzes the code and suggests the most promising next steps. To maintain a fast search process, the framework evaluates these suggestions using a lightweight "hardware cost model" rather than executing the code on real hardware for every trial.

Key Insights and Zero-Shot Capabilities

The researchers evaluated their method on representative computational kernels from production-scale models (Llama-3-8B, DeepSeek-R1, FLUX, and Llama-4-Scout) across diverse hardware platforms including ARM, AMD, Apple Silicon, and Intel CPUs.

Several key insights emerged from the evaluation:

  • Context is the Secret Sauce: Providing the LLM with a deeper historical trace (including "grandparent" and "great-grandparent" states) leads to significantly faster convergence. The LLM leverages the trajectory of optimization to make intelligent decisions.
  • Zero-Shot Capability: Remarkably, the LLM does not require fine-tuning on compiler-specific data. Its general-purpose reasoning and code comprehension are sufficient to propose hardware-informed transformations out-of-the-box.
  • Open-Source Parity: While proprietary models perform well, open-source models like Llama 3.3 70B achieved nearly identical performance, making this approach highly accessible for local, privacy-preserving deployments.
  • Overcoming the "Rugged" Landscape: Compiler optimization landscapes are notoriously "rugged," where minor changes can cause massive performance swings. LLM reasoning helps the search "jump" over low-probability paths where traditional stochastic searches often get stuck.

Performance and Results

The REASONING COMPILER consistently outperformed TVM’s MetaSchedule, which relies on evolutionary search.

Performance comparison showing relative speedup over number of samples
  • Efficiency: It achieved a 5.0x average speedup using 5.8x fewer samples than TVM.
  • Sample Efficiency: Overall, the framework demonstrated a 10.8x improvement in sample efficiency across all tested kernels and hardware.
  • Rapid Convergence: On the Llama-4-Scout MLP layer, the REASONING COMPILER hit a 12.7x speedup in just 20 samples, whereas TVM failed to reach that level even after 3,000 samples.
  • End-to-End Performance: For a full Llama-3-8B model, it required 3.9x fewer samples to achieve a 4.0x speedup, resulting in a 5.6x total efficiency gain.

Limitations and Future Directions

While highly effective, the current approach has a few limitations. It currently relies on external LLM APIs, which introduces latency (though the cost per experiment remains low). Performance is also inherently tied to prompt structure. Furthermore, the current evaluation focused primarily on CPU architectures; extending this framework to GPUs, which feature even more complex memory hierarchies, is a logical next step. Finally, future iterations could enable the LLM to "learn" from the cost model's feedback in real-time, dynamically refining its internal understanding of hardware performance.

Summary updated

BibTeX
@inproceedings{tang2025reasoning,
  author = {Annabelle Sujun Tang and Christopher Priebe and Rohan Mahapatra and Lianhui Qin and Hadi Esmaeilzadeh},
  title = {{REASONING COMPILER: LLM-Guided Optimizations for Efficient Model Serving}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=2D4TuZyNnr},
}
Figure