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 · DOI

Overview

LoraRetriever is a novel "retrieve-then-compose" framework designed to empower Large Language Models (LLMs) with the ability to dynamically select and combine specialized LoRA (Low-Rank Adaptation) experts. By intelligently routing requests to the most relevant adapters in a massive, ever-growing pool, LoraRetriever enables LLMs to handle a diverse mix of tasks in real-time—even those they weren't explicitly trained for.

Addressing the Scaling Challenge in LoRA Serving

The rapid proliferation of specialized LoRA adapters for tasks like medical QA, legal drafting, or multilingual translation presents a significant serving challenge: how can we leverage thousands of experts simultaneously? Existing approaches typically fall into two categories, both with notable drawbacks:

  1. Static Mixture-of-Experts (MoE): These methods fix a set of LoRAs during training. Adding new experts requires retraining the entire routing system.
  2. Global Composition: Tools like LoRAhub optimize a single combination of LoRAs for an entire dataset, failing in dynamic "in the wild" scenarios where user prompts vary wildly from one moment to the next.

LoraRetriever addresses these gaps by being input-aware (selecting LoRAs per prompt), dynamic (allowing pool updates without retraining), and efficient (supporting high-throughput batch processing).

The LoraRetriever Architecture

The framework consists of three core components:

  1. Input-Aware Retrieval: Each LoRA is represented as an embedding derived from representative samples of its training data. Upon receiving a prompt, an instruction-tuned retriever calculates cosine similarity to identify the "Top-K" best-matching experts.
  2. LoRA Composition: Selected experts are combined via two strategies:
  3. Mixture of LoRAs: Outputs from individual LoRAs are averaged, providing robustness for Out-of-Distribution (OOD) tasks.
  4. Fusion of LoRAs: LoRA weights are averaged into a single parameter set, enabling faster single-pass computation.
  5. Efficient Batch Inference: To handle heterogeneous requests in a single batch, LoraRetriever utilizes a LoRA mapping matrix, ensuring that different prompts can utilize different experts without sacrificing GPU throughput.
The LoraRetriever architecture: (a) Input-Aware Retrieval, (b) Composition strategies, and (c) Batch Inference optimization.

Experimental Evaluation

The authors benchmarked LoraRetriever using a pool of 48 LoRAs trained on Flan-v2, covering 10 task clusters such as Commonsense Reasoning and Translation. A "Mixed Task" dataset of 6,000 shuffled samples was used to simulate real-world usage.

Key Insights

  • Data as a Proxy: A LoRA's expertise can be effectively represented by the semantic space of its training data rather than its internal weights.
  • Instruction-Tuned Retrieval: Fine-tuning the retriever with specific instructions is crucial for generalizing to unseen tasks.
  • Generalization via Similarity: The system can solve novel tasks by composing "related" experts (e.g., combining German-English and English-French adapters for German-French translation).

Performance and Efficiency

LoraRetriever consistently outperformed baselines like MoE and LoRAhub across NLU and NLG tasks. Notably, it maintained high accuracy even in OOD scenarios where the ideal adapter was unavailable. Furthermore, the custom batching strategy achieved throughput comparable to a single-LoRA setup, demonstrating that input-aware routing is computationally feasible at scale.

Performance metrics showing Mean Accuracy (IID and OOD) vs. number of LoRAs, and Throughput vs. Batch Size.

Limitations and Future Work

Current limitations include the requirement for training data samples to index LoRAs (raising privacy concerns) and the restriction to a single base model architecture (e.g., Llama-2-7b). Future research aims to align LoRA parameters directly in embedding space and bridge disparate model architectures.

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