🧪 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.
Metadata
Release files for mergenetic 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mergenetic-0.1.1.tar.gz | 42.2 kB | With provenance | Details for mergenetic-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mergenetic-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for mergenetic-0.1.1-py3-none-any.whl |
Total release size: 93.3 kB
Release files / mergenetic-0.1.1.tar.gz
| Download URL | mergenetic-0.1.1.tar.gz |
|---|---|
| Size | 42.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d117716f843d534c5296b2d869bd9a5d7970e1608b3ca1b4b54c4e9dc85b105c
|
|
BLAKE2b-256 checksum How to use checksums |
a18eef0593bb8c8b6b6390cb05ffa336eac9fdd5182e11eadd69940ec51ec529
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 20, 2025.
Transparency logRelease files / mergenetic-0.1.1-py3-none-any.whl
| Download URL | mergenetic-0.1.1-py3-none-any.whl |
|---|---|
| Size | 51.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c9a0e25c24e0fb5aea33653cd9f597830ff992d91c6800420ca2ea21549c981
|
|
BLAKE2b-256 checksum How to use checksums |
888a33302c5dd1cb28e9d49b435783cc5dd1b2ab91b94f684bdb50c99b7e0765
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 20, 2025.
Transparency logSecurity for mergenetic 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mergenetic-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 20, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.