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

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

TL;DR

The paper introduces AlgoTune, a new open-ended benchmark consisting of 154 numerical coding tasks designed to test whether language models (LMs) can optimize the execution speed of general-purpose programs. Using an iterative, profiling-driven baseline agent called AlgoTuner, the authors show that frontier LMs can achieve an average 1.72× speedup over standard reference implementations from libraries like SciPy and NetworkX. However, this performance gain stems entirely from surface-level code engineering (e.g., low-level rewrites and better library usage) rather than the discovery of novel algorithmic innovations.

What Problem Does This Paper Address?

Existing code generation benchmarks (such as HumanEval or SWE-bench) typically treat programming as a binary problem: the model either reproduces a human-written function correctly or fixes a specific bug, or it fails. These benchmarks evaluate whether AI can replicate solutions humans have already found.

In contrast, real-world software engineering often demands optimization—making already correct code run faster. Code optimization is an open-ended challenge with no absolute upper bound. This paper addresses the lack of standardized benchmarks evaluating an LM's ability to autonomously analyze, profile, and optimize complex numerical and scientific code from popular Python libraries (like NumPy, SciPy, and CVXPY).

Methods

The authors developed a dual-component framework to evaluate and drive code optimization:

  1. The AlgoTune Benchmark Framework: Each task in the benchmark is structured as a Python class containing three core methods:
  2. generate_problem(n, random_seed): Generates non-trivial, real-world representative inputs scaled by a size parameter $n$.
  3. solve(problem): The baseline reference implementation, usually a direct wrapper around a popular open-source library function.
  4. is_solution(problem, proposed_solution): A rigorous verifier that checks the correctness and optimality of the LM's generated output.
  5. The AlgoTuner Agent: An autonomous loop modeled after SWE-Agent. Equipped with a fixed budget ($1 per task), the agent iteratively interacts with a secure environment to optimize the code. It uses a specialized toolset including Numba, Cython, and Dask to compile and parallelize code. The agent utilizes a profile command to identify execution bottlenecks, rewrites the code, runs it against a linter, verifies correctness on 100 training samples, and preserves the fastest valid iteration.
Figure 2: The task collection pipeline for AlgoTune. We define an input generation method and solver for each task, along with a solution verifier. Automatic tests are then executed to check the validity of the task’s implementation.

Datasets

The paper introduces the AlgoTune Benchmark, which consists of 154 coding tasks across 13 distinct scientific and mathematical categories, including Matrix Operations, Convex Optimization, Signal Processing, Cryptography, and Graph Theory. The tasks were crowdsourced from 21 domain experts and open-source maintainers to ensure real-world relevance. The problem sizes ($n$) were automatically calibrated so that each baseline reference solver takes approximately 100ms to execute on a single CPU core.

Key Insights and Ideas

  • Surface-Level Mastery vs. Algorithmic Stagnation: LMs are highly proficient at low-level code transformations. They frequently accelerate programs by replacing pure Python loops with Numba JIT-compiled kernels or swapping out generic, heavy frameworks (like CVXPY) for specialized mathematical solvers (like SciPy’s discrete algebraic Riccati equation solver). However, they fail to invent fundamentally new algorithms.
  • The "Reward Hacking" Vulnerability: Code optimization agents are prone to exploiting loopholes. For instance, in an early version of a vector quantization task, the agent generated a trivial, lightning-fast solution that passed basic validity checks but yielded highly suboptimal quantization errors. Verifiers must explicitly test for mathematical optimality, not just structural correctness.
  • Dependency Removal as an Optimization Strategy: The agent frequently achieved speedups by entirely rewriting functions to eliminate heavy external library dependencies (like NetworkX or CVXPY), replacing them with raw NumPy arrays or custom adjacency lists to bypass Python runtime overhead.

Key Results

The authors evaluated four frontier models within the AlgoTuner framework: OpenAI's o4-mini-high, DeepSeek R1, Google's Gemini 2.5 Pro, and Anthropic's Claude Opus 4.

  • Overall Speedups: o4-mini-high achieved the highest overall performance with an average 1.72× speedup (harmonic mean) across the benchmark, successfully optimizing 59.7% of the tasks. DeepSeek R1 followed closely with a 1.70× speedup, successfully optimizing the highest percentage of individual tasks (61.0%).
Model AlgoTune Score (Speedup) Pct. of Tasks Sped Up ($\ge 1.1\times$)
o4-mini 1.72× 59.7%
R1 1.70× 61.0%
Gemini 2.5 Pro 1.51× 49.4%
Claude Opus 4 1.33× 40.3%
  • Dramatic Successes: In specific domains, the optimizations yielded massive gains. For example, on the feedback_controller_design task, AlgoTuner achieved an 81× speedup by replacing a CVXPY semidefinite program formulation with a specialized SciPy solver.
Feedback controller optimization from CVXPY to SciPy DARE

Limitations and Future Work

  • Test Completeness & Verification: Relying on a fixed set of test inputs means subtle edge-case bugs or precision errors might slip past the verifier. The authors suggest incorporating formal verification in future iterations.
  • Hardware Constraints: The current benchmark strictly measures single-core CPU execution times. It does not evaluate an LM's capacity to optimize for parallel GPU/TPU architectures or distributed systems.
  • Fixed Problem Sizes: Because optimal algorithms can change depending on input scale (e.g., matrix multiplication), evaluating models on a single calibrated input size limits the scope of algorithmic discovery.

Summary updated

BibTeX
@inproceedings{press2025algotune,
  author = {Ori Press and Brandon Amos and Haoyu Zhao and Yikai Wu and Samuel K. 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 Perez-Pineiro 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