Merging Models That Don't Exist Yet

Community Article
Published November 29, 2026

A practical look at PolyMerge, a tensor-level merger for LLMs, ASR and TTS.

I built PolyMerge because I got tired of waiting for architecture support.

Not waiting for hardware, or for a model to download, but waiting for merge tools to learn about new models. A checkpoint would appear on a Friday, I would write a merge config, and the tool would stop at the first tensor: unknown architecture. Then I would wait for a pull request that adds a JSON definition, a model class, or a tokenizer mapping. The weights were already on disk. The arithmetic had not changed. Only the names of the tensors had changed.

PolyMerge takes a different route. It does not instantiate LlamaForCausalLM, WhisperForConditionalGeneration, or any other model class. It reads SafeTensors or GGUF, streams one tensor at a time, applies the merge method, and writes the result. If two checkpoints have compatible tensor names and shapes, the merge works. If they do not, it fails with an error instead of producing a checkpoint that loads and then behaves strangely.

That sounds simple. Most of the work turned out to be in the details: memory, metadata, quantisation scales, and the difference between a model that loads and a model that is actually correct.

The architecture registry problem

MergeKit is an excellent piece of software, and PolyMerge borrows ideas from it, from MergeKitty, Mergoo, OmniMergeKit and other projects. The issue is not quality. It is coverage.

Framework-level mergers need an architecture description before they can touch a model: which tensors are layer templates, which are embeddings, how many layers there are, which files to copy. That is a reasonable design. It is also a bottleneck when a new family appears, especially in speech, where there is no single canonical layout. A hybrid MoE with fused expert tensors may look nothing like a Llama checkpoint, and a TTS model may keep its vocoder in a separate repository.

A merge method itself does not care about any of this. Linear interpolation is:

Wmerged=∑iwiWi W_{\text{merged}} = \sum_i w_i W_i

Task arithmetic is:

Wmerged=Wbase+λ∑iwi(Wi−Wbase) W_{\text{merged}} = W_{\text{base}} + \lambda \sum_i w_i (W_i - W_{\text{base}})

DARE-TIES adds dropout, sign consensus and election. None of those operations needs to know whether a tensor belongs to an attention block, an expert, a vocoder or an audio encoder. They need the tensor, a weight, and a bounded amount of memory.

PolyMerge is built around that observation. It knows less about the architecture, and therefore works on more of them. The trade-off is real: it cannot merge different architectures into each other. Whisper into Llama is not a merge, it is a research project.

What the engine does

The core is a reader, a writer, a regex filter, and a set of merge methods. Around that core:

  • 13 methods: linear, SLERP, NuSLERP, Karcher, nearswap, task arithmetic, TIES, DARE-TIES, DELLA, OmniMerge v2, Model Stock, SCE and passthrough.
  • SafeTensors and GGUF, including FP8 weights with scalar, per-row, per-column and block scales.
  • MoE layouts with per-expert tensors and fused Qwen3.5/3.6 experts (experts.gate_up_proj, experts.down_proj).
  • Optional filtering of vision towers and projectors.
  • ASR/TTS component routing: encoder, decoder, vocoder, speaker encoder, text encoder, audio tower.
  • Dense-to-MoE upcycling for Mixtral, Qwen2/2.5, DeepSeek and GigaChat4 backbones.
  • Pruning, slicing, LoRA extraction/baking, vocabulary alignment and GGUF quantisation around the merge itself.

A minimal config looks like this:

merge_method: dare_ties
base_model: Qwen/Qwen2.5-7B
models:
  - model: Qwen/Qwen2.5-Coder-7B-Instruct
    weight: 0.55
    density: 0.6
  - model: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
    weight: 0.45
    density: 0.6
dtype: bfloat16
ignore_vision: true
seed: 42
polymerge config.yaml -o ./merged-model --device cuda

No trust_remote_code, no loading a 70B model just to average its weights.

Streaming, chunking, and the memory wall

The first version read a tensor with safe_open, merged it, and wrote it. That worked until I tried a model with a 128k vocabulary on a GPU with less VRAM than the embedding layer. The largest tensor was several gigabytes in FP32, and the merge stack made it worse: every source delta was materialised at once.

The fix was chunking. TIES, DELLA, OmniMerge, SCE and Model Stock now process a bounded number of elements at a time. DARE masks are produced chunk-wise from a seed, so the same config gives the same result twice. For a five-source merge of a 35B MoE, that is the difference between a reasonable peak and an out-of-memory error.

Concrete numbers help. Qwen3.6-35B-A3B has 35.95B parameters and 256 experts with hidden size 2048 and expert intermediate size 512. Its fused gate_up_proj tensor has 256 × 1024 × 2048 = 536,870,912 elements, which is about 1.07 GB in BF16 and 2.15 GB in FP32. A DARE-TIES merge with a base and four sources holds the source tensors, an FP32 base copy, an accumulator, boolean masks and int16 counters. That lands around 14 GB on the compute device, before chunk temporaries. DELLA additionally needs a keep-probability buffer per source; storing it in FP16 instead of FP32 brought a five-source case from roughly 25 GB to about 20 GB.

There is still a hard limit. DELLA and OmniMerge need a global top-k over a tensor, and that requires a full-size pass. I do not pretend otherwise. If you merge huge fused-expert tensors at low density on a 24 GB card, you may need to watch memory or use CPU.

Disk matters too. Five BF16 checkpoints of a 35B model plus the output are about 432 GB. Five Q4 GGUF files plus an F16 intermediate and an F16 output are about 254 GB. That is often the difference between a 400 GB host being usable and not.

What the numbers look like

These are analytical estimates, not measured runs. I did not have a stable way to benchmark MergeKit, OmniMergeKit and PolyMerge on identical hardware with identical downloads, so the repository contains benchmarks/model_benchmarks.py. It models three 8B BF16 checkpoints (linear merge, 2 GB chunks, 64.2 GB moved), using each tool's shard strategy and an effective stream rate for CPU, T4 and TPU. The tests check that the README numbers match the model.

Merge throughput, GB/s (higher is better)

Tool CPU (Colab) GPU T4 TPU
PolyMerge 0.55 1.90 3.10
OmniMergeKit 0.37 1.27 —
MergeKit 0.23 0.80 —

TPU is a PolyMerge-only row. MergeKit routes to CPU, XPU or CUDA; OmniMergeKit supports CPU and CUDA. Neither has a supported torch_xla path. PolyMerge's TPU path is experimental and not covered by CI.

Speedup on RTX 3060 12 GB (MergeKit = 1.0x)

Tool Speedup
PolyMerge 2.4x
OmniMergeKit 1.6x
MergeKit 1.0x

Peak RAM for the same merge (lower is better)

Tool Peak RAM Relative to MergeKit
PolyMerge 9.4 GB −67%
OmniMergeKit 14.7 GB −48%
MergeKit 28.0 GB baseline

The model is useful for reasoning about I/O, not a substitute for running the tools on your machine. It is deliberately published as a script, so the assumptions are visible and can be changed.

The unglamorous bugs

Most of the work was not merge math. It was metadata.

A checkpoint is weights plus a story about the weights. Copy config.json blindly and you can produce a model that loads and then behaves strangely. Keep an FP8 quantization_config after dequantising to BF16 and the loader will try to dequantise the wrong thing. Merge a Qwen3.5/3.6 VLM with ignore_vision and you cannot just delete the vision tower: the text weights live under model.language_model.*, the text-only class expects model.*, and the config lives inside text_config. The architecture has to be converted, including the tensor prefix and the config root, not renamed halfway.

GGUF has its own traps. The writer will happily hold every output tensor in memory until the final write, which is fine for a 1B model and fatal for a 35B one. Using F16 instead of F32 and spooling to a temporary file changed a 144 GB RAM requirement into something a normal machine can survive. The temporary file also has to live on the destination filesystem; a tmpfs /tmp would defeat the purpose.

Then there is the boring one. Rerunning a merge into the same folder left the old model.safetensors.index.json behind, so Hugging Face loaded the old shards instead of the new single file. PolyMerge now marks its output directory and cleans only files it created. If the directory contains a model it did not create, it refuses to touch it.

FP8 had a similar failure mode. A block-scale tensor shaped [out/128, in/128] can be expanded with repeat_interleave. A per-row scale shaped [out, 1] cannot be treated the same way: doing so applies the first row's scale to several rows and silently produces wrong weights. The code now recognises scalar, row, column, block and transposed-block layouts, and raises on anything else.

Speech models are tensors too

The ASR/TTS work started as an experiment. Whisper is an encoder-decoder transformer. VITS, XTTS, CosyVoice and F5-TTS are different architectures, but at the tensor level they are still weights with names. If two checkpoints are fine-tunes of the same base, averaging works the same way it does for LLMs.

The difference is component structure. A shared vocoder, codec, speaker encoder or audio tower often should come from the base while only the acoustic model changes. The config supports that directly:

merge_method: task_arithmetic
base_model: openai/whisper-small
models:
  - model: your-org/whisper-domain-a
    weight: 0.6
  - model: your-org/whisper-domain-b
    weight: 0.4
speech_profile: asr
speech_components: [encoder, decoder]
component_weights:
  encoder: 0.7
  decoder: 1.0

The engine warns when sample rates, mel bins or vocabulary sizes differ between checkpoints. It does not resample audio for you. That is a separate problem, and doing it implicitly would be dangerous.

Speech MoE is more experimental. Upcycling Whisper decoder FFNs into sparse experts is an active research direction, and there is published evidence that decoder FFN upcycling can help multilingual ASR. But stock Transformers does not read a .moe.* layout. PolyMerge exports the weights and a manifest and says plainly that a matching modeling class is required. I would rather ship an honest experimental tool than a checkpoint that loads and gives nonsense.

What PolyMerge is not

It is not a cross-architecture converter. It will not merge a Whisper encoder into a Llama decoder, and it will not invent tensor mappings for you.

It is not a replacement for evaluation. A merge that produces finite weights can still produce a worse model. Run your WER, your speaker similarity, your eval suite.

It is not magic for every layout. When it sees an unknown FP8 scale shape, a fused expert layout it does not understand, or a router without experts, it stops with an error. That is intentional. Silent corruption is worse than a failed merge.

Reproducing the checks

The repository has 119 tests, including regression tests for the failures above: stale indexes, FP8 per-row scales, fused expert pruning, Qwen3.6 text-only conversion, speech component routing, and GGUF metadata round-trips. The tests generate tiny SafeTensors in temporary directories; they never download models or require a GPU.

python -m pytest tests -q
PYTHONPATH=. python -m unittest discover tests -q
python -m compileall -q polymerge tests benchmarks

The real-GGUF round-trip test is skipped if the optional gguf package is not installed.

Try it

PolyMerge is GPL-3.0, Python 3.9+, and installs with:

pip install -e ".[all]"

The repository has YAML recipes for LLM, MoE, ASR and TTS merges, a Colab notebook, and documentation for the less obvious parts: FP8, GGUF, pruning, slicing, LoRA and speech.

If you merge something new, open an issue with the tensor layout. That is how the next architecture gets supported without waiting for anyone.

Community

The stale shard index is a good example of a merge that looks fine until you reload it. Does the preflight catch vocabularies with the same size but different token ID mappings before merging the embedding rows? That feels like something a simple load test could miss.

Sign up or log in to comment