TL;DR
Large Language Models (LLMs) for code generation are computationally expensive and energy-hungry. This paper introduces Flab-Pruner, a novel unified structural pruning method that simultaneously prunes vocabulary, layers, and Feed-Forward Network (FFN) components of Code LLMs. Flab-Pruner significantly reduces model size and computational cost while maintaining high performance, even outperforming dense models after post-training.
What Problem Does This Paper Address?
The widespread adoption of Large Language Models (LLMs) in code generation tasks has led to significant concerns regarding their high computational demands and energy consumption. This is particularly problematic for "green software engineering," which aims to reduce the environmental impact of software. Existing pruning methods, often designed for classification models, struggle with the high-dimensional output of generative Code LLMs. Furthermore, single-component pruning approaches are insufficient, and generic post-training methods don't fully leverage the unique characteristics of code-related tasks. The authors aim to address these limitations by proposing a unified, multi-granular pruning strategy specifically tailored for Code LLMs.
Methods
The core of the paper is the Flab-Pruner method, a unified structural pruning approach that combines three key components:
- Vocabulary Pruning: This involves removing infrequently used tokens from the model's vocabulary. The authors define a threshold for token usage to retain essential tokens, thereby reducing the embedding and output layer sizes.
- Layer Pruning: This method iteratively removes entire layers from the model. Unlike previous approaches that rely on layer similarity metrics, Flab-Pruner uses KL divergence between the pruned and original model's output probability distributions to identify and remove the least impactful layers.
- FFN Pruning: This targets neurons within the Feed-Forward Network (FFN) modules of the Transformer architecture. The authors propose four heuristic rules (Top-K, Bottom-K, Middle-K, Random Sampling) to select neurons for pruning, aiming to reduce computational overhead.
A crucial aspect of their method is the pruning objective: minimizing the KL divergence between the output probability distributions of the pruned and original models. This ensures that the pruned model maintains similar token generation probabilities, directly optimizing for code generation quality.
Additionally, they introduce a customized code instruction data strategy for performance recovery. Instead of using the original dataset, they replace generated code with semantically correct code from the original model (if it passes tests), creating a higher-quality dataset for fine-tuning the pruned model. This strategy enhances performance recovery efficiency.
Datasets
The paper utilizes several datasets for training and evaluation:
- HumanEval: A widely used benchmark for code generation.
- OpenEval: Another benchmark for code generation.
- CodeHarmony: A newly introduced comprehensive benchmark dataset for code intelligence evaluation. It was constructed by aggregating function-level Python code from open-source repositories, generating test cases using LLMs, and integrating Chain-of-Thought (CoT) reasoning steps.
- HumanEval-CoT and OpenEval-CoT: Datasets used for CoT generation.
- CRUX dataset: Used for output prediction tasks.
- RECODE and EvoEval: Datasets used for robustness analysis.
Key Insights and Ideas
- Unified Pruning is Key: Combining vocabulary, layer, and FFN pruning offers synergistic benefits that single-component approaches miss.
- KL Divergence for Code LLMs: For generative code models, minimizing KL divergence of output probabilities is a more effective pruning objective than layer-wise similarity metrics, directly preserving code generation capabilities.
- Customized Data Strategy for Recovery: Replacing generated code with verified outputs from the original model significantly improves the efficiency and effectiveness of performance recovery after pruning.
- Pruning is More Than Just Size Reduction: The paper demonstrates that structured pruning can lead to substantial efficiency gains (GPU usage, FLOPs, CO2 emissions) without sacrificing, and sometimes even improving, performance and robustness.
- Post-training is Crucial: While pruning alone reduces model size, post-training with the customized data strategy is essential for recovering and even enhancing performance, especially under perturbed conditions.
Key Results
- Parameter Reduction: Flab-Pruner reduces model parameters by approximately 22%.
- Performance Retention: The pruned model retains about 97% of the original performance before post-training.
- Performance Recovery: After post-training, Flab-Pruner achieves comparable or even superior performance to the original dense models across various code intelligence tasks (Code Generation, CoT Generation, Output Prediction). For example, on CodeQwen, Pass@1 improved from 75.00% (pruned) to 78.05% (pruned + PT), surpassing the dense model's 77.44%.
- Efficiency Gains: Significant improvements were observed in:
- GPU Usage: Reduced from 13.55 GB (dense) to 10.72 GB (pruned) and even 3.02 GB at INT4 precision.
- Tokens per second: Increased from 30 (dense) to 38 (pruned).
- CO2 Emissions: Reduced from 2.14 g to 1.84 g per evaluation.
- FLOPs: Reduced from 7.04T to 5.64T per inference.
- Robustness: Pruned models show a slight decrease in robustness under certain perturbations, but post-training helps recover and even enhance robustness in some cases.
- Computational Cost: The pruning process takes approximately 6 hours, but this is quickly amortized by the inference efficiency gains, with a break-even point of around 108,617 inference runs.
Limitations and Future Work
- Dataset Representativeness: The authors acknowledge that their dataset selection (primarily Python) might limit the generalizability of findings to other programming languages. Future work will expand to more languages.
- Model Scope: The study focused on three specific Code LLMs. Future work will include a broader range of models to improve external validity.
- Efficiency of Pruning Methods: While Flab-Pruner is efficient, future work aims to develop even more efficient pruning methods.
- New Architectures: Exploring transfer-based methods that leverage importance patterns from previously pruned models to new architectures is a future direction.
- Broader Code LLM Exploration: Evaluating Flab-Pruner on a wider array of generative coding tasks and Code LLMs is planned.
- Release of Pruned Models: The authors plan to release pruned models and datasets to facilitate further research.
Summary updated