Flexora: Flexible Low Rank Adaptation for Large Language Models

Chenxing Wei, Yao Shu, Ying Tiffany He, Fei Richard Yu · DOI

Abstract

Low-Rank Adaptation (LoRA) has emerged as a standard for parameter-efficient fine-tuning (PEFT) of Large Language Models (LLMs). However, applying LoRA uniformly across all layers can lead to overfitting and performance degradation, particularly on complex reasoning tasks. We introduce Flexora, a framework that automates the selection of critical layers for task-specific adaptation. By treating layer selection as a bilevel optimization problem, Flexora identifies a "just right" subset of layers, reducing trainable parameters by up to 50% while consistently outperforming standard LoRA.

Introduction

The efficiency of LoRA stems from training low-rank adapter matrices while keeping the base model frozen. Despite its success, LoRA faces a significant challenge: determining which layers to adapt. Manual selection is labor-intensive and often suboptimal, while adapting all layers frequently leads to overfitting on smaller or specialized datasets. Flexora addresses this by providing an automated, mathematically grounded method to identify and tune only the most impactful layers for a given task.

Methodology

Flexora employs a three-stage pipeline designed to optimize layer selection without significant computational overhead.

The three-stage Flexora pipeline: (a) Initialization of selection hyperparameters, (b) Flexible Layer Selection via bilevel optimization, and (c) Final Fine-tuning of the selected subset.
  1. Initialization: A selection hyperparameter ($\alpha$) is injected into the LoRA formulation for each layer. This parameter acts as a gate, controlling the contribution of each layer's adapter to the final output.
  2. Flexible Layer Selection: Layer selection is framed as a bilevel optimization problem. Using Unrolled Differentiation (UD), the framework simultaneously optimizes model parameters on a training set and selection hyperparameters ($\alpha$) on a validation set. Layers with negative $\alpha$ values are discarded as non-critical.
  3. Fine-tuning: After identifying the critical layers, the model is reset. Non-critical layers are frozen, and adapters in the selected layers are retrained from scratch to eliminate noise from the selection phase.

Experimental Results

The researchers evaluated Flexora across several mainstream LLMs, including Llama3-8B, Mistral-7B, and Gemma-7B, using challenging benchmarks such as Hellaswag, PIQA, Winogrande, and RACE.

Performance and improvement ratios for Flexora on Llama-3-8B across multiple reasoning benchmarks.

As shown in the results for Llama-3-8B, Flexora consistently achieves higher accuracy than vanilla LoRA. Notably, it reached an average accuracy of 86.46% compared to 83.04% for standard LoRA, while utilizing 41% to 50% fewer trainable parameters. This demonstrates that "less is more" when it comes to layer-wise adaptation in LLMs.

Key Insights

  • Generalization through Sparsity: Theoretical analysis suggests that using a subset of layers improves generalization by simplifying the loss landscape, preventing the model from memorizing training noise.
  • Layer Importance Patterns: Empirical findings indicate that the initial and final layers of LLMs are often the most critical for task adaptation, while middle layers can sometimes be redundant or harmful.
  • Efficiency: The selection phase is highly efficient, typically requiring less than an hour on a single A100 GPU for standard datasets.

Conclusion

Flexora provides a robust solution to the layer selection problem in LoRA fine-tuning. By automating the identification of critical layers, it enhances model performance and reduces parameter counts. Future work includes extending Flexora to larger models (70B+) and exploring its effectiveness in multi-turn dialogue and specialized coding tasks.

Summary updated

BibTeX
@inproceedings{wei2025flexora,
  author = {Chenxing Wei and Yao Shu and Ying Tiffany He and Fei Richard Yu},
  title = {{Flexora: Flexible Low Rank Adaptation for Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure