LoraRetriever: Input-Aware LoRA Retrieval and Composition for Mixed Tasks in the Wild

Ziyu Zhao, Leilei Gan, Guoyin Wang, Wangchunshu Zhou, Hongxia Yang, Kun Kuang, Fei Wu

Introduction

Large Language Models (LLMs) have demonstrated remarkable general-purpose capabilities, yet they often struggle with highly specialized tasks. Low-Rank Adaptation (LoRA) has emerged as a popular solution for parameter-efficient fine-tuning on specific domains. However, as the ecosystem of specialized LoRAs grows—with thousands available on platforms like HuggingFace—a "paradox of choice" arises: how can a model dynamically select and combine the most relevant experts for an unpredictable user prompt?

Existing Mixture-of-Experts (MoE) approaches typically fix the set of experts during training, limiting scalability. Furthermore, real-world requests are often heterogeneous, requiring a blend of capabilities (e.g., sentiment analysis in a specific foreign language) that a single pre-trained expert might not cover.

Methods: The LoraRetriever Framework

LoraRetriever addresses these challenges through a "retrieve-then-compose" architecture. The framework is built on three pillars:

  1. Input-Aware LoRA Retrieval: Instead of a static router, LoraRetriever uses an instruction-tuned embedding model. Each LoRA in the pool is represented by an embedding derived from representative training samples. For any given prompt, the retriever identifies the top-k most relevant LoRAs.
  2. LoRA Composition: The system combines the retrieved experts using two primary strategies: Fusion (averaging weights) or Mixture (running LoRAs in parallel and averaging hidden states). The Mixture approach generally proves more robust for complex, multi-faceted tasks.
  3. Efficient Batch Inference: To maintain high throughput, the authors implemented a specialized batching strategy using a "LoRA mapping matrix" and optimized operations, allowing different requests in a single batch to utilize distinct sets of LoRAs simultaneously.
The LoraRetriever framework: Input-aware retrieval, composition, and batch inference.

Datasets and Evaluation

The framework was evaluated using a mixed-task benchmark featuring 48 distinct LoRAs trained on subsets of the Flan-v2 collection. These covered Natural Language Understanding (NLU) tasks like sentiment analysis and commonsense reasoning, as well as Natural Language Generation (NLG) tasks such as translation and data-to-text. Llama-2 (7B and 13B) served as the base models.

Key Insights

  • Plug-and-Play Scalability: By decoupling retrieval from the base model, new LoRAs can be added to the pool without retraining the LLM or the router.
  • Instructional Retrieval: Standard embeddings are insufficient for task-specific retrieval. Adding explicit instructions (e.g., "Represent the sentence for similar task retrieval") significantly improves accuracy.
  • Cross-Task Synergy: LoraRetriever can synthesize solutions for tasks it wasn't explicitly trained for by combining complementary experts, such as bridging language gaps through intermediate translation LoRAs.

Key Results

LoraRetriever consistently outperformed established baselines like MoE-LoRA and AdapterSoup. In In-Distribution (IID) scenarios, it matched the performance of manually selected "perfect" experts. Crucially, it demonstrated strong generalization in Out-of-Domain (OOD) settings by retrieving similar experts when an exact match was unavailable.

Performance and throughput analysis of LoraRetriever across different configurations.

As shown in the results, the "Mixture" strategy maintains high accuracy even as the number of retrieved LoRAs increases, whereas "Fusion" tends to degrade. Furthermore, the batching optimization ensures that dynamic expert selection does not compromise GPU throughput, remaining competitive with single-LoRA setups.

Limitations and Future Work

While effective, LoraRetriever currently requires representative data samples to embed each LoRA, which may pose privacy concerns. Additionally, the framework assumes all experts share the same base model architecture. Future research may explore more sophisticated collaboration mechanisms between experts beyond simple averaging.

Summary updated

BibTeX
@inproceedings{zhao2024loraretriever,
  author = {Ziyu Zhao and Leilei Gan and Guoyin Wang and Wangchunshu Zhou and Hongxia Yang and Kun Kuang and Fei Wu},
  title = {{LoraRetriever: Input-Aware LoRA Retrieval and Composition for Mixed Tasks in the Wild}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.263},
}
Figure