Skip to main content

Pre-merge diagnostic framework for LLM model merging — analyze, diagnose, and optimize before you merge.

Project description

MergeLens

Pre-merge diagnostics for LLM model merging

PyPI Python License Downloads Tests


34% of top Open LLM Leaderboard models are merges, yet merging is blind trial-and-error. MergeLens tells you before you merge whether it will work — and which method to use.

Features

  • Single compatibility score — Merge Compatibility Index (MCI): 0-100, go/no-go verdict
  • 10 diagnostic metrics — cosine similarity, spectral overlap, sign disagreement, TSV interference, CKA, and more
  • Strategy recommender — optimal merge method + ready-to-paste MergeKit YAML
  • Conflict zone detection — pinpoints problematic layers
  • Interactive HTML reports — self-contained Plotly dashboards
  • MCP server — AI assistants can diagnose merges natively
  • Memory efficient — lazy safetensors loading, peak memory = 2× largest layer

Install

pip install mergelens

Optional extras:

pip install mergelens[report]  # Interactive HTML report generation
pip install mergelens[mcp]    # MCP server for AI assistants
pip install mergelens[audit]  # Capability probing (requires transformers)
pip install mergelens[all]    # Everything

Quick Start

CLI

Compare two models (local paths or HuggingFace Hub IDs):

mergelens compare model_a/ model_b/
mergelens compare meta-llama/Llama-3-8B mistralai/Mistral-7B-v0.1

Add a base model for task vector metrics:

mergelens compare model_a/ model_b/ --base base_model/

Generate an HTML report:

mergelens compare model_a/ model_b/ --report report.html

Diagnose a MergeKit config before running it:

mergelens diagnose merge.yaml

Python API

from mergelens import compare_models

result = compare_models(["model_a/", "model_b/"])

print(f"MCI: {result.mci.score}{result.mci.verdict}")
# MCI: 72.3 — compatible

Inspect conflicts and get a strategy recommendation:

for zone in result.conflict_zones:
    print(f"Layers {zone.start_layer}-{zone.end_layer}: {zone.severity.value}")

if result.strategy:
    print(f"Recommended: {result.strategy.method.value}")
    print(result.strategy.mergekit_yaml)  # copy-paste into MergeKit

Diagnose a MergeKit config:

from mergelens import diagnose_config

result = diagnose_config("merge.yaml")
print(f"Overall interference: {result.overall_interference:.4f}")

Metrics

Metric What It Measures Range Source
Cosine Similarity Weight vector alignment [-1, 1] Standard
L2 Distance Normalized weight divergence [0, +inf) Standard
KL Divergence Weight distribution difference [0, +inf) Standard
Spectral Subspace Overlap Top-k SVD direction alignment [0, 1] Zhou et al. 2026
Effective Rank Ratio Dimensionality compatibility [0, 1] Shannon entropy
Sign Disagreement Rate Parameter sign conflicts [0, 1] TIES-Merging (Yadav et al. 2023)
TSV Interference Cross-task singular vector conflict [0, +inf) Gargiulo et al. 2025
Task Vector Energy Knowledge concentration in top SVs [0, 1] Choi et al. 2024
CKA Similarity Activation representation similarity [0, 1] Kornblith et al. 2019
Merge Compatibility Index Composite go/no-go score [0, 100] Ours
MCI Verdicts
Score Verdict Meaning
75-100 Highly Compatible Merge with confidence
55-74 Compatible Should work, monitor quality
35-54 Risky Expect degradation, use targeted methods
0-34 Incompatible These models likely shouldn't be merged
Strategy Recommendations

MergeLens maps diagnostic profiles to merge methods. Different metrics predict success for different methods (Zhou et al. 2026 found only 46.7% metric overlap between methods):

Diagnostic Profile Recommended Method
High cosine similarity everywhere SLERP
High sign disagreement (>30%) TIES
Concentrated task vector energy DARE
Low spectral overlap Linear (small alpha)

Each recommendation includes a ready-to-paste MergeKit YAML config.

MCP Integration

{
  "mcpServers": {
    "mergelens": {
      "command": "mergelens",
      "args": ["serve"]
    }
  }
}

Tools: compare_models, diagnose_merge, get_conflict_zones, suggest_strategy, generate_report, explain_layer, get_compatibility_score, audit_model

How It Works

MergeLens loads model weights lazily via memory-mapped safetensors (peak memory: 2× largest layer, not 2× full model). It computes metrics layer-by-layer, detects conflict zones, and aggregates everything into the MCI score.

Security: No pickle/torch.load (safetensors only), yaml.safe_load(), tensor size limits, no credential leakage.

Development

git clone https://github.com/shuhulx/mergelens.git
cd mergelens
pip install -e ".[dev,all]"
pytest

References

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mergelens-0.1.7.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mergelens-0.1.7-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

Details for the file mergelens-0.1.7.tar.gz.

File metadata

  • Download URL: mergelens-0.1.7.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for mergelens-0.1.7.tar.gz
Algorithm Hash digest
SHA256 742293c0ace969063f4296a93aa9da24196d2686de50f894481c96133e263b0b
MD5 cdc0a04fdcddfa492f1d7d6149b16a3d
BLAKE2b-256 9af5782a185d18640398287c31ae29f4e4243541c96ec57b31bc01569d45c75b

See more details on using hashes here.

File details

Details for the file mergelens-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: mergelens-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 48.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for mergelens-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 701351d8f181b63e740578ebbc38a894d7d81c5c0ff0bc8c544a79f7af3f4076
MD5 156dbcfd1ed0402c14235a5a48fbab08
BLAKE2b-256 2f23ce30e72459d497ed115f9fe5cf941a7e6319594e87f66f9fc038793dd2f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page