Mediator: Memory-efficient LLM Merging with Less Parameter Conflicts and Uncertainty Based Routing

Kunfeng Lai, Zhenheng Tang, Xinglin Pan, Peijie Dong, Xiang Liu, Haolan Chen, Li Shen, Bo Li, Xiaowen Chu · OpenReview

TL;DR

This paper introduces "Mediator," a novel LLM merging technique that intelligently combines averaging and routing strategies to overcome parameter conflicts and reduce memory costs. By adaptively merging low-conflict layers and routing high-conflict ones with task-specific experts, Mediator achieves superior performance on complex reasoning tasks while significantly reducing system overhead compared to existing methods.

What Problem Does This Paper Address?

Large Language Models (LLMs) are often fine-tuned for specific tasks, leading to a proliferation of specialized models. Merging these models offers a way to create a single, more capable LLM without extensive retraining. However, traditional methods like simple averaging suffer from "parameter conflicts," where fine-tuning on different tasks leads to conflicting parameter updates, degrading performance. Model routing, while avoiding conflicts, incurs substantial storage and computational costs by requiring all fine-tuned models to be loaded during inference. This paper addresses the challenge of merging LLMs effectively by balancing performance gains with memory and computational efficiency, particularly for real-world applications with diverse and potentially out-of-distribution inputs.

Methods

Mediator employs a multi-faceted approach:

  1. Adaptive Layer-wise Merging and Routing: The core idea is to leverage the observation that parameter conflicts vary across different layers of an LLM. Mediator identifies layers with low parameter conflicts and averages them to preserve shared knowledge. For layers with high conflicts, it uses a novel task-level expert routing mechanism. This adaptive strategy avoids the pitfalls of uniformly averaging or routing all layers.
  2. Expert Decomposition and Sparsity: To further reduce storage costs, Mediator decomposes fine-tuned models into a dense "base" expert and several sparse "task-specific" experts. This is inspired by the sparsity of task arithmetics (parameter differences between fine-tuned and base models). By sparsifying these task arithmetics, Mediator significantly compresses the storage requirements.
  3. Uncertainty-Based Expert Routing: For handling out-of-distribution (OOD) samples, Mediator uses a Bayesian approach to estimate task uncertainty. It dynamically selects and merges appropriate experts based on this uncertainty, allowing for more robust inference in real-world scenarios.

Datasets

The paper uses a variety of datasets for training and evaluation:

  • Finetuning Datasets: Publicly available datasets augmented with Chain-of-Thought (CoT) data generated by GPT-40. Specific datasets include:
  • Math: GSM8K Socratic Training Set, Orca-Math.
  • QA: Alpaca QA Pairs, WebQuestions, SQuAD v1 & v2.
  • Code: MBPP, Magicoder-Evol-Instruct, LeetCode, ConalaMineded.
  • Scalability Tasks: Magpie (Instruction Following), IndustryInstruction (Economics), DISC-Med (Medicine), DISC-Law (Law).
  • Evaluation Tasks:
    • Mathematical Reasoning: GSM8K.
  • Knowledge-based QA: TriviaQA, MMLU.
  • Code Generation: HumanEval.
  • Logical Reasoning: WinoGrande.
  • Multi-domain Knowledge: MMLU (covering Medicine, College Economics, Law).
  • Instruction Following: IFEval.

Key Insights and Ideas

  • Layer-wise Conflict Distribution: The paper's key insight is that parameter conflicts are not uniform across LLM layers. Front and back layers tend to have higher conflicts, suggesting they capture more task-specific knowledge, while middle layers share more common knowledge. This observation is crucial for the adaptive merging strategy.
  • Task Arithmetic Sparsity for Compression: Decomposing fine-tuned models into a base and sparse task-specific experts (task arithmetics) offers a significant avenue for memory compression, reducing storage from 50% to as low as 7%.
  • Uncertainty for OOD Robustness: Using task uncertainty to guide expert selection is a powerful way to handle out-of-distribution inputs, making the merged model more adaptable to real-world data.
  • Task-Level vs. Token-Level Routing: The paper argues for task-level routing over token-level routing in the context of model merging, as it better aligns with how LLMs are fine-tuned and avoids the complexity and cost of token-level routing.

Key Results

  • Performance Improvement: Mediator consistently achieves significant performance improvements on real-world reasoning tasks, often outperforming both individual fine-tuned models and other merging methods. For example, on Qwen 2.5 7B, Mediator achieved an average score of 71.00%, outperforming baselines.
  • Memory Efficiency: Mediator significantly reduces memory costs. By decomposing experts and using layer-wise merging, it achieves a compression ratio of up to 7x for 8 experts.
  • Inference Speed: Mediator's inference time is only slightly longer (0.2s to 0.4s) than that of a single LLM, making it much more efficient than token-level routing methods which can be more than 2x slower.
  • Scalability: Mediator demonstrates good scalability, maintaining performance improvements even when finetuning on more tasks.

Limitations and Future Work

  • Parameter Conflict Theory: The paper acknowledges that a theoretical foundation for parameter conflicts remains unexplored.
  • Scaling Challenges: While Mediator scales well to 8 models, expanding to hundreds or thousands of experts for applications like personalization poses deployment challenges.
  • Loading Time: Loading experts per sample remains a system bottleneck, although optimizations are discussed. Faster loading mechanisms are an area for future research.
  • Future Work: The authors suggest exploring theoretical foundations of parameter conflicts, optimizing for large-scale deployment, and developing faster expert loading mechanisms.

Summary updated

BibTeX
@misc{lai2025mediator,
  author = {Kunfeng Lai and Zhenheng Tang and Xinglin Pan and Peijie Dong and Xiang Liu and Haolan Chen and Li Shen and Bo Li and Xiaowen Chu},
  title = {{Mediator: Memory-efficient LLM Merging with Less Parameter Conflicts and Uncertainty Based Routing}},
  year = {2025},
  eprint = {2502.04411},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.04411},
}
Figure