Mergoo: Efficiently Merge and Train Multiple LLM Experts

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Mergoo: Efficiently Merge and Train Multiple LLM Experts

Summary

Mergoo is an open-source Python library designed to simplify the merging of multiple Large Language Model (LLM) experts. It enables efficient training of these merged LLMs, allowing users to integrate knowledge from various generic or domain-specific models. The library supports several merging methods, including Mixture-of-Experts and Mixture-of-Adapters, across popular base models.

Repository Information

Analyzed by OSRepos on July 7, 2026

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

Mergoo is a powerful Python library developed by Leeroo-AI, aimed at streamlining the process of combining multiple Large Language Model (LLM) experts and efficiently training the resulting merged model. This library is particularly useful for integrating diverse knowledge bases from different LLM experts, whether they are generic or specialized for specific domains. Mergoo offers robust support for various merging techniques, including Mixture-of-Experts (MoE), Mixture-of-Adapters (MoA), and Layer-wise merging, providing flexibility in how models are combined.

Key features of Mergoo include:

  • Multiple Merging Methods: Supports Mixture-of-Experts, Mixture-of-Adapters, and Layer-wise merging.
  • Flexible Layer Merging: Allows for flexible merging configurations for each layer.
  • Broad Base Model Support: Compatible with popular models like Llama (including LLaMa3), Mistral, Phi3, and BERT.
  • Trainer Integration: Works seamlessly with Hugging Face's Trainer, SFTrainer, and PEFT.
  • Device Compatibility: Supports CPU, MPS, and GPU environments.
  • Training Choices: Offers options to train only the Router of MoE layers or perform full fine-tuning of the merged LLM.

Installation

Getting started with Mergoo is straightforward. You can install it using pip:

pip install mergoo

For the latest unstable version directly from GitHub:

pip install git+https://github.com/Leeroo-AI/mergoo

Alternatively, you can install it from the source:

git clone https://github.com/Leeroo-AI/mergoo
cd mergoo
pip install -e .

Examples

Mergoo simplifies the configuration and merging process. Here are examples for setting up configurations for different merging scenarios.

Fully Fine-tuned Experts

This configuration demonstrates merging fully fine-tuned LLM experts, such as combining math and code-specific Mistral models.

config = {
    "model_type": "mistral",
    "num_experts_per_tok": 2,
    "experts": [
        {"expert_name": "base_expert", "model_id": "mistralai/Mistral-7B-v0.1"},
        {"expert_name": "expert_1", "model_id": "meta-math/MetaMath-Mistral-7B"},
        {"expert_name": "expert_2", "model_id": "ajibawa-2023/Code-Mistral-7B"}
    ],
    "router_layers": ["gate_proj", "up_proj", "down_proj"]
}

Mixture of Adapters (MoE on LoRA)

Mergoo can also build a routing layer on top of LoRAs, creating a Mixture of Adapters. This is ideal for merging LoRA fine-tuned LLM experts.

config = {
    "model_type": "mistral",
    "num_experts_per_tok": 2,
    "base_model": "mistralai/Mistral-7B-v0.1",
    "experts": [
        {"expert_name": "adapter_1", "model_id": "predibase/customer_support"},
        {"expert_name": "adapter_2", "model_id": "predibase/customer_support_accounts"},
        {"expert_name": "adapter_3", "model_id": "predibase/customer_support_orders"},
        {"expert_name": "adapter_4", "model_id": "predibase/customer_support_payments"}
    ],
}

After configuring, you can merge and save the checkpoint:

import torch
from mergoo.compose_experts import ComposeExperts

model_id = "data/mistral_lora_moe"
expertmerger = ComposeExperts(config, torch_dtype=torch.float16)
expertmerger.compose()
expertmerger.save_checkpoint(model_id)

Then, load and fine-tune the merged model using Hugging Face Trainer:

from transformers import Trainer
from mergoo.models.modeling_mistral import MistralForCausalLM

model = MistralForCausalLM.from_pretrained("data/mistral_lora_moe") 
# NOTE: 'gate' / router layers are untrained hence weight loading warning would appeare for them

trainer = Trainer( ... )
trainer.train()

Why Use Mergoo?

Mergoo addresses the growing need to combine specialized LLMs effectively. By providing a flexible and efficient framework for merging, it allows developers and researchers to:

  • Leverage Diverse Expertise: Integrate knowledge from multiple domain-specific or task-specific LLMs into a single, more capable model.
  • Improve Model Performance: Potentially enhance performance on complex tasks by routing inputs to the most relevant expert or combining their strengths.
  • Reduce Training Costs: Efficiently train merged models, focusing on router layers or specific components, rather than retraining entire large models from scratch.
  • Simplify Complex Workflows: Abstract away the complexities of implementing Mixture-of-Experts or Mixture-of-Adapters architectures.
  • Stay Current: Support for the latest LLMs like Llama3 and integration with Hugging Face ecosystem ensures compatibility with modern AI practices.

Links

Explore Mergoo further through these official resources:

Related repositories

Similar repositories that may be relevant next.

Memoripy: An AI Memory Layer for Context-Aware Applications

Memoripy: An AI Memory Layer for Context-Aware Applications

July 5, 2026

Memoripy is a Python library designed to provide an AI memory layer for context-aware applications. It offers both short-term and long-term storage, semantic clustering, and optional memory decay. This robust tool helps AI systems manage and retrieve relevant information efficiently, supporting various LLM APIs like OpenAI and Ollama.

aillmmemory
claude-mem: Persistent Context Across Sessions for AI Agents

claude-mem: Persistent Context Across Sessions for AI Agents

May 20, 2026

claude-mem is an innovative GitHub repository designed to provide persistent context across sessions for various AI agents. It intelligently captures agent activities, compresses them using AI, and injects relevant information into future interactions. This powerful tool supports a wide range of AI platforms, including Claude Code, OpenClaw, Gemini, and Copilot.

ai-agentspersistent-memoryclaude-code
AutoGen: A Programming Framework for Agentic AI

AutoGen: A Programming Framework for Agentic AI

March 30, 2026

AutoGen is a versatile programming framework from Microsoft designed for building multi-agent AI applications. It empowers AI agents to operate autonomously or collaborate seamlessly with human users, streamlining the execution of complex tasks. The framework offers a layered, extensible design, providing both high-level APIs for rapid prototyping and low-level components for fine-grained control.

agentic-aimulti-agentllm-framework
EasyEdit: An Easy-to-Use Knowledge Editing Framework for LLMs

EasyEdit: An Easy-to-Use Knowledge Editing Framework for LLMs

January 26, 2026

EasyEdit is an open-source framework designed for efficient knowledge editing in Large Language Models (LLMs). It provides a unified, easy-to-use platform to modify, insert, or erase specific knowledge within LLMs without negatively impacting overall performance. This tool is crucial for aligning LLMs with evolving user needs and correcting factual inaccuracies.

artificial-intelligenceknowledge-editinglarge-language-models

Source repository

Open the original repository on GitHub.

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️