Skip to main content
QUICK REVIEW

[Paper Review] Learning Performance-Improving Code Edits

Alexander Shypula, Aman Madaan|arXiv (Cornell University)|Feb 15, 2023
Software Engineering ResearchComputer Science24 citations
TL;DR

The paper creates PIE, a large dataset of performance-improving edits for C++ code, and shows how retrieval-based prompting, performance-conditioned generation, and self-play fine-tuning can adapt LLMs to reliably optimize code performance measured in the gem5 simulator, surpassing the best human performance in speedups on average.

ABSTRACT

With the decline of Moore's law, optimizing program performance has become a major focus of software research. However, high-level optimizations such as API and algorithm changes remain elusive due to the difficulty of understanding the semantics of code. Simultaneously, pretrained large language models (LLMs) have demonstrated strong capabilities at solving a wide range of programming tasks. To that end, we introduce a framework for adapting LLMs to high-level program optimization. First, we curate a dataset of performance-improving edits made by human programmers of over 77,000 competitive C++ programming submission pairs, accompanied by extensive unit tests. A major challenge is the significant variability of measuring performance on commodity hardware, which can lead to spurious "improvements." To isolate and reliably evaluate the impact of program optimizations, we design an environment based on the gem5 full system simulator, the de facto simulator used in academia and industry. Next, we propose a broad range of adaptation strategies for code optimization; for prompting, these include retrieval-based few-shot prompting and chain-of-thought, and for finetuning, these include performance-conditioned generation and synthetic data augmentation based on self-play. A combination of these techniques achieves a mean speedup of 6.86 with eight generations, higher than average optimizations from individual programmers (3.66). Using our model's fastest generations, we set a new upper limit on the fastest speedup possible for our dataset at 9.64 compared to using the fastest human submissions available (9.56).

Motivation & Objective

  • Provide a dataset and framework to study high-level program optimizations by LLMs.
  • Enable reliable, reproducible performance measurement using the gem5 simulator.
  • Evaluate prompting and fine-tuning strategies to adapt pre-trained code LLMs for performance optimization.
  • Identify effective adaptation techniques that surpass human performance in average speedups.

Proposed method

  • Curate PIE, a dataset of performance-improving edits (PIE) from CodeNet with execution times annotated via gem5.
  • Use the gem5 full-system simulator to obtain deterministic performance measurements.
  • Evaluate prompting strategies including instruction prompting, chain-of-thought, dynamic retrieval-based few-shot prompting.
  • Explore fine-tuning approaches: high-quality subset, performance-conditioned generation, and synthetic data via self-play.
  • Incorporate performance tags to steer optimization toward higher-performance solutions.
  • Augment data with synthetic examples generated by LLMs and filtered for novelty and speedup.
  • Measure effectiveness using percent of optimized programs, speedup, and correctness across test sets.

Experimental results

Research questions

  • RQ1Can large language models be effectively adapted to high-level code optimization tasks using PIE?
  • RQ2Which prompting or fine-tuning strategies best improve performance and correctness when optimizing code?
  • RQ3How do retrieval-based prompting, performance-conditioned generation, and synthetic self-play data compare in driving speedups?
  • RQ4What is the gap between open models and closed models like GPT-3.5 in this setting, and can open models close it with proper adaptation?

Key findings

  • A dataset of 77,967 training pairs from 1,474 problems enables reliable training and evaluation for performance optimization.
  • gem5-based evaluation provides deterministic performance measurements, mitigating phantom improvements seen on real hardware.
  • Dynamic retrieval-based prompting substantially outperforms baselines, e.g., GPT-3.5 with retrieval achieves high correctness and speedups.
  • Fine-tuning with PIE yields strong improvements; performance-conditioned generation markedly boosts optimization performance.
  • GPT-3.5 with synthetic self-play data reaches the highest reported average speedup (6.86×) on the test set, exceeding the best human solution (4.06×).
  • Open-code models (codellama) with appropriate tuning can approach or match closed models in performance when using the right adaptation strategies.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.