Abstract
Large language models (LLMs) have made significant strides in code acceleration (CA) tasks. Current works typically fine-tune LLMs using slow-fast code pairs mined from online programming platforms. Although these methods are widely recognized for their effectiveness, the training data often lack clear code acceleration patterns and offer only limited speed improvements. Moreover, existing training methods, such as direct instruction fine-tuning (IFT), tend to overlook the hierarchical relationships among acceleration patterns. In this work, we introduce BITE, a novel training paradigm designed to improve LLMs’ CA capabilities through two key innovations: (1) Bidirectional tree editing, which generates high-quality training data by incrementally transforming given code into both its most efficient and least efficient variants, and (2) Progressive code acceleration learning, which enables LLMs to internalize multi-level CA strategies by learning increasingly sophisticated acceleration patterns. Additionally, we introduce a new CA evaluation benchmark and metric for comprehensive assessment of model performance on CA tasks. Extensive experiments on both our benchmark and existing benchmarks demonstrate the effectiveness of our approach. Notably, BITE enables Qwen-1.5B to outperform prompt-enhanced GPT-4 and current training-based methods on average across five programming languages.
Introduction
Code Acceleration (CA) involves automatically refactoring source code to enhance execution speed while maintaining functional equivalence. While Large Language Models (LLMs) excel at general coding tasks, they frequently struggle with deep optimization. Existing approaches primarily rely on "slow-fast" code pairs scraped from competitive programming platforms like Codeforces. However, these datasets suffer from three major issues:
- Stylistic Noise: Pairs from different authors introduce variations in naming and formatting that obscure actual optimization patterns.
- Conservative Optimization: Mined data often reflects marginal speedups, leading models to learn minor tweaks rather than significant algorithmic improvements.
- Lack of Hierarchy: Current training treats simple math simplifications and complex $O(n^2)$ to $O(n \log n)$ transformations as equivalent, ignoring the natural learning progression.
Methodology: The BITE Framework
The BITE framework addresses these challenges through a two-stage process: high-quality data generation via bidirectional editing and a structured learning curriculum.
Bidirectional Tree Editing
To eliminate stylistic noise, BITE uses two specialized models: a Code Optimizer ($M_{opti}$) and a Code Degrader ($M_{degr}$). Starting from a "source" code snippet, these models iteratively generate a tree of variants. The Optimization Tree explores increasingly efficient versions, while the Degradation Tree explores less efficient variants. By generating training pairs from these trees (e.g., source to optimized, or degraded to source), the framework ensures that differences are purely algorithmic, effectively removing noise.
Progressive Code Acceleration Learning (PKAC)
BITE employs a three-stage curriculum learning strategy to help models internalize optimization strategies of varying difficulty:
- Stage 1 (Easy): Transforming "slow" (degraded) code back to the "source" version.
- Stage 2 (Medium): Transforming "source" code into "fast" (optimized) versions.
- Stage 3 (Hard): Direct acceleration from the slowest degraded versions to the fastest optimized versions.
To maintain performance on simpler tasks while learning complex ones, each stage incorporates a "Knowledge Consolidation" step, including subsets of data from previous stages.
Evaluation and Results
The researchers introduced the BITE Benchmark, a rigorous evaluation set covering C++, C, Go, Java, and Python. To avoid data leakage, it uses code published after May 2024 and includes expert-optimized references. They also proposed the Acceleration Progress (AP) metric, which measures the percentage of the performance gap closed between the original code and the expert-level optimum.
Key Findings
- Performance: A 1.5B parameter Qwen model trained with BITE outperformed prompt-enhanced GPT-4 across the benchmark.
- Data Quality: BITE-generated pairs achieved a 306.3% speedup ratio, more than double the 158.6% found in standard web-scraped datasets.
- Universal Patterns: Training a single multilingual model proved more effective than language-specific models, suggesting that optimization logic transcends syntax.
Conclusion
BITE demonstrates that high-quality, noise-free data and a hierarchical learning approach are critical for advancing LLM capabilities in code optimization. By leveraging bidirectional tree editing and a progressive curriculum, even small models can achieve state-of-the-art performance in code acceleration, surpassing much larger general-purpose models like GPT-4. Future work will expand this framework to consider memory efficiency and systems-level optimizations.
Summary updated