Flexible library for merging large language models (LLMs) via evolutionary optimization (ACL 2025 Demo).
Jupyter Notebook
107
87 commits
updated Aug 8, 2025
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.
mergekit for merging, pymoo for optimisation, and lm‑eval‑harness for metrics.You can install the latest release directly from PyPI:
pip install mergenetic
Or update an existing installation:
pip install --upgrade mergenetic
Another option is to create a conda environment and install it from source:
git clone https://github.com/tommasomncttn/mergenetic.git
cd mergenetic
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.
The fastest way to see Mergenetic in action is the Colab notebook here
| 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 |
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)
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()
python -m mergenetic.cli \
--merge-type single \
--eval-method lm-eval \
--models mistral-7b math-7b \
--task gsm8k-it
An interactive wizard will guide you through the remaining options. See cli/README.md for the full reference.
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.
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.
notebooks/Cross_Lingual_Math_Merging.ipynbBug reports, feature requests and pull requests are very welcome! Please read CONTRIBUTING.md before you start.
@inproceedings{minut-etal-2025-mergenetic,
title = "Mergenetic: a Simple Evolutionary Model Merging Library",
author = "Minut, Adrian Robert and
Mencattini, Tommaso and
Santilli, Andrea and
Crisostomi, Donato and
Rodol{\`a}, Emanuele",
editor = "Mishra, Pushkar and
Muresan, Smaranda and
Yu, Tao",
booktitle = "Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)",
month = jul,
year = "2025",
address = "Vienna, Austria",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2025.acl-demo.55/",
pages = "572--582",
ISBN = "979-8-89176-253-4"
}
Licensed under the Apache 2.0 licence – see the LICENSE file for details.
514 followers · starred May 2025
Jupyter Notebook
76.6%
Python
23.3%
Flexible library for merging large language models (LLMs) via evolutionary optimization (ACL 2025 Demo).
Jupyter Notebook
107
87 commits
updated Aug 8, 2025
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.
mergekit for merging, pymoo for optimisation, and lm‑eval‑harness for metrics.You can install the latest release directly from PyPI:
pip install mergenetic
Or update an existing installation:
pip install --upgrade mergenetic
Another option is to create a conda environment and install it from source:
git clone https://github.com/tommasomncttn/mergenetic.git
cd mergenetic
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.
The fastest way to see Mergenetic in action is the Colab notebook here
| 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 |
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)
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()
python -m mergenetic.cli \
--merge-type single \
--eval-method lm-eval \
--models mistral-7b math-7b \
--task gsm8k-it
An interactive wizard will guide you through the remaining options. See cli/README.md for the full reference.
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.
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.
notebooks/Cross_Lingual_Math_Merging.ipynbBug reports, feature requests and pull requests are very welcome! Please read CONTRIBUTING.md before you start.
@inproceedings{minut-etal-2025-mergenetic,
title = "Mergenetic: a Simple Evolutionary Model Merging Library",
author = "Minut, Adrian Robert and
Mencattini, Tommaso and
Santilli, Andrea and
Crisostomi, Donato and
Rodol{\`a}, Emanuele",
editor = "Mishra, Pushkar and
Muresan, Smaranda and
Yu, Tao",
booktitle = "Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)",
month = jul,
year = "2025",
address = "Vienna, Austria",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2025.acl-demo.55/",
pages = "572--582",
ISBN = "979-8-89176-253-4"
}
Licensed under the Apache 2.0 licence – see the LICENSE file for details.
514 followers · starred May 2025
Jupyter Notebook
76.6%
Python
23.3%