当前位置: 首页 > Skill >

fusion-bench

fusion-bench

fusion-bench

使用FusionBench运行模型融合实验,包括运行基准测试、添加新合并算法、评估融合模型及管理模型库。

1.0.0 2026.11.19 215
获取Skill文件查看使用说明
作 者:林言 许可证: 更新时间:2026.11.19
本文目录展开

FusionBench Skill

FusionBench is a comprehensive benchmark/toolkit for deep model fusion (model merging).

Paper: arXiv:2406.03280
PyPI: pip install fusion-bench
Repo: https://code.tanganke.com/tanganke/fusion_bench
Docs: https://tanganke.github.io/fusion_bench/

Quick Start

# Install
pip install fusion-bench

# Run a simple experiment (CLIP ViT-B/32, task arithmetic on 8 tasks)
fusion_bench method=task_arithmetic modelpool=clip-vit-base-patch32 taskpool=clip-vit-base-patch32_8tasks

# Run with different merging method
fusion_bench method=ties_merging modelpool=clip-vit-base-patch32 taskpool=clip-vit-base-patch32_8tasks

Architecture Overview

fusion_bench/
├── method/           # Merging algorithms (30+)
├── modelpool/        # Model loading & management
├── config/           # Hydra YAML configs
├── tasks/            # Task evaluation
├── utils/            # Helpers (state_dict ops, lazy loading, etc.)
└── scripts/          # CLI & web UI

Key Components

  1. ModelPool: Loads and manages pre-trained/fine-tuned models

    • AutoModelPool: Auto-selects based on config
    • CLIPVisionModelPool: For CLIP ViT models
    • CausalLMPool: For Llama, GPT-2, etc.
  2. Method: The merging algorithm

    • Inherits from BaseModelFusionAlgorithm
    • Implements run(modelpool) → merged model
  3. TaskPool: Evaluation tasks

    • CLIP: 8-38 classification tasks
    • LLM: ARC, HellaSwag, MMLU, etc.

Supported Merging Methods

Basic

Method Config Name Description
Simple Average simple_average Uniform weight averaging
Weighted Average weighted_average Learnable task weights
Task Arithmetic task_arithmetic task_vector = fine-tuned - base
Slerp slerp Spherical interpolation

Sparse/Pruning

Method Config Name Description
TIES ties_merging Trim, Elect, Sign + merge
DARE dare Drop And REscale
Magnitude Pruning magnitude_pruning Prune by magnitude

Advanced

Method Config Name Description
AdaMerging adamerging Learn layer-wise coefficients
Fisher Merging fisher_merging Fisher-weighted merging
RegMean regmean Regression mean (closed-form)
RegMean++ regmean_plusplus Enhanced RegMean with cross-layer deps

MoE-Based

Method Config Name Description
WE-MoE we_moe Weight Ensembling MoE
PWE-MoE pwe_moe Pareto-optimal WE-MoE
RankOne-MoE rankone_moe Rank-1 expert decomposition
Sparse-WE-MoE sparse_we_moe Sparse weight ensembling

Continual Merging

Method Config Name Description
OPCM opcm Orthogonal Projection Continual Merging
DOP dop Dual Orthogonal Projection
Gossip gossip Gossip-based continual merging

Specialized

Method Config Name Description
ISO-C/CTS isotropic_merging Isotropic merging in common/task subspace
AdaSVD ada_svd SVD-based adaptive merging
WUDI wudi Wasserstein distance merging
ExPO expo Exponential task vectors

Running Experiments

1. Basic Merging (CLI)

# Task Arithmetic on CLIP ViT-B/32
fusion_bench 
  method=task_arithmetic 
  modelpool=clip-vit-base-patch32 
  taskpool=clip-vit-base-patch32_8tasks

# TIES merging with custom scaling
fusion_bench 
  method=ties_merging 
  method.scaling_coefficient=0.3 
  modelpool=clip-vit-base-patch32 
  taskpool=clip-vit-base-patch32_8tasks

2. LLM Merging

# Merge Llama models
fusion_bench 
  method=task_arithmetic 
  modelpool=llama2-7b 
  taskpool=llama2-7b_tasks

# With DARE
fusion_bench 
  method=dare 
  method.type=task_arithmetic 
  modelpool=llama2-7b

3. Using Fabric (Distributed/Mixed Precision)

fusion_bench 
  fabric=deepspeed_stage_2 
  method=adamerging 
  modelpool=clip-vit-base-patch32

Adding a New Method

Step 1: Create method file

# fusion_bench/method/my_method.py
from fusion_bench.method.base_algorithm import BaseModelFusionAlgorithm
from fusion_bench.modelpool import BaseModelPool
import torch

class MyMergingAlgorithm(BaseModelFusionAlgorithm):
    """
    My custom merging algorithm.
    """
    def __init__(self, scaling_coefficient: float = 1.0, **kwargs):
        super().__init__(**kwargs)
        self.scaling_coefficient = scaling_coefficient
    
    @torch.no_grad()
    def run(self, modelpool: BaseModelPool):
        # 1. Load base model
        base_model = modelpool.load_model("_base_")
        base_sd = base_model.state_dict()
        
        # 2. Compute merged task vectors
        merged_tv = {}
        for model_name in modelpool.model_names:
            if model_name == "_base_":
                continue
            model = modelpool.load_model(model_name)
            tv = {k: v - base_sd[k] for k, v in model.state_dict().items()}
            # Your merging logic here
            for k in tv:
                if k not in merged_tv:
                    merged_tv[k] = tv[k] * self.scaling_coefficient
                else:
                    merged_tv[k] += tv[k] * self.scaling_coefficient
        
        # 3. Apply merged task vector
        for k in base_sd:
            base_sd[k] += merged_tv.get(k, 0)
        
        base_model.load_state_dict(base_sd)
        return base_model

Step 2: Register in __init__.py

# fusion_bench/method/__init__.py
_import_structure = {
    ...
    "my_method": ["MyMergingAlgorithm"],
}

Step 3: Create config

# config/method/my_method.yaml
_target_: fusion_bench.method.my_method.MyMergingAlgorithm
scaling_coefficient: 1.0

Step 4: Run

fusion_bench method=my_method modelpool=clip-vit-base-patch32

Model Pool Configuration

CLIP Models

# config/modelpool/clip-vit-base-patch32.yaml
_target_: fusion_bench.modelpool.CLIPVisionModelPool
model_names:
  - _base_
  - Cars
  - DTD
  - EuroSAT
  - GTSRB
  - MNIST
  - RESISC45
  - SUN397
  - SVHN
model_dir: ${oc.env:HOME}/.cache/fusion_bench/models

LLM Models

# config/modelpool/llama2-7b.yaml
_target_: fusion_bench.modelpool.CausalLMPool
model_names:
  - _base_
  - arc
  - hellaswag
  - mmlu
model_dir: ${oc.env:HOME}/.cache/fusion_bench/llama_models

Utilities

State Dict Arithmetic

from fusion_bench.utils.state_dict_arithmetic import StateDict

# Convenient operations on state dicts
sd1 = StateDict(model1.state_dict())
sd2 = StateDict(model2.state_dict())

merged = sd1 + sd2           # Add
diff = sd1 - sd2             # Subtract
scaled = sd1 * 0.5           # Scale
tv_merged = sd1 + 0.3 * sd2  # Linear combination

Lazy State Dict

from fusion_bench.utils.lazy_state_dict import LazyStateDict

# Load large models without OOM
lazy_sd = LazyStateDict.from_file("model.safetensors")
# Only loads tensors when accessed

Common Workflows

1. Evaluate a single merged model

from fusion_bench import AutoModelPool
from fusion_bench.method import SimpleAverageAlgorithm

pool = AutoModelPool.from_config("config/modelpool/clip-vit-base-patch32.yaml")
method = SimpleAverageAlgorithm()
merged_model = method.run(pool)

# Evaluate on tasks
for task_name in pool.model_names:
    if task_name == "_base_":
        continue
    acc = evaluate(merged_model, task_name)
    print(f"{task_name}: {acc:.2%}")

2. Hyperparameter search

# Sweep scaling coefficient
for coeff in 0.2 0.4 0.6 0.8 1.0; do
  fusion_bench 
    method=task_arithmetic 
    method.scaling_coefficient=$coeff 
    modelpool=clip-vit-base-patch32
done

3. Compare multiple methods

for method in simple_average task_arithmetic ties_merging dare; do
  echo "=== $method ==="
  fusion_bench 
    method=$method 
    modelpool=clip-vit-base-patch32 
    taskpool=clip-vit-base-patch32_8tasks
done

Tips

  1. Memory: Use fabric=deepspeed_stage_2 for large models
  2. Caching: Models are cached in ~/.cache/fusion_bench/
  3. Reproducibility: Set seed=42 in config
  4. Debugging: Use hydra.verbose=true for detailed logs
  5. Web UI: Run fusion_bench_webui for interactive exploration

Related Papers

  1. FusionBench (arXiv:2406.03280) - The benchmark paper
  2. SMILE (arXiv:2408.10174) - Sparse MoE from pre-trained models
  3. WE-MoE - Weight Ensembling MoE for multi-task merging
  4. OPCM/DOP - Continual model merging methods
  5. RegMean++ (arXiv:2508.03121) - Enhanced RegMean

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,019
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,014
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,014
Skill 文件
  • SKILL.md
    • FusionBench Skill
    • Quick Start
    • Architecture Overview
      • Key Components
    • Supported Merging Methods
      • Basic
      • Sparse/Pruning
      • Advanced
      • MoE-Based
      • Continual Merging
      • Specialized
    • Running Experiments
      • 1. Basic Merging (CLI)
      • 2. LLM Merging
      • 3. Using Fabric (Distributed/Mixed Precision)
    • Adding a New Method
      • Step 1: Create method file
      • Step 2: Register in __init__.py
      • Step 3: Create config
      • Step 4: Run
    • Model Pool Configuration
      • CLIP Models
      • LLM Models
    • Utilities
      • State Dict Arithmetic
      • Lazy State Dict
    • Common Workflows
      • 1. Evaluate a single merged model
      • 2. Hyperparameter search
      • 3. Compare multiple methods
    • Tips
    • Related Papers
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期