Skip to content
ehristoforuPublic

Repository files navigation

PolyMerge Logo

PolyMerge

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.

CI License Python Format Colab


Overview

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.

Key Capabilities

  • 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, and passthrough.
  • 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.

Benchmarks

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.

Google Colab Hardware Throughput Benchmark


Throughput Benchmark


RAM Consumption Benchmark


Comparison

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

Installation

git clone https://github.com/ehristoforu/polymerge.git
cd polymerge
pip install -e ".[all]"

Quick Usage

YAML Configuration Specification

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: true

For Qwen3.5/3.6 VLM checkpoints, ignore_vision: true strips the visual tower, flattens text_config to the root and renames model.language_model.* to model.*, producing a loadable Qwen3_5MoeForCausalLM checkpoint. Set ignore_vision: false to keep the multimodal layout.

Model Merging

# Run merge from YAML config
polymerge config.yaml -o ./merged_model

MoE Upcycling

polymerge examples_configs/moe_qwen_shared_expert.yaml -o ./assembled_moe --moe

Model Pruning

# 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

Speech Models (ASR / TTS)

# 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

LoRA Operations

# 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_model

Documentation

Detailed technical documentation and mathematical formulations:


Upstream Acknowledgements

PolyMerge integrates and expands upon algorithms, tooling and research from the open-source community.

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.


Contributing

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.


License

This project is licensed under the GNU General Public License v3.0.

Releases

Contributors

Languages