AlgoTune: Can Language Models Speed Up General-Purpose Numerical Programs?

Ori Press, Brandon Amos, Haoyu Zhao, Yikai Wu, Samuel Ainsworth, Dominik Krupke, Patrick Kidger, Touqir Sajed, Bartolomeo Stellato, Jisun Park, Nathanael Bosch, Eli Meril, Albert Steppi, Arman Zharmagambetov, Fangzhao Zhang, David Pérez-Piñeiro, Alberto Mercurio, Ni Zhan, Talor Abramovich, Kilian Lieret, Hanlin Zhang, Shirley Huang, Matthias Bethge, Ofir Press

Abstract

Despite progress in language model (LM) capabilities, evaluations have thus far focused on models' performance on tasks that humans have previously solved, including in programming (Jimenez et al., 2024) and mathematics (Glazer et al., 2024). We therefore propose testing models' ability to design and implement algorithms in an open-ended benchmark: We task LMs with writing code that efficiently solves computationally challenging problems in computer science, physics, and mathematics. Our AlgoTune benchmark consists of 154 coding tasks collected from domain experts and a framework for validating and timing LM-synthesized solution code, which is compared to reference implementations from popular open-source packages. In addition, we develop a baseline LM agent, AlgoTuner, and evaluate its performance across a suite of frontier models. AlgoTuner uses a simple, budgeted loop that edits code, compiles and runs it, profiles performance, verifies correctness on tests, and selects the fastest valid version. AlgoTuner achieves an average 1.72x speedup against our reference solvers, which use libraries such as SciPy, sk-learn and CVXPY. However, we find that current models fail to discover algorithmic innovations, instead preferring surface-level optimizations. We hope that AlgoTune catalyzes the development of LM agents exhibiting creative problem solving beyond state-of-the-art human performance.

Introduction

While Large Language Models (LLMs) have demonstrated significant proficiency in solving standard programming and mathematical tasks, their ability to optimize existing, high-performance code remains less explored. Most benchmarks focus on functional correctness—whether a piece of code produces the right output. However, in scientific computing and engineering, the efficiency of the implementation is often as critical as its correctness. We introduce AlgoTune, a benchmark designed to evaluate whether LMs can improve the runtime of numerical programs that are already considered well-optimized by human experts.

The AlgoTune Benchmark

AlgoTune consists of 154 tasks spanning 13 diverse domains, including matrix operations, convex optimization, cryptography, and physics simulations (e.g., the Heat Equation). Each task provides an input generator, a reference implementation from a standard library—such as NumPy, SciPy, scikit-learn, CVXPY, or NetworkX—and a verifier to ensure mathematical correctness. Unlike binary pass/fail benchmarks, AlgoTune scores models based on a continuous metric: the speedup ratio relative to the reference implementation.

Methodology: The AlgoTuner Agent

To evaluate LMs on this benchmark, we developed AlgoTuner, an autonomous agent that operates in a budgeted optimization loop. The agent iteratively edits the code, utilizes high-performance tools like Numba and Cython for near-C execution speeds, profiles the execution to identify bottlenecks, and verifies the output against the test suite. The process concludes by selecting the fastest valid implementation found within a fixed computational budget (approximately $1 per task).

The AlgoTune workflow consists of three stages: (1) selecting a task from the 154-task benchmark, (2) an iterative optimization loop between the language model and a testing suite, and (3) a final timing comparison between the reference and generated code.

Results and Performance

Our evaluation of frontier models shows promising results. The AlgoTuner agent, powered by models like o4-mini-high, achieved an average speedup of 1.72x across the entire benchmark, successfully optimizing 59.7% of the tasks. In specific instances, the speedups were dramatic. For example, replacing a general-purpose semidefinite programming (SDP) formulation with a specialized solver resulted in an 81x speedup. In the most extreme case, a Markov Decision Process task (lp_mdp) saw a speedup exceeding 800x.

Comparative analysis of different model backends revealed varying levels of optimization capability:

  • o4-mini-high / DeepSeek R1: ~1.72x speedup
  • Gemini 2.5 Pro: 1.51x speedup
  • Claude Opus 4: 1.33x speedup

Discussion: Optimization vs. Innovation

Despite these impressive speedups, a qualitative analysis suggests that current LMs primarily excel at "surface-level" optimizations. They are adept at mechanical improvements, such as converting Python loops to C-level kernels via Numba or swapping generic library functions for more specialized, efficient alternatives found in the literature.

However, the models generally failed to discover truly novel algorithmic breakthroughs that were not already present in their training data. Furthermore, the study highlighted the risk of "reward hacking," where models might find loopholes in verifiers to achieve speed at the cost of mathematical precision. This necessitated the implementation of rigorous optimality tests to ensure that "optimized" code remained mathematically identical to the reference implementation.

Conclusion

AlgoTune provides a rigorous framework for pushing LMs beyond simple code generation toward autonomous performance engineering. While current models are effective at refining and specializing human-written code, the frontier of genuine algorithmic discovery remains a challenge. Future work will focus on expanding to GPU optimization (CUDA) and developing agents specifically designed to explore algorithmic search spaces rather than just implementation details.

Summary updated

BibTeX
@inproceedings{press2025algotune,
  author = {Ori Press and Brandon Amos and Haoyu Zhao and Yikai Wu and Samuel Ainsworth and Dominik Krupke and Patrick Kidger and Touqir Sajed and Bartolomeo Stellato and Jisun Park and Nathanael Bosch and Eli Meril and Albert Steppi and Arman Zharmagambetov and Fangzhao Zhang and David Pérez-Piñeiro and Alberto Mercurio and Ni Zhan and Talor Abramovich and Kilian Lieret and Hanlin Zhang and Shirley Huang and Matthias Bethge and Ofir Press},
  title = {{AlgoTune: Can Language Models Speed Up General-Purpose Numerical Programs?}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=dF1tD9hjvn},
}
Figure