Merge anything. No model classes. No waiting for support.
High-performance, architecture-agnostic model merging, upcycling, and pruning engine for language, ASR and TTS models.
PolyMerge is a unified engine for combining, transforming, and compressing language, ASR and TTS models at the raw tensor level. It eliminates framework-level dependencies on model classes, enabling immediate support for any current or newly released architecture without upstream updates.
- Zero-Class Architecture Agnostic: Direct tensor streaming across SafeTensors and GGUF files without instantiating modeling code.
- Vision Layer Isolation: Automatic regex filtering of multimodal/vision layers (
visual.*,vision_tower.*,mm_projector.*). - Modern Merge Algorithms: 13 methods, including
linear,slerp,nuslerp,karcher,nearswap,task_arithmetic,ties,dare_ties,della,omnimerge_v2,model_stock,sce, andpassthrough. - Sanity Audit & Collapse Diagnostics: Standalone audit (
--audit) of NaN/Inf parameters and MoE router matrix condition numbers to catch degeneration before serving. - GGUF Merge/Quantize & Hub Publication: CPU-side GGUF merging via the Python API (
GGUFMergeEngine, dequantized per tensor, F16 output by default), llama.cpp post-quantization (QuantizerTool), plus one-command repository publishing (--push-to-hub). - Parameter Evolution Grid: Parameter search optimization across mixing ratios and densities.
- Universal MoE Upcycling: Assembles sparse Mixture-of-Experts models from dense checkpoints (Mixtral, Qwen2/2.5, DeepSeek, GigaChat4).
- Zero-Backprop Pruning: Dense layer removal with local residual healing and MoE expert pruning with T18 Soft-Transfer router recovery.
- ASR & TTS Merging: Architecture-agnostic speech merge with audio-config validation, component-aware weights (
encoder,decoder,vocoder,speaker,audio_tower) and optional experimental FFN-to-MoE upcycling for ASR/TTS. - Complete LoRA Toolkit: Truncated SVD extraction, in-place base baking, and multi-adapter combination.
- Memory & Staging Optimization: Sequential chunked I/O, chunked delta math, and multi-pass staged pipelines for memory-constrained hardware.
Analytical estimates, not measured runs. benchmarks/model_benchmarks.py models three 8B BF16 checkpoints (linear merge, 2 GB chunks, 64.2 GB moved) on Google Colab Free Tier hardware (Xeon CPU, Tesla T4 GPU, TPU) and a NVIDIA GeForce RTX 3060 12GB / 32GB RAM machine. TPU applies to PolyMerge only: MergeKit routes to CPU/XPU/CUDA and OmniMergeKit to CPU/CUDA, neither has a supported torch_xla backend. Throughput comes from effective single-pass stream rates scaled by each tool's I/O structure, read from competitor implementations: MergeKit's 5 GB lazy shard graph, OmniMergeKit's 50M-element fp32 chunks, and mergoo's full AutoModel loading (48.2 GB peak, OOM on 32 GB). Model output: PolyMerge peaks at 9.4 GB RAM, MergeKit at 28.0 GB, OmniMergeKit at 14.7 GB.
| Feature | Standard Tools | Single-Task Scripts | PolyMerge |
|---|---|---|---|
| Zero-Class Architecture Support | No | Partial | Full |
| Multimodal / Vision Auto-Filter | No | Manual | Automatic |
| All 13 Merge Methods | Partial | Partial | Full |
| ASR / TTS Component-Aware Merge | No | Manual | Native |
| MoE Upcycling (Dense to MoE) | Limited | No | Full (4 Targets) |
| Shared Expert Support | No | Limited | Native |
| Zero-Retraining Pruning | No | Script-based | Integrated |
| Direct GGUF Merging | No | External | Python API |
| LoRA SVD Extract & Bake | Partial | No | Integrated |
| Low-RAM Multi-Stage Pipeline | No | No | Native |
| Hardware Routing | CPU/GPU | CPU/GPU | CPU / GPU / TPU |
git clone https://github.com/ehristoforu/polymerge.git
cd polymerge
pip install -e ".[all]"PolyMerge accepts declarative YAML configuration files describing the base model, fine-tunes, weights, densities, and methods.
# config.yaml - Example DARE-TIES Merge
merge_method: dare_ties
base_model: meta-llama/Llama-3.2-1B
models:
- model: meta-llama/Llama-3.2-1B-Instruct
parameters:
weight: 0.6
density: 0.5
- model: meta-llama/Llama-3.2-1B
parameters:
weight: 0.4
density: 0.5
parameters:
normalize: true
dtype: bfloat16
ignore_vision: trueFor Qwen3.5/3.6 VLM checkpoints,
ignore_vision: truestrips the visual tower, flattenstext_configto the root and renamesmodel.language_model.*tomodel.*, producing a loadableQwen3_5MoeForCausalLMcheckpoint. Setignore_vision: falseto keep the multimodal layout.
# Run merge from YAML config
polymerge config.yaml -o ./merged_modelpolymerge examples_configs/moe_qwen_shared_expert.yaml -o ./assembled_moe --moe# Dense layer pruning with residual healing
polymerge --prune-dense --base meta-llama/Llama-3.2-1B -o ./pruned_model --drop-fraction 0.2
# MoE expert pruning with soft-transfer router recovery
polymerge --prune-moe --base google/gemma-4-26B-A4B-it -o ./gemma_64e --target-experts 64 --alpha 0.3# Domain/language ASR merge, encoder 0.7x / decoder 1.0x
polymerge examples_configs/12_asr_whisper_domain_merge.yaml -o ./whisper-merged
# TTS speaker/emotion attribute interpolation
polymerge examples_configs/13_tts_attribute_merge.yaml -o ./tts-merged
# Experimental dense-to-MoE upcycling of speech FFN blocks
polymerge examples_configs/14_asr_whisper_speech_moe.yaml -o ./whisper-moe --speech-moe# SVD LoRA extraction
polymerge --extract-lora --base /path/base --tuned /path/tuned -o ./my_lora --rank 16
# Direct bake into base
polymerge --merge-lora --base /path/base --adapter ./my_lora -o ./baked_modelDetailed technical documentation and mathematical formulations:
- Merge Methods & Formulas
- MoE Upcycling Architecture
- Model Pruning & Recovery
- Layer Slicing
- LoRA Tools
- Tokenizer Alignment
- ASR & TTS Merging
- Hardware & Optimization
- CLI Reference
PolyMerge integrates and expands upon algorithms, tooling and research from the open-source community.
- OmniMergeKit (MIT): tensor-level streaming,
omnimerge_v2, T18 router recovery and expert pruning. - MergeKit (LGPL-3.0): merge methods, YAML configs, MoE upcycling and slicing foundations.
- MergeKitty (LGPL-3.0-or-later): out-of-core merging, LoRA handling and tokensurgeon.
- Mergoo (LGPL-3.0): early dense-to-MoE composition; the original
mergoorepository is no longer publicly reachable. - MergeUI (Apache-2.0): merge-graph and UI design.
- PruneMe: layer pruning via inter-block similarity; based on arXiv:2403.17887.
- MergeWhisper (LGPL-3.0): ASR/Whisper merging and speech metadata; paper arXiv:2603.05354.
- model-merge-tts: TTS attribute interpolation; Interspeech 2024 paper.
- Emoji-TTS / Irodori-TTS (MIT): flow-matching TTS reference and Irodori-TTS-500M-v3.
Speech upcycling also draws on UME (arXiv:2412.17507), Speech-FT (arXiv:2502.12672) and Whisper decoder FFN upcycling (Shinayama et al., Interspeech 2026).
Full credits, licenses and paper links: ACKNOWLEDGEMENTS.md.
See CONTRIBUTING.md for setup, tests and pull-request rules. Security reports go through SECURITY.md. Contributing docs are welcome — new architectures should fail fast rather than write silently broken checkpoints.
This project is licensed under the GNU General Public License v3.0.