[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6MAGG9G5J2R9G5ZV7JSYA3V":3,"skill-same:01M6MAGG9G5J2R9G5ZV7JSYA3V":97},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":40,"linkOnly":41,"markdownContent":42,"markdownBody":43,"frontMatter":44,"refName":51,"commitSha":52,"skillDirectory":53,"forksCount":54,"repositoryHtmlUrl":55,"repositoryHomepageUrl":56,"ownerHtmlUrl":57,"ownerBlogUrl":58,"ownerDescription":59,"updatedAt":60,"install":61,"resources":74},"01M6MAGG9G5J2R9G5ZV7JSYA3V","model-merging",null,"Merge multiple fine-tuned models using mergekit to combine capabilities without retraining. Use when creating specialized models by blending domain-specific expertise (math + coding + chat), improving performance beyond single models, or experimenting rapidly with model variants. Covers SLERP, TIES-Merging, DARE, Task Arithmetic, linear merging, and production deployment strategies.","hashgraph-online\u002Fawesome-codex-plugins","hashgraph-online","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F160371962?v=4","01M6CNB6NRJVNNGN14TR01Q6D3","HOL (Hashgraph Online)","01M6JT1HSKKG9V68KQAQGBA7XP",1554,"MIT","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],"model","Model Merging","when","performance","variants","expertise","No Retraining","Model Fusion","Task Arithmetic","DARE","TIES","SLERP","Mergekit","Emerging Techniques","fusion","strategies","specialized","math","Transformers","capabilities","merge","2026-11-10 10:12:30",false,"---\nname: model-merging\ndescription: Merge multiple fine-tuned models using mergekit to combine capabilities without retraining. Use when creating specialized models by blending domain-specific expertise (math + coding + chat), improving performance beyond single models, or experimenting rapidly with model variants. Covers SLERP, TIES-Merging, DARE, Task Arithmetic, linear merging, and production deployment strategies.\nlicense: MIT\nmetadata:\n  version: 1.0.0\n  category: multimodal-and-emerging\n  maintainer: Kalaris Labs\n  tags: Emerging Techniques, Model Merging, Mergekit, SLERP, TIES, DARE, Task Arithmetic, Model Fusion, No Retraining, Multi-Capability, Arcee AI\n  dependencies: mergekit, transformers, torch\n---\n\n# Model Merging: Combining Pre-trained Models\n\n## When to Use This Skill\n\nUse Model Merging when you need to:\n- **Combine capabilities** from multiple fine-tuned models without retraining\n- **Create specialized models** by blending domain-specific expertise (math + coding + chat)\n- **Improve performance** beyond single models (often +5-10% on benchmarks)\n- **Reduce training costs** - no GPUs needed, merges run on CPU\n- **Experiment rapidly** - create new model variants in minutes, not days\n- **Preserve multiple skills** - merge without catastrophic forgetting\n\n**Success Stories**: Marcoro14-7B-slerp (best on Open LLM Leaderboard 02\u002F2024), many top HuggingFace models use merging\n\n**Tools**: mergekit (Arcee AI), LazyMergekit, Model Soup\n\n## Installation\n\n```bash\n# Install mergekit\ngit clone https:\u002F\u002Fgithub.com\u002Farcee-ai\u002Fmergekit.git\ncd mergekit\npip install -e .\n\n# Or via pip\npip install mergekit\n\n# Optional: Transformer library\npip install transformers torch\n```\n\n## Quick Start\n\n### Simple Linear Merge\n\n```yaml\n# config.yml - Merge two models with equal weights\nmerge_method: linear\nmodels:\n  - model: mistralai\u002FMistral-7B-v0.1\n    parameters:\n      weight: 0.5\n  - model: teknium\u002FOpenHermes-2.5-Mistral-7B\n    parameters:\n      weight: 0.5\ndtype: bfloat16\n```\n\n```bash\n# Run merge\nmergekit-yaml config.yml .\u002Fmerged-model --cuda\n\n# Use merged model\npython -m transformers.models.auto --model_name_or_path .\u002Fmerged-model\n```\n\n### SLERP Merge (Best for 2 Models)\n\n```yaml\n# config.yml - Spherical interpolation\nmerge_method: slerp\nslices:\n  - sources:\n      - model: mistralai\u002FMistral-7B-v0.1\n        layer_range: [0, 32]\n      - model: teknium\u002FOpenHermes-2.5-Mistral-7B\n        layer_range: [0, 32]\nparameters:\n  t: 0.5  # Interpolation factor (0=model1, 1=model2)\ndtype: bfloat16\n```\n\n## Core Concepts\n\n### 1. Merge Methods\n\n**Linear (Model Soup)**\n- Simple weighted average of parameters\n- Fast, works well for similar models\n- Can merge 2+ models (`w1 + w2 + ... = 1`)\n\n**SLERP (Spherical Linear Interpolation)**\n- Interpolates along sphere in weight space\n- Preserves magnitude of weight vectors\n- Best for merging 2 models\n- Smoother than linear\n\n```python\n# SLERP formula\nmerged = (sin((1-t)*θ) \u002F sin(θ)) * model1 + (sin(t*θ) \u002F sin(θ)) * model2\n# where θ = arccos(dot(model1, model2))\n# t ∈ [0, 1]\n```\n\n**Task Arithmetic**\n- Extract \"task vectors\" (fine-tuned - base)\n- Combine task vectors, add to base\n- Good for merging multiple specialized models (`merged = base + α₁·tv₁ + α₂·tv₂`)\n\n**TIES-Merging**\n- Task arithmetic + sparsification\n- Resolves sign conflicts in parameters\n- Best for merging many task-specific models\n\n**DARE (Drop And REscale)**\n- Randomly drops fine-tuned parameters\n- Rescales remaining parameters\n- Reduces redundancy, maintains performance\n\n### 2. Configuration Structure\n\n```yaml\n# Basic structure\nmerge_method: \u003Cmethod>  # linear, slerp, ties, dare_ties, task_arithmetic\nbase_model: \u003Cpath>      # Optional: base model for task arithmetic\n\nmodels:\n  - model: \u003Cpath\u002Fto\u002Fmodel1>\n    parameters:\n      weight: \u003Cfloat>   # Merge weight\n      density: \u003Cfloat>  # For TIES\u002FDARE\n\n  - model: \u003Cpath\u002Fto\u002Fmodel2>\n    parameters:\n      weight: \u003Cfloat>\n\nparameters:\n  # Method-specific parameters\n\ndtype: \u003Cdtype>  # bfloat16, float16, float32\n\n# Optional\nslices:  # Layer-wise merging\ntokenizer:  # Tokenizer configuration\n```\n\n## Merge Methods Guide\n\nDetails, code examples and parameter tables: [references\u002Fmerge-methods-guide.md](references\u002Fmerge-methods-guide.md). Read it when this step applies.\n\n## Advanced Patterns\n\n### Layer-wise Merging\n\n```yaml\n# Different models for different layers\nmerge_method: passthrough\nslices:\n  - sources:\n      - model: mistralai\u002FMistral-7B-v0.1\n        layer_range: [0, 16]   # First half\n  - sources:\n      - model: teknium\u002FOpenHermes-2.5-Mistral-7B\n        layer_range: [16, 32]  # Second half\ndtype: bfloat16\n```\n\n### MoE from Merged Models\n\n```yaml\n# Create Mixture of Experts\nmerge_method: moe\nbase_model: mistralai\u002FMistral-7B-v0.1\nexperts:\n  - source_model: WizardLM\u002FWizardMath-7B-V1.1\n    positive_prompts:\n      - \"math\"\n      - \"calculate\"\n  - source_model: teknium\u002FOpenHermes-2.5-Mistral-7B\n    positive_prompts:\n      - \"chat\"\n      - \"conversation\"\n  - source_model: ajibawa-2023\u002FCode-Mistral-7B\n    positive_prompts:\n      - \"code\"\n      - \"python\"\ndtype: bfloat16\n```\n\n### Tokenizer Merging\n\n```yaml\nmerge_method: linear\nmodels:\n  - model: mistralai\u002FMistral-7B-v0.1\n  - model: custom\u002Fspecialized-model\n\ntokenizer:\n  source: \"union\"  # Combine vocabularies from both models\n  tokens:\n    \u003C|special_token|>:\n      source: \"custom\u002Fspecialized-model\"\n```\n\n## Best Practices\n\n### 1. Model Compatibility\n\n```python\n# ✅ Good: Same architecture\nmodels = [\n    \"mistralai\u002FMistral-7B-v0.1\",\n    \"teknium\u002FOpenHermes-2.5-Mistral-7B\",  # Both Mistral 7B\n]\n\n# ❌ Bad: Different architectures\nmodels = [\n    \"meta-llama\u002FLlama-2-7b-hf\",  # Llama\n    \"mistralai\u002FMistral-7B-v0.1\",  # Mistral (incompatible!)\n]\n```\n\n### 2. Weight Selection\n\n```yaml\n# ✅ Good: Weights sum to 1.0\nmodels:\n  - model: model_a\n    parameters:\n      weight: 0.6\n  - model: model_b\n    parameters:\n      weight: 0.4  # 0.6 + 0.4 = 1.0\n\n# ⚠️  Acceptable: Weights don't sum to 1 (for task arithmetic)\nmodels:\n  - model: model_a\n    parameters:\n      weight: 0.8\n  - model: model_b\n    parameters:\n      weight: 0.8  # May boost performance\n```\n\n**Unsupervised Coefficient Tuning (no labeled data needed)**\n\nInstead of manual search, use *generation consistency*: merge with several candidate coefficients, generate responses on a small unlabeled subset, and pick the coefficient whose outputs are most similar to those of its neighbors. Consistent outputs signal a stable, well-performing merge region (AdaMMS, arXiv:2503.23733).\n\n```python\n# Pseudocode — see references\u002Fcoefficient-tuning.md for full implementation\ncandidates = [0.3, 0.4, 0.5, 0.6, 0.7]\nfor alpha in candidates:\n    merged_paths[alpha] = merge_with_coefficient(alpha, model_a, model_b)\n    responses[alpha]    = generate_responses(merged_paths[alpha], eval_prompts)\n\n# Score each alpha by similarity to its neighbors (alpha ± 0.1)\nbest_alpha = max(candidates, key=lambda a: generation_consistency(a, responses))\n```\n\nSee **[references\u002Fcoefficient-tuning.md](references\u002Fcoefficient-tuning.md)** for the full algorithm, similarity metrics, multi-coefficient search, and end-to-end pipeline.\n\n### 3. Method Selection\n\n```python\n# Choose merge method based on use case:\n\n# 2 models, smooth blend → SLERP\nmerge_method = \"slerp\"\n\n# 3+ models, simple average → Linear\nmerge_method = \"linear\"\n\n# Multiple task-specific models → Task Arithmetic or TIES\nmerge_method = \"ties\"\n\n# Want to reduce redundancy → DARE\nmerge_method = \"dare_ties\"\n```\n\n### 4. Density Tuning (TIES\u002FDARE)\n\n```yaml\n# Start conservative (keep more parameters)\nparameters:\n  density: 0.8  # Keep 80%\n\n# If performance good, increase sparsity\nparameters:\n  density: 0.5  # Keep 50%\n\n# If performance degrades, reduce sparsity\nparameters:\n  density: 0.9  # Keep 90%\n```\n\n### 5. Layer-specific Merging\n\nPreserve the base model's first\u002Flast layers (often best left untouched) and merge only the middle via `merge_method: passthrough` with `slices` — see the [Layer-wise Merging](#layer-wise-merging) pattern above.\n\n## Evaluation & Testing\n\n### Benchmark Merged Models\n\n```python\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\n# Load merged model\nmodel = AutoModelForCausalLM.from_pretrained(\".\u002Fmerged-model\")\ntokenizer = AutoTokenizer.from_pretrained(\".\u002Fmerged-model\")\n\n# Test on various tasks\ntest_prompts = {\n    \"math\": \"Calculate: 25 * 17 =\",\n    \"code\": \"Write a Python function to reverse a string:\",\n    \"chat\": \"What is the capital of France?\",\n}\n\nfor task, prompt in test_prompts.items():\n    inputs = tokenizer(prompt, return_tensors=\"pt\")\n    outputs = model.generate(**inputs, max_length=100)\n    print(f\"{task}: {tokenizer.decode(outputs[0])}\")\n```\n\n### Common Benchmarks\n\n- **Open LLM Leaderboard**: General capabilities\n- **MT-Bench**: Multi-turn conversation\n- **MMLU**: Multitask accuracy\n- **HumanEval**: Code generation\n- **GSM8K**: Math reasoning\n\n## Production Deployment\n\n### Save and Upload\n\n```python\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\n# Load merged model\nmodel = AutoModelForCausalLM.from_pretrained(\".\u002Fmerged-model\")\ntokenizer = AutoTokenizer.from_pretrained(\".\u002Fmerged-model\")\n\n# Upload to HuggingFace Hub\nmodel.push_to_hub(\"username\u002Fmy-merged-model\")\ntokenizer.push_to_hub(\"username\u002Fmy-merged-model\")\n```\n\n### Quantize Merged Model\n\n```bash\n# Quantize with GGUF\npython convert.py .\u002Fmerged-model --outtype f16 --outfile merged-model.gguf\n\n# Quantize with GPTQ\npython quantize_gptq.py .\u002Fmerged-model --bits 4 --group_size 128\n```\n\n## Common Pitfalls\n\n- **Mismatched architectures** — only merge models that share the same architecture (e.g., don't mix Llama and Mistral).\n- **Over-weighting one model** (e.g., `0.95 \u002F 0.05`) — keep weights balanced, typically in the 0.3–0.7 range.\n- **Skipping evaluation** — always benchmark a merged model before deploying (see the Evaluation & Testing section above).\n\n## Resources\n\n- **mergekit GitHub**: https:\u002F\u002Fgithub.com\u002Farcee-ai\u002Fmergekit\n- **HuggingFace Tutorial**: https:\u002F\u002Fhuggingface.co\u002Fblog\u002Fmlabonne\u002Fmerge-models\n- **LazyMergekit**: Automated merging notebook\n- **TIES Paper**: https:\u002F\u002Farxiv.org\u002Fabs\u002F2306.01708\n- **DARE Paper**: https:\u002F\u002Farxiv.org\u002Fabs\u002F2311.03099\n\n## See Also\n\n- `references\u002Fmethods.md` - Deep dive into merge algorithms\n- `references\u002Fexamples.md` - Real-world merge configurations\n- `references\u002Fevaluation.md` - Benchmarking and testing strategies\n- `references\u002Fcoefficient-tuning.md` - Unsupervised coefficient search via generation consistency (AdaMMS, arXiv:2503.23733)\n\n## Agent operating procedure\n\n1. **Check the environment.** Confirm GPU memory, model checkpoint and licence, framework versions and input formats.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Run inference on a single sample at low resolution or short length first.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Inspect outputs qualitatively and with task metrics; check licence restrictions for generated content.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| Out-of-memory on large inputs | Reduce resolution or sequence length, use half precision, or tile the input. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Check model and dataset licences before commercial or published use.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n","# Model Merging: Combining Pre-trained Models\n\n## When to Use This Skill\n\nUse Model Merging when you need to:\n- **Combine capabilities** from multiple fine-tuned models without retraining\n- **Create specialized models** by blending domain-specific expertise (math + coding + chat)\n- **Improve performance** beyond single models (often +5-10% on benchmarks)\n- **Reduce training costs** - no GPUs needed, merges run on CPU\n- **Experiment rapidly** - create new model variants in minutes, not days\n- **Preserve multiple skills** - merge without catastrophic forgetting\n\n**Success Stories**: Marcoro14-7B-slerp (best on Open LLM Leaderboard 02\u002F2024), many top HuggingFace models use merging\n\n**Tools**: mergekit (Arcee AI), LazyMergekit, Model Soup\n\n## Installation\n\n```bash\n# Install mergekit\ngit clone https:\u002F\u002Fgithub.com\u002Farcee-ai\u002Fmergekit.git\ncd mergekit\npip install -e .\n\n# Or via pip\npip install mergekit\n\n# Optional: Transformer library\npip install transformers torch\n```\n\n## Quick Start\n\n### Simple Linear Merge\n\n```yaml\n# config.yml - Merge two models with equal weights\nmerge_method: linear\nmodels:\n  - model: mistralai\u002FMistral-7B-v0.1\n    parameters:\n      weight: 0.5\n  - model: teknium\u002FOpenHermes-2.5-Mistral-7B\n    parameters:\n      weight: 0.5\ndtype: bfloat16\n```\n\n```bash\n# Run merge\nmergekit-yaml config.yml .\u002Fmerged-model --cuda\n\n# Use merged model\npython -m transformers.models.auto --model_name_or_path .\u002Fmerged-model\n```\n\n### SLERP Merge (Best for 2 Models)\n\n```yaml\n# config.yml - Spherical interpolation\nmerge_method: slerp\nslices:\n  - sources:\n      - model: mistralai\u002FMistral-7B-v0.1\n        layer_range: [0, 32]\n      - model: teknium\u002FOpenHermes-2.5-Mistral-7B\n        layer_range: [0, 32]\nparameters:\n  t: 0.5  # Interpolation factor (0=model1, 1=model2)\ndtype: bfloat16\n```\n\n## Core Concepts\n\n### 1. Merge Methods\n\n**Linear (Model Soup)**\n- Simple weighted average of parameters\n- Fast, works well for similar models\n- Can merge 2+ models (`w1 + w2 + ... = 1`)\n\n**SLERP (Spherical Linear Interpolation)**\n- Interpolates along sphere in weight space\n- Preserves magnitude of weight vectors\n- Best for merging 2 models\n- Smoother than linear\n\n```python\n# SLERP formula\nmerged = (sin((1-t)*θ) \u002F sin(θ)) * model1 + (sin(t*θ) \u002F sin(θ)) * model2\n# where θ = arccos(dot(model1, model2))\n# t ∈ [0, 1]\n```\n\n**Task Arithmetic**\n- Extract \"task vectors\" (fine-tuned - base)\n- Combine task vectors, add to base\n- Good for merging multiple specialized models (`merged = base + α₁·tv₁ + α₂·tv₂`)\n\n**TIES-Merging**\n- Task arithmetic + sparsification\n- Resolves sign conflicts in parameters\n- Best for merging many task-specific models\n\n**DARE (Drop And REscale)**\n- Randomly drops fine-tuned parameters\n- Rescales remaining parameters\n- Reduces redundancy, maintains performance\n\n### 2. Configuration Structure\n\n```yaml\n# Basic structure\nmerge_method: \u003Cmethod>  # linear, slerp, ties, dare_ties, task_arithmetic\nbase_model: \u003Cpath>      # Optional: base model for task arithmetic\n\nmodels:\n  - model: \u003Cpath\u002Fto\u002Fmodel1>\n    parameters:\n      weight: \u003Cfloat>   # Merge weight\n      density: \u003Cfloat>  # For TIES\u002FDARE\n\n  - model: \u003Cpath\u002Fto\u002Fmodel2>\n    parameters:\n      weight: \u003Cfloat>\n\nparameters:\n  # Method-specific parameters\n\ndtype: \u003Cdtype>  # bfloat16, float16, float32\n\n# Optional\nslices:  # Layer-wise merging\ntokenizer:  # Tokenizer configuration\n```\n\n## Merge Methods Guide\n\nDetails, code examples and parameter tables: [references\u002Fmerge-methods-guide.md](references\u002Fmerge-methods-guide.md). Read it when this step applies.\n\n## Advanced Patterns\n\n### Layer-wise Merging\n\n```yaml\n# Different models for different layers\nmerge_method: passthrough\nslices:\n  - sources:\n      - model: mistralai\u002FMistral-7B-v0.1\n        layer_range: [0, 16]   # First half\n  - sources:\n      - model: teknium\u002FOpenHermes-2.5-Mistral-7B\n        layer_range: [16, 32]  # Second half\ndtype: bfloat16\n```\n\n### MoE from Merged Models\n\n```yaml\n# Create Mixture of Experts\nmerge_method: moe\nbase_model: mistralai\u002FMistral-7B-v0.1\nexperts:\n  - source_model: WizardLM\u002FWizardMath-7B-V1.1\n    positive_prompts:\n      - \"math\"\n      - \"calculate\"\n  - source_model: teknium\u002FOpenHermes-2.5-Mistral-7B\n    positive_prompts:\n      - \"chat\"\n      - \"conversation\"\n  - source_model: ajibawa-2023\u002FCode-Mistral-7B\n    positive_prompts:\n      - \"code\"\n      - \"python\"\ndtype: bfloat16\n```\n\n### Tokenizer Merging\n\n```yaml\nmerge_method: linear\nmodels:\n  - model: mistralai\u002FMistral-7B-v0.1\n  - model: custom\u002Fspecialized-model\n\ntokenizer:\n  source: \"union\"  # Combine vocabularies from both models\n  tokens:\n    \u003C|special_token|>:\n      source: \"custom\u002Fspecialized-model\"\n```\n\n## Best Practices\n\n### 1. Model Compatibility\n\n```python\n# ✅ Good: Same architecture\nmodels = [\n    \"mistralai\u002FMistral-7B-v0.1\",\n    \"teknium\u002FOpenHermes-2.5-Mistral-7B\",  # Both Mistral 7B\n]\n\n# ❌ Bad: Different architectures\nmodels = [\n    \"meta-llama\u002FLlama-2-7b-hf\",  # Llama\n    \"mistralai\u002FMistral-7B-v0.1\",  # Mistral (incompatible!)\n]\n```\n\n### 2. Weight Selection\n\n```yaml\n# ✅ Good: Weights sum to 1.0\nmodels:\n  - model: model_a\n    parameters:\n      weight: 0.6\n  - model: model_b\n    parameters:\n      weight: 0.4  # 0.6 + 0.4 = 1.0\n\n# ⚠️  Acceptable: Weights don't sum to 1 (for task arithmetic)\nmodels:\n  - model: model_a\n    parameters:\n      weight: 0.8\n  - model: model_b\n    parameters:\n      weight: 0.8  # May boost performance\n```\n\n**Unsupervised Coefficient Tuning (no labeled data needed)**\n\nInstead of manual search, use *generation consistency*: merge with several candidate coefficients, generate responses on a small unlabeled subset, and pick the coefficient whose outputs are most similar to those of its neighbors. Consistent outputs signal a stable, well-performing merge region (AdaMMS, arXiv:2503.23733).\n\n```python\n# Pseudocode — see references\u002Fcoefficient-tuning.md for full implementation\ncandidates = [0.3, 0.4, 0.5, 0.6, 0.7]\nfor alpha in candidates:\n    merged_paths[alpha] = merge_with_coefficient(alpha, model_a, model_b)\n    responses[alpha]    = generate_responses(merged_paths[alpha], eval_prompts)\n\n# Score each alpha by similarity to its neighbors (alpha ± 0.1)\nbest_alpha = max(candidates, key=lambda a: generation_consistency(a, responses))\n```\n\nSee **[references\u002Fcoefficient-tuning.md](references\u002Fcoefficient-tuning.md)** for the full algorithm, similarity metrics, multi-coefficient search, and end-to-end pipeline.\n\n### 3. Method Selection\n\n```python\n# Choose merge method based on use case:\n\n# 2 models, smooth blend → SLERP\nmerge_method = \"slerp\"\n\n# 3+ models, simple average → Linear\nmerge_method = \"linear\"\n\n# Multiple task-specific models → Task Arithmetic or TIES\nmerge_method = \"ties\"\n\n# Want to reduce redundancy → DARE\nmerge_method = \"dare_ties\"\n```\n\n### 4. Density Tuning (TIES\u002FDARE)\n\n```yaml\n# Start conservative (keep more parameters)\nparameters:\n  density: 0.8  # Keep 80%\n\n# If performance good, increase sparsity\nparameters:\n  density: 0.5  # Keep 50%\n\n# If performance degrades, reduce sparsity\nparameters:\n  density: 0.9  # Keep 90%\n```\n\n### 5. Layer-specific Merging\n\nPreserve the base model's first\u002Flast layers (often best left untouched) and merge only the middle via `merge_method: passthrough` with `slices` — see the [Layer-wise Merging](#layer-wise-merging) pattern above.\n\n## Evaluation & Testing\n\n### Benchmark Merged Models\n\n```python\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\n# Load merged model\nmodel = AutoModelForCausalLM.from_pretrained(\".\u002Fmerged-model\")\ntokenizer = AutoTokenizer.from_pretrained(\".\u002Fmerged-model\")\n\n# Test on various tasks\ntest_prompts = {\n    \"math\": \"Calculate: 25 * 17 =\",\n    \"code\": \"Write a Python function to reverse a string:\",\n    \"chat\": \"What is the capital of France?\",\n}\n\nfor task, prompt in test_prompts.items():\n    inputs = tokenizer(prompt, return_tensors=\"pt\")\n    outputs = model.generate(**inputs, max_length=100)\n    print(f\"{task}: {tokenizer.decode(outputs[0])}\")\n```\n\n### Common Benchmarks\n\n- **Open LLM Leaderboard**: General capabilities\n- **MT-Bench**: Multi-turn conversation\n- **MMLU**: Multitask accuracy\n- **HumanEval**: Code generation\n- **GSM8K**: Math reasoning\n\n## Production Deployment\n\n### Save and Upload\n\n```python\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\n# Load merged model\nmodel = AutoModelForCausalLM.from_pretrained(\".\u002Fmerged-model\")\ntokenizer = AutoTokenizer.from_pretrained(\".\u002Fmerged-model\")\n\n# Upload to HuggingFace Hub\nmodel.push_to_hub(\"username\u002Fmy-merged-model\")\ntokenizer.push_to_hub(\"username\u002Fmy-merged-model\")\n```\n\n### Quantize Merged Model\n\n```bash\n# Quantize with GGUF\npython convert.py .\u002Fmerged-model --outtype f16 --outfile merged-model.gguf\n\n# Quantize with GPTQ\npython quantize_gptq.py .\u002Fmerged-model --bits 4 --group_size 128\n```\n\n## Common Pitfalls\n\n- **Mismatched architectures** — only merge models that share the same architecture (e.g., don't mix Llama and Mistral).\n- **Over-weighting one model** (e.g., `0.95 \u002F 0.05`) — keep weights balanced, typically in the 0.3–0.7 range.\n- **Skipping evaluation** — always benchmark a merged model before deploying (see the Evaluation & Testing section above).\n\n## Resources\n\n- **mergekit GitHub**: https:\u002F\u002Fgithub.com\u002Farcee-ai\u002Fmergekit\n- **HuggingFace Tutorial**: https:\u002F\u002Fhuggingface.co\u002Fblog\u002Fmlabonne\u002Fmerge-models\n- **LazyMergekit**: Automated merging notebook\n- **TIES Paper**: https:\u002F\u002Farxiv.org\u002Fabs\u002F2306.01708\n- **DARE Paper**: https:\u002F\u002Farxiv.org\u002Fabs\u002F2311.03099\n\n## See Also\n\n- `references\u002Fmethods.md` - Deep dive into merge algorithms\n- `references\u002Fexamples.md` - Real-world merge configurations\n- `references\u002Fevaluation.md` - Benchmarking and testing strategies\n- `references\u002Fcoefficient-tuning.md` - Unsupervised coefficient search via generation consistency (AdaMMS, arXiv:2503.23733)\n\n## Agent operating procedure\n\n1. **Check the environment.** Confirm GPU memory, model checkpoint and licence, framework versions and input formats.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Run inference on a single sample at low resolution or short length first.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Inspect outputs qualitatively and with task metrics; check licence restrictions for generated content.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| Out-of-memory on large inputs | Reduce resolution or sequence length, use half precision, or tile the input. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Check model and dataset licences before commercial or published use.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n",{"name":5,"license":15,"metadata":45,"description":7},{"tags":46,"version":47,"category":48,"maintainer":49,"dependencies":50},"Emerging Techniques, Model Merging, Mergekit, SLERP, TIES, DARE, Task Arithmetic, Model Fusion, No Retraining, Multi-Capability, Arcee AI","1.0.0","multimodal-and-emerging","Kalaris Labs","mergekit, transformers, torch","main","2b63f856ce19c2a797929cacabd9e0fc936812fa","plugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging",468,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins","https:\u002F\u002Fhol.org\u002Fplugins\u002Fbest-codex-plugins","https:\u002F\u002Fgithub.com\u002Fhashgraph-online","https:\u002F\u002Fhol.org","Open-source standards and developer tools for interoperable AI agents: discovery, identity, communication, payments, privacy and security.","2026-11-11 02:22:54",{"source":8,"skillName":5,"commands":62,"prompt":72,"zipAvailable":73},[63,66,69],{"tool":64,"command":65},"npx","npx skills add hashgraph-online\u002Fawesome-codex-plugins --skill model-merging",{"tool":67,"command":68},"bunx","bunx skills add hashgraph-online\u002Fawesome-codex-plugins --skill model-merging",{"tool":70,"command":71},"pnpm","pnpm dlx skills add hashgraph-online\u002Fawesome-codex-plugins --skill model-merging","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging\u002FSKILL.md",true,[75,81,85,89,93],{"path":76,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Fcoefficient-tuning.md","REFERENCE","参考文档",14622,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging\u002Freferences\u002Fcoefficient-tuning.md",{"path":82,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":83,"sourceHtmlUrl":84},"references\u002Fevaluation.md",11705,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging\u002Freferences\u002Fevaluation.md",{"path":86,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":87,"sourceHtmlUrl":88},"references\u002Fexamples.md",8813,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging\u002Freferences\u002Fexamples.md",{"path":90,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":91,"sourceHtmlUrl":92},"references\u002Fmerge-methods-guide.md",2499,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging\u002Freferences\u002Fmerge-methods-guide.md",{"path":94,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":95,"sourceHtmlUrl":96},"references\u002Fmethods.md",9562,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fmodel-merging\u002Freferences\u002Fmethods.md",[98,124,149,183,204,218],{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":102,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":40},"01M716A6ETNB9B1SQ3GXZC75VR","deja-search","deja-vu memory — search the user's past AI coding sessions with the deja CLI. Holds what they already settled and never wrote into the repo (naming rules, banned or already-tried tools, required checks before merge, preferred values, who owns what). Use before your first edit in a task, before you call a change done or ready to merge, before you recommend a tool, library, design or reviewer, before re-debugging an error that may already be solved, when they say 'didn't we fix this before', 'what did we decide about X' or 'I already have that', and before telling them something on this machine does not exist.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fvshulcz\u002Fdeja-vu\u002Fskills\u002Fdeja-search\u002FSKILL.md",[],[106,107,108,109,110,111,112,113,114,115,116,21,117,118,119,120,121,122,39,123],"search","deja search","error","ready","never","memory","re","decide","fix","design","debugging","you","done","reviewer","io","change","cli","past",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":102,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":40},"01M716A3J2W5SENSE9VGMXB375","deja-reflect","End-of-session reflection and memory curation with deja-vu. Review what was decided, what commands broke and what repaired them, and record durable project rules or decisions with deja remember so the next session starts with them.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fvshulcz\u002Fdeja-vu\u002Fskills\u002Fdeja-reflect\u002FSKILL.md",[],[131,132,133,134,111,135,136,137,138,139,140,141,142,120,143,144,145,146,147,148],"reflect","deja reflect","brew","remember","project rules","project","session","end","reflection","Rules","decisions","review","with","record","github","next","https","node",{"skillNo":150,"name":151,"nameZh":6,"description":152,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":102,"licenseFileUrl":6,"sourceHtmlUrl":153,"categories":154,"keywords":166,"publishedAt":40},"01M715T3RR4BAYSR57HPPTJ0PF","revid","Make, edit, export and post AI videos with Revid (revid.ai) through the Revid MCP server. Use whenever the user wants a short-form or long-form video made (from an idea, a script, a URL, an article, a PDF, a tweet, a product page, their own clips, or a song), wants to find what is going viral on TikTok, YouTube, Instagram or X before making something, wants to edit or re-export an existing Revid project, generate a standalone AI image or clip, make a series episode, or publish and schedule a finished video to connected social accounts. Covers setup (hosted MCP with OAuth, or an API key), the 36 tools, credits, polling and the rules for publishing. Routes to the more specific revid-* skills when one fits.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Ftmakersas\u002Frevid-skills\u002Fskills\u002Frevid\u002FSKILL.md",[155,160,163],{"categoryNo":156,"categoryName":157,"taxonomyType":158,"taxonomyTypeDesc":159},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":161,"categoryName":162,"taxonomyType":158,"taxonomyTypeDesc":159},"01JBSEEDCAT000000000000016","图像与多媒体",{"categoryNo":164,"categoryName":165,"taxonomyType":158,"taxonomyTypeDesc":159},"01JBSEEDCAT000000000000023","Skill与智能体开发",[151,167,168,169,170,171,136,172,112,173,174,175,176,21,177,178,179,180,181,182],"Video","short-form","standalone","PDF","viral","tiktok","short","social","MCP","song","URL","image","mcp server","schedule","api","publish",{"skillNo":184,"name":185,"nameZh":6,"description":186,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":102,"licenseFileUrl":6,"sourceHtmlUrl":187,"categories":188,"keywords":189,"publishedAt":40},"01M71569ZM2X3H5RBFK8PVKMK2","review-study","Review a QuestionPunk survey before launch for wording, answer choices, branching, and missing settings. Use for check my survey or review this draft before publishing.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fquestionpunk\u002Fcodex-plugin\u002Fskills\u002Freview-study\u002FSKILL.md",[],[190,191,142,192,193,194,195,196,197,198,199,200,201,202,203],"study","review study","for","answer","missing","survey","publishing","use","check","draft","settings","launch","my","branching",{"skillNo":205,"name":206,"nameZh":6,"description":207,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":102,"licenseFileUrl":6,"sourceHtmlUrl":208,"categories":209,"keywords":210,"publishedAt":40},"01M71567GV0C35YQBY0DPGR86B","manage-study","Find QuestionPunk studies, check status, publish an explicitly requested draft, or retrieve its participant link. Use for find my survey, publish this study, or how many people responded.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fquestionpunk\u002Fcodex-plugin\u002Fskills\u002Fmanage-study\u002FSKILL.md",[],[211,190,212,192,195,197,213,198,199,182,214,215,216,217,202],"manage study","manage","people","how","find","link","status",{"skillNo":219,"name":220,"nameZh":6,"description":221,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":102,"licenseFileUrl":6,"sourceHtmlUrl":222,"categories":223,"keywords":224,"publishedAt":40},"01M71565A8TCA01AZQZRGRYMFZ","create-study","Create a saved QuestionPunk survey draft from a research brief or edit specified questions. Use for requests such as make a customer feedback survey or shorten my onboarding study.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fquestionpunk\u002Fcodex-plugin\u002Fskills\u002Fcreate-study\u002FSKILL.md",[],[225,190,226,227,228,229,192,230,195,231,197,232,233,199,234,235,236,237,238,202],"create study","create","brief","as","feedback","customer feedback","research brief","shorten","saved","research","requests","customer","questions","edit"]