NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuning

Dong Huang, Guangtao Zeng, Jianbo Dai, Meng Luo, Han Weng, Yuhao Qing, Heming Cui, Zhijiang Guo, Jie Zhang

Overview

EffiCoder is a novel framework designed to train Large Language Models (LLMs) to generate code that is not only functionally correct but also highly efficient. By fine-tuning models on EFFIINSTRUCT—a curated dataset of over 65,000 tasks where solutions are selected based on real-world execution profiles—researchers achieved a staggering 48.4% reduction in execution time and a significant boost in coding accuracy (pass@1).

The Efficiency Gap: What Problem Does This Paper Address?

While LLMs have become remarkably adept at writing code that "works," they often produce naive solutions. These snippets might pass unit tests but are frequently slower and more memory-intensive than code written by expert human developers.

Comparison of different code solutions for the same task, highlighting variations in execution speed and memory usage.

In the real world, inefficient code translates to higher cloud computing costs, increased energy consumption (a growing sustainability concern), and poor performance on resource-constrained hardware like mobile or embedded devices. Most existing research focuses heavily on correctness (whether the code passes the test), leaving efficiency (how fast and lean it runs) as an afterthought. EffiCoder bridges this gap by treating efficiency as a primary objective during the fine-tuning process.

Methodology

The authors developed a multi-step pipeline to transform standard "correct" code generation into "efficient and correct" code generation:

The EffiCoder data generation pipeline, from mining candidate tasks to profiling and selecting the most efficient solutions for the EFFIINSTRUCT dataset.
  1. Task Aggregation: Coding challenges were collected from nine diverse open-source datasets.
  2. Candidate Generation: Instead of relying on a single model, multiple high-performing LLMs (such as GPT-4o and DeepSeek-Coder) were used to generate a variety of candidate solutions for each task.
  3. Local Profiling: Every candidate solution was executed locally to measure three key metrics: Execution Time (ET), Max Memory Usage (MU), and Total Memory Usage (TMU).
  4. Selection (The "Darwinian" Step): For every task, slow and bloated solutions were discarded. Only the most efficient solution that passed all test cases was kept. This curated collection formed the EFFIINSTRUCT dataset.
  5. Efficiency-Aware Fine-tuning: This dataset was then used to fine-tune eight different open-source LLMs (including the Qwen2.5-Coder and CodeLlama families) using standard Supervised Fine-Tuning (SFT).

Datasets and Benchmarks

  • EFFIINSTRUCT (New): The primary contribution of the paper, containing 65,710 tasks across five programming languages: Python, C++, Java, Rust, and Go. It was built by filtering an initial pool of 790,000 candidate tasks.
  • Evaluation Benchmarks: To rigorously test the models, the authors utilized EffiBench (specifically for efficiency), EvalPlus (HumanEvalPlus & MBPPPlus), DS-1000 (data science), EvoEval, and HumanEval-X (multilingual).

Key Insights

  • Efficiency and Correctness are Synergistic: One of the most striking findings is that fine-tuning for efficiency actually improves correctness. For example, Qwen2.5-Coder-7B-Instruct saw its pass@1 score jump from 44.8% to 57.7%. This suggests that "efficient" code often follows better logic and cleaner patterns, which are easier for the model to learn and replicate accurately.
  • The "Garbage In, Garbage Out" Correlation: The researchers proved a strong positive correlation (r > 0.95) between the efficiency of the training data and the efficiency of the model's subsequent outputs. Training a model on lazy, unoptimized code guarantees lazy, unoptimized outputs.
  • Pruning is the Secret Sauce: Case studies revealed that EffiCoder-tuned models are significantly better at implementing "early exit" strategies and pruning redundant recursive calls—mirroring how human experts optimize algorithms.

Key Results

The quantitative improvements were substantial across the board:

  • Speedup: On the EffiBench benchmark, the average execution time for correct tasks generated by Qwen2.5-Coder-7B-Instruct decreased by 48.4%.
  • Memory Optimization: Total Memory Usage (TMU) for DeepSeek-Coder-6.7B-Instruct dropped from 30.05 Mbs to 9.48 Mbs—a massive 68.5% reduction.
  • Outperforming Baselines: EffiCoder significantly outperformed existing optimization methods like PIE and Mercury. In a head-to-head comparison on HumanEvalPlus, EffiCoder achieved a 31.1% pass@1 compared to PIE’s 19.5% using the same base model (CodeLlama-7B).

Limitations and Future Work

  • Hardware Sensitivity: The profiling of "efficiency" is inherently tied to the hardware and environment where the code is executed. Code optimized for an Intel Xeon processor might not be the most efficient on an ARM-based mobile chip.
  • LLM "Ceiling": The dataset relies on existing LLMs to generate the initial "efficient" candidates. If no current LLM can generate a highly optimized solution for a very complex problem, that task cannot contribute an expert-level sample to the training set.
  • Future Directions: The authors suggest exploring the trade-offs between efficiency, maintainability, and fairness in automated code generation. They also plan to open-source the model weights and dataset to foster further research into sustainable AI.

Summary updated

BibTeX
@inproceedings{huang2025efficoder,
  author = {Dong HUANG and Guangtao Zeng and Jianbo Dai and Meng Luo and Han Weng and Yuhao QING and Heming Cui and Zhijiang Guo and Jie Zhang},
  title = {{EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuning}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=8bgaOg1TlZ},
}
Figure