FanLoRA: Fantastic LoRAs and Where to Find Them in Large Language Model Fine-tuning

Aaron Xuxiang Tian, Yi Zhao, Congrui Yin, Wei Zhu, Xing Tian, Yi GeEMNLP 2024

TL;DR

Fine-tuning large language models (LLMs) is computationally expensive. While Parameter-Efficient Fine-Tuning (PEFT) methods like LoRA help, they can introduce significant latency in multi-tenant systems. This paper introduces FanLoRA, a framework that intelligently selects a minimal set of LoRA modules per Transformer layer, drastically reducing inference latency without sacrificing performance, making LLMs more practical for industrial use.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown remarkable capabilities, but fine-tuning them for specific tasks is often prohibitively expensive due to their massive parameter counts. Parameter-Efficient Fine-Tuning (PEFT) methods, such as Low-Rank Adaptation (LoRA), have emerged as a popular solution. LoRA works by injecting small, trainable low-rank matrices into the existing weights of a pre-trained LLM, significantly reducing the number of trainable parameters. However, a key challenge with LoRA and its variants is that they often require adding these modules to many linear layers within the Transformer architecture. This leads to increased computational overhead during inference, particularly in multi-tenant environments where a single LLM backbone must serve multiple users or tasks simultaneously. Merging LoRA parameters back into the main model is not always feasible in these scenarios, exacerbating the latency issue. The paper aims to address this by finding a way to select only the most critical LoRA modules, thereby minimizing inference latency while maintaining high performance.

Methods

The FanLoRA framework consists of four main steps:

  1. Full LoRA Fine-tuning: Initially, LoRA modules (with a chosen rank) are added to all linear weights within each Transformer layer. The model is then fine-tuned on a large-scale instruction tuning dataset. This step allows all LoRA modules to acquire knowledge from diverse tasks.
  2. Importance Scoring: A novel "ablation-based score" (AB-score) is introduced to quantify the importance of each individual LoRA module. This method involves systematically zeroing out specific LoRA modules and observing the impact on model performance on a validation set. By comparing performance across four scenarios (full LoRA, LoRA module ablated, all LoRAs ablated, and only the specific LoRA module active), the AB-score effectively measures a module's contribution.
  3. FanLoRA Setting Selection: Based on the AB-scores, a sparse set of LoRA modules is selected for each Transformer layer. Specifically, the authors keep at most $K_{max}$ modules per layer, and any module with a negative importance score is pruned. This results in the "FanLoRA setting."
  4. Downstream Task Fine-tuning: The selected FanLoRA modules, initialized randomly, are then fine-tuned on specific downstream tasks.

Datasets

The paper utilizes the following datasets:

  • UltraChat: A large-scale, open-source, multi-round dialogue dataset used for the initial full LoRA fine-tuning step.
  • Downstream Tasks:
    • Question Answering: SQuAD, BoolQ, COPA.
  • General LLM Evaluation: MT-Bench, MMLU, LLM-Eval1.
  • Math Reasoning: HSM10K (a proprietary high-school level math problem dataset).
  • SQL Generation: Q2SQL (a proprietary dataset of SQL queries and natural language questions).

Key Insights and Ideas

  • Not all LoRA modules are created equal: The core insight is that a significant portion of LoRA modules added during the initial full fine-tuning phase might not be critical for downstream performance.
  • Intelligent pruning is key: By developing an effective importance scoring mechanism (AB-score), FanLoRA can identify and retain only the most impactful LoRA modules.
  • Layer-wise importance varies: The importance of LoRA modules is not uniform across Transformer layers. Lower layers tend to benefit more from LoRA modules in the self-attention components (Query, Key), while higher layers show more importance in the Feed-Forward Network (FFN) components (Gate, Up, Down).
  • Transferability of the FanLoRA setting: The selected FanLoRA setting, derived from general instruction tuning, proves to be broadly applicable across diverse downstream tasks.
  • Efficiency gains are substantial: The drastic reduction in the number of active LoRA modules leads to significant improvements in inference speed and reduced memory usage.

Key Results

  • Performance: FanLoRA consistently outperforms existing PEFT baselines (including LoRA, AdaLoRA, and (IA)³) across a wide range of tasks (question answering, general LLM evaluation, math reasoning, SQL generation) with comparable or fewer tunable parameters. For instance, on the SQuAD benchmark, FanLoRA achieved 83.1 accuracy with 8.6M parameters, outperforming LoRA (81.8 accuracy, 10.0M parameters) and AdaLoRA (82.2 accuracy, 10.0M parameters).
  • Efficiency: FanLoRA significantly reduces inference latency. The paper shows that FanLoRA is much faster than AdaLoRA, with comparable GPU memory costs. This is attributed to the drastically fewer LoRA modules that need to be computed per token.
  • Stability: The FanLoRA setting is shown to be stable across different random seeds, indicating reliable importance score estimations.
  • Impact of $K_{max}$: The optimal number of kept LoRA modules per layer ($K_{max}$) was found to be 2, validating the paper's default experimental setting. Increasing $K_{max}$ beyond this point led to performance degradation, suggesting the inclusion of less effective or even detrimental modules.

Limitations and Future Work

  • Model Scale: The experiments were primarily conducted on 7B parameter models. The authors acknowledge that testing on larger models (20B or 70B parameters) was limited by computational resources, and future work could explore this.
  • Task Diversity: While a good range of tasks was covered, other NLP tasks like information extraction were not explored. The authors believe their framework is transferable and would be interested in investigating its performance on these tasks and with different backbone architectures.
  • Safety Aspects: The paper focuses on performance and efficiency. Future work could investigate how FanLoRA affects the safety aspects of LLMs.

Summary updated

BibTeX
@inproceedings{tian2024fanlora,
  author = {Aaron Xuxiang Tian and Yi Zhao and Congrui Yin and Wei Zhu and Xing Tian and Yi Ge},
  title = {{FanLoRA: Fantastic LoRAs and Where to Find Them in Large Language Model Fine-tuning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
}
Figure