Evolutionary model merging for LLMs
Project description
🧪 Mergenetic: Evolutionary Model Merging for LLMs
mergenetic is a flexible library for merging large language models (LLMs) via evolutionary optimization. It frames model merging as a black-box optimization problem and uses techniques like genetic algorithms and smart performance estimators to search for optimal weight combinations — enabling high-performance merges, even on consumer hardware.
✨ Why Mergenetic?
- State‑of‑the‑art merging techniques – linear soups, SLERP, TIES/DARE, Task Arithmetic and more.
- Hardware‑friendly – search in parameter space, not gradient space; no model must fit in memory twice.
- Modular & hackable – plug‑and‑play problems, searchers, mergers and evaluators.
- Familiar tools under the hood –
mergekitfor merging,pymoofor optimisation, andlm‑eval‑harnessfor metrics.
📚 Table of Contents
- Installation
- Quickstart
- Key Concepts
- Usage Examples
- Project Layout
- Learn More
- Contributing
- Citation
- License
🛠️ Installation
conda create --name mergenetic python=3.11 -y
conda activate mergenetic
pip install -r requirements.txt
pip install -e .
Heads‑up: some merge methods require bfloat16 support. Make sure your CUDA / ROCm stack is recent enough.
⚡ Quickstart
The fastest way to see Mergenetic in action is the Colab notebook here
🔑 Key Concepts
1. Merging Strategies
| Strategy | Multi‑model? | Needs base model? | Paper |
|---|---|---|---|
| Linear / Model Soups | ✅ | ❌ | arXiv:2203.05482 |
| SLERP | ❌ | ✅ | – |
| Task Arithmetic | ✅ | ✅ | arXiv:2212.04089 |
| TIES | ✅ | ✅ | arXiv:2306.01708 |
| DARE | ✅ | ✅ | arXiv:2311.03099 |
2. Evolutionary Algorithms
Mergenetic wraps every single‑ and multi‑objective optimiser in pymoo – GA, DE, CMA‑ES, NSGA‑II/III and many more. Simply import the one you need:
from pymoo.algorithms.soo.genetic_algorithm import GA
algorithm = GA(pop_size=32)
3. Evaluation & Fitness
- Native support for LM‑Eval Harness tasks
- Low‑cost proxies: IRT estimators or random sampling
- Bring‑your‑own metric by writing a single function
🚀 Usage Examples
Python API
from mergenetic.searcher import Searcher
from mergenetic.optimization.predefined_problems import CrossLingualMathProblem
from mergenetic.merging import SlerpMerger
from mergenetic.utils import ConfigLmEval
config = ConfigLmEval(**yaml.load(open("path/to/config.yaml"), Loader=yaml.FullLoader))
merger = SlerpMerger(...)
problem = CrossLingualMathProblem(...)
algorithm = GA(...)
searcher = Searcher(problem, algorithm, config.path_to_store_config, config.n_iter, config.run_id, config.seed)
searcher.search()
searcher.test()
Command‑Line Interface
python -m mergenetic.cli \
--merge-type single \
--eval-method lm-eval \
--models mistral-7b math-7b \
--task ita_gsm8k
An interactive wizard will guide you through the remaining options. See cli/README.md for the full reference.
Graphical Interface
Run the Gradio dashboard locally:
cd gui
pip install -r requirements.txt
python3 gui.py
…and configure experiments with dropdowns – no code required! See gui/README.md for the full details.
🗂️ Project Layout
mergenetic/
├── merging/ # adapters around mergekit strategies
├── optimization/ # pymoo problems for various tasks
├── evaluation/ # LM‑Eval & custom fitness functions
├── estimator/ # fast score predictors (IRT, sampling)
├── searcher/ # evolutionary loop orchestration
└── utils/ # config, logging, GPU helpers, …
Detailed docs for each module live in src/mergenetic/README.md.
📒 Learn More
- 📓 Tutorial notebook:
notebooks/Cross_Lingual_Math_Merging.ipynb - 🎞️ Video walk‑through: YouTube (5 min)
- 🔗 Related repos: mergekit · pymoo · lm‑eval‑harness
🤝 Contributing
Bug reports, feature requests and pull requests are very welcome! Please read CONTRIBUTING.md before you start.
🧠 Citation
@misc{minut2025mergeneticsimpleevolutionarymodel,
title={Mergenetic: a Simple Evolutionary Model Merging Library},
author={Adrian Robert Minut and Tommaso Mencattini and Andrea Santilli and Donato Crisostomi and Emanuele Rodolà},
year={2025},
eprint={2505.11427},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2505.11427},
}
📄 License
Licensed under the Apache 2.0 licence – see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mergenetic-0.1.1.tar.gz.
File metadata
- Download URL: mergenetic-0.1.1.tar.gz
- Upload date:
- Size: 42.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d117716f843d534c5296b2d869bd9a5d7970e1608b3ca1b4b54c4e9dc85b105c
|
|
| MD5 |
6d3b4d7fdb7849b67684b41cd186334e
|
|
| BLAKE2b-256 |
a18eef0593bb8c8b6b6390cb05ffa336eac9fdd5182e11eadd69940ec51ec529
|
Provenance
The following attestation bundles were made for mergenetic-0.1.1.tar.gz:
Publisher:
publish-to-pypi.yml on tommasomncttn/mergenetic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mergenetic-0.1.1.tar.gz -
Subject digest:
d117716f843d534c5296b2d869bd9a5d7970e1608b3ca1b4b54c4e9dc85b105c - Sigstore transparency entry: 215397256
- Sigstore integration time:
-
Permalink:
tommasomncttn/mergenetic@89faa31d0e0cf2247dfa3a94594cc0a9c60cb742 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tommasomncttn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@89faa31d0e0cf2247dfa3a94594cc0a9c60cb742 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mergenetic-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mergenetic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 51.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c9a0e25c24e0fb5aea33653cd9f597830ff992d91c6800420ca2ea21549c981
|
|
| MD5 |
6d4ba734ddc1c87106942d8f6a63f0d5
|
|
| BLAKE2b-256 |
888a33302c5dd1cb28e9d49b435783cc5dd1b2ab91b94f684bdb50c99b7e0765
|
Provenance
The following attestation bundles were made for mergenetic-0.1.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on tommasomncttn/mergenetic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mergenetic-0.1.1-py3-none-any.whl -
Subject digest:
4c9a0e25c24e0fb5aea33653cd9f597830ff992d91c6800420ca2ea21549c981 - Sigstore transparency entry: 215397258
- Sigstore integration time:
-
Permalink:
tommasomncttn/mergenetic@89faa31d0e0cf2247dfa3a94594cc0a9c60cb742 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tommasomncttn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@89faa31d0e0cf2247dfa3a94594cc0a9c60cb742 -
Trigger Event:
release
-
Statement type: