Model Merging and Task Arithmetic: Mathematical Foundations, Task Vectors, TIES-Merging, DARE, and Spherical Linear Interpolation (SLERP)

Model Merging and Task Arithmetic: Mathematical Foundations, Task Vectors, TIES-Merging, DARE, and Spherical Linear Interpolation (SLERP) Model merging enables the combination of multiple specialized large language models into a unified checkpoint without retraining, backpropagation, or access to the original training datasets. Rather than running costly multi-task supervised fine-tuning across disparate domains, practitioners can directly manipulate parameter tensors in weight space to fuse ca

8 min
Model Merging and Task Arithmetic: Mathematical Foundations, Task Vectors, TIES-Merging, DARE, and Spherical Linear Interpolation (SLERP)

Model Merging and Task Arithmetic: Mathematical Foundations, Task Vectors, TIES-Merging, DARE, and Spherical Linear Interpolation (SLERP)

Model merging enables the combination of multiple specialized large language models into a unified checkpoint without retraining, backpropagation, or access to the original training datasets. Rather than running costly multi-task supervised fine-tuning across disparate domains, practitioners can directly manipulate parameter tensors in weight space to fuse capabilities such as mathematical reasoning, instruction following, coding, and multilingual fluency.

This explainer details the theoretical foundations and algorithms governing parameter-space fusion, from linear task vectors and spherical geometry to interference-resolving pruning techniques like TIES-Merging and DARE.


1. Parameter Geometry and Linear Mode Connectivity

Model merging relies on the empirical observation that fine-tuned neural networks derived from a shared pre-trained initialization reside within the same low-loss basin.

When models share an identical base initialization θ0Rd\theta_0 \in \mathbb{R}^d, their optimization trajectories during Supervised Fine-Tuning (SFT) remain closely aligned in the loss landscape. This phenomenon is formalized by the Linear Mode Connectivity (LMC) hypothesis (Frankle et al., 2020; Entezari et al., 2022; Ainsworth et al., 2022).

For two fine-tuned checkpoints θA\theta_A and θB\theta_B initialized from θ0\theta_0, the linear interpolation path:

θ(α)=(1α)θA+αθB,α[0,1]\theta(\alpha) = (1 - \alpha)\theta_A + \alpha \theta_B, \quad \alpha \in [0, 1]

often encounters virtually zero barrier in the loss surface L(θ(α))\mathcal{L}(\theta(\alpha)), provided the fine-tuning step count is moderate and learning rates avoid chaotic divergence.

                       Loss Landscape Basin
                               
                      Loss L(θ)
                         ▲
                         │       Barrier for distinct inits
                         │        _ . - - - . _
                         │      /               \
                         │     /                 \
                         │    /                   \
                         │   /  Low-loss valley   \
                         │  /  (Linear Mode Conn)  \
                         │ /                       \
                         │/                         \
                         └───────●───────────●───────► Parameter Space θ
                                 θ_A         θ_B

Unlike joint multi-task training (which suffers from gradient interference, catastrophic forgetting, and immense compute overhead), weight merging operates strictly post-hoc on static parameter tensors.


2. Linear Task Arithmetic and Task Vectors

The foundational abstraction for linear parameter manipulation is the task vector, introduced by Ilharco et al. (2023).

2.1 Mathematical Formulation

Given a base model θ0Rd\theta_0 \in \mathbb{R}^d and a model fine-tuned on task tt, denoted θtRd\theta_t \in \mathbb{R}^d, the task vector τt\tau_t is defined as the coordinate-wise delta:

τt=θtθ0\tau_t = \theta_t - \theta_0

Because τt\tau_t represents the directional displacement in parameter space required to execute task tt, algebraic operations on τt\tau_t produce corresponding shifts in model capabilities:

  1. Multi-Task Merging (Addition):

θmerged=θ0+k=1Kλkτk\theta_{\text{merged}} = \theta_0 + \sum_{k=1}^K \lambda_k \tau_k where λk>0\lambda_k > 0 is a task-specific scaling hyperparameter.

  1. Targeted Capability Removal (Subtraction / Unlearning):

θunlearned=θ0λτtoxic\theta_{\text{unlearned}} = \theta_0 - \lambda \tau_{\text{toxic}} Subtracting a task vector trained on undesirable behavior (such as toxic generations, copyrighted data, or vulnerable code) dampens those representations without full retraining.

  1. Analogical Task Transfer:

θtarget=θ0+(τFrenchτEnglish)\theta_{\text{target}} = \theta_0 + (\tau_{\text{French}} - \tau_{\text{English}})

2.2 Limitations of Naive Linear Addition

While elegant, naive addition of task vectors breaks down as the number of tasks KK grows or when fine-tuning steps push weights far from θ0\theta_0. Two structural issues arise:

  • Magnitude Domination: Layers with high learning-rate displacement dominate the linear sum, drowning out subtle fine-grained capabilities.
  • Destructive Sign Interference: Parameter coordinates where one task vector is positive (τA(j)>0\tau_A^{(j)} > 0) and another is negative (τB(j)<0\tau_B^{(j)} < 0) cancel each other out, degrading performance on both source tasks.

3. Spherical Linear Interpolation (SLERP)

When merging exactly two models (K=2K=2), standard Linear Interpolation (LERP) suffers from high-dimensional geometric distortion.

3.1 Geometric Shrinkage in Euclidean Interpolation

In Euclidean space, linearly interpolating between two high-dimensional vectors θA\theta_A and θB\theta_B of equal norm θA=θB=r\|\theta_A\| = \|\theta_B\| = r yields a midpoint whose norm is strictly smaller:

θ(0.5)=θA+θB2=rcos(Ω2)<r\|\theta(0.5)\| = \left\|\frac{\theta_A + \theta_B}{2}\right\| = r \cos\left(\frac{\Omega}{2}\right) < r

where Ω\Omega is the angle between θA\theta_A and θB\theta_B. In multi-billion parameter networks, this reduction in parameter magnitude dampens activation variance across transformer layers, leading to degraded perplexity.

       LERP (Euclidean Chord) vs SLERP (Spherical Arc)
       
                     SLERP Path (Constant Norm)
                           .-'""'-.
                        .-'        '-.
                     .-'              '-.
                 θ_A ●───────────────────● θ_B
                      \   LERP Chord    /
                       \ (Norm Drops)  /
                        \             /
                         \     Ω     /
                          \    │    /
                           \   │   /
                            \  │  /
                             \ │ /
                              \│/
                               ● Origin (0,0)

3.2 SLERP Derivation

Spherical Linear Interpolation (Shoemake, 1985; adapted to LLMs by Goddard et al., 2024) traverses the great circle arc connecting the two normalized parameter vectors on a hypersphere.

Let vA=θAθAv_A = \frac{\theta_A}{\|\theta_A\|} and vB=θBθBv_B = \frac{\theta_B}{\|\theta_B\|}. The angle Ω\Omega between them is:

Ω=arccos(vAvBvAvB)=arccos(vATvB)\Omega = \arccos\left(\frac{v_A \cdot v_B}{\|v_A\| \|v_B\|}\right) = \arccos(v_A^T v_B)

The interpolated unit vector v(t)v(t) for interpolation factor t[0,1]t \in [0, 1] is:

SLERP(vA,vB;t)=sin((1t)Ω)sinΩvA+sin(tΩ)sinΩvB\text{SLERP}(v_A, v_B; t) = \frac{\sin((1 - t)\Omega)}{\sin \Omega} v_A + \frac{\sin(t \Omega)}{\sin \Omega} v_B

The final parameter tensor θ(t)\theta(t) scales v(t)v(t) by interpolating the original vector magnitudes:

θ(t)=[(1t)θA+tθB]SLERP(vA,vB;t)\theta(t) = \left[ (1 - t)\|\theta_A\| + t\|\theta_B\| \right] \cdot \text{SLERP}(v_A, v_B; t)

By preserving angular velocity and vector norm, SLERP maintains layer activation statistics and outperforms linear averaging on pairwise model combinations.


4. TIES-Merging: Trimming, Electing Sign, and Disjoint Merging

To scale model merging to K>2K > 2 models without destructive interference, Yadav et al. (NeurIPS 2023) introduced TIES-Merging (TRIM, ELECT SIGN & MERGE).

TIES and DARE Architecture

TIES identifies two primary drivers of degradation during multi-task fusion:

  1. Parameter Redundancy: A vast majority of parameter changes in τk\tau_k consist of small, low-magnitude noise accumulated during gradient descent that contribute little to downstream capability.
  2. Sign Disagreements: When different task vectors push the same parameter coordinate in opposing directions (+ vs + \text{ vs } -), standard averaging cancels both signals.

4.1 The Three-Stage TIES Algorithm

For a set of KK fine-tuned models with task vectors {τ1,τ2,,τK}\{\tau_1, \tau_2, \dots, \tau_K\} relative to base initialization θ0\theta_0:

Step 1: Trim (Sparsification)

For each task vector τk\tau_k, retain only the top-p%p\% elements by absolute magnitude (typically p[10%,30%]p \in [10\%, 30\%]). All remaining coordinates are reset to zero:

τ^k(j)={τk(j)if τk(j)Quantile1p(τk)0otherwise\hat{\tau}_k^{(j)} = \begin{cases} \tau_k^{(j)} & \text{if } |\tau_k^{(j)}| \ge \text{Quantile}_{1-p}(|\tau_k|) \\ 0 & \text{otherwise} \end{cases}

Step 2: Elect Sign (Directional Consensus)

For each parameter index j{1,,d}j \in \{1, \dots, d\}, compute the majority directional vector γ(j){1,+1}\gamma^{(j)} \in \{-1, +1\} across all trimmed task vectors based on total coordinate mass:

γ(j)=sgn(k=1Kτ^k(j))\gamma^{(j)} = \text{sgn}\left(\sum_{k=1}^K \hat{\tau}_k^{(j)}\right)

If the sum is zero, γ(j)\gamma^{(j)} defaults to sgn(k=1Kτk(j))\text{sgn}\left(\sum_{k=1}^K \tau_k^{(j)}\right).

Step 3: Disjoint Merge (Selective Averaging)

For each coordinate jj, compute the average strictly among task vectors whose sign matches the elected majority γ(j)\gamma^{(j)}. Vectors with opposing signs are excluded for that coordinate:

A(j)={k{1,,K}τ^k(j)0 and sgn(τ^k(j))=γ(j)}A^{(j)} = \left\{ k \in \{1, \dots, K\} \mid \hat{\tau}_k^{(j)} \neq 0 \text{ and } \text{sgn}(\hat{\tau}_k^{(j)}) = \gamma^{(j)} \right\}

τTIES(j)={1A(j)kA(j)τ^k(j)if A(j)>00otherwise\tau_{\text{TIES}}^{(j)} = \begin{cases} \frac{1}{|A^{(j)}|} \sum_{k \in A^{(j)}} \hat{\tau}_k^{(j)} & \text{if } |A^{(j)}| > 0 \\ 0 & \text{otherwise} \end{cases}

The final merged model is constructed with global scaling factor λ\lambda:

θmerged=θ0+λτTIES\theta_{\text{merged}} = \theta_0 + \lambda \cdot \tau_{\text{TIES}}

By pruning low-magnitude updates and filtering directional conflicts, TIES eliminates destructive interference while retaining high-confidence domain updates.


5. DARE: Drop And REscale

While TIES trims by deterministic top-kk magnitude, Yu et al. (ICML 2024) proved in DARE (Drop And REscale) that fine-tuned delta parameters exhibit extreme structural redundancy.

5.1 The Super Mario Phenomenon

Yu et al. discovered that between 90% and 99% of delta parameters in SFT models can be set to zero at random without degrading model performance, as long as the remaining parameters are rescaled to maintain expected activation outputs.

5.2 Mathematical Formulation

Given task vector τk=θkθ0\tau_k = \theta_k - \theta_0 and drop rate p[0.90,0.99]p \in [0.90, 0.99]:

  1. Sample a random binary mask mk(j)Bernoulli(1p)m_k^{(j)} \sim \text{Bernoulli}(1 - p) for each coordinate jj.
  2. Compute the sparsified, rescaled delta vector τ~k\tilde{\tau}_k:

τ~k(j)=mk(j)1pτk(j)\tilde{\tau}_k^{(j)} = \frac{m_k^{(j)}}{1 - p} \cdot \tau_k^{(j)}

Because E[mk(j)]=1p\mathbb{E}[m_k^{(j)}] = 1 - p, the mathematical expectation of the rescaled vector is unbiased:

E[τ~k(j)]=E[mk(j)]1pτk(j)=τk(j)\mathbb{E}[\tilde{\tau}_k^{(j)}] = \frac{\mathbb{E}[m_k^{(j)}]}{1 - p} \cdot \tau_k^{(j)} = \tau_k^{(j)}

                   DARE Sparsification & Rescaling
                   
Original Delta:   [ +0.04 ,  -0.02 ,  +0.08 ,  -0.05 ,  +0.01 ]
Bernoulli Mask:   [   1   ,    0   ,    0   ,    1   ,    0   ]  (p = 0.6)
Dropped Delta:    [ +0.04 ,    0   ,    0   ,  -0.05 ,    0   ]
Rescaled (x 2.5): [ +0.10 ,    0   ,    0   ,  -0.125,    0   ]

5.3 DARE-TIES and DARE-Task Arithmetic

DARE is routinely paired with downstream merge algorithms:

  • DARE-Task Arithmetic: Sparsify each delta with DARE, then sum: θ0+λkτ~k\theta_0 + \lambda \sum_k \tilde{\tau}_k.
  • DARE-TIES: Sparsify each delta with DARE, then pass the surviving coordinates through TIES sign election and disjoint averaging.

By eliminating up to 99% of non-zero coordinates before merging, DARE drastically reduces coordinate overlap between models, lowering collision probability to near zero.


Beyond weight averaging within identical layer topologies, recent advances explore cross-layer stacking and automated parameter discovery.

6.1 Model Soups

Introduced by Wortsman et al. (ICML 2022), Model Soups average the weights of multiple models fine-tuned with different hyperparameters (learning rates, random seeds, augmentations) from the same base model:

  • Uniform Soup: Direct arithmetic mean 1Kk=1Kθk\frac{1}{K} \sum_{k=1}^K \theta_k.
  • Greedy Soup: Sequentially adds candidate checkpoints to the running average only if validation performance improves.

6.2 Passthrough / Frankenmerging (Layer Stacking)

Passthrough merging stitches layers from one or more models into non-standard depth configurations (for example, creating a 120-billion parameter model by repeating middle layers of a 70B checkpoint).

While effective at increasing capacity, frankenmerges introduce layer-to-layer hidden state distribution shifts, requiring careful interpolation across boundary layers.

6.3 Evolutionary Model Merging (Sakana AI)

Akiba et al. (2024) automated the discovery of merge configurations using evolutionary algorithms (specifically CMA-ES). Evolutionary merging operates in two spaces:

  1. Parameter Space (Layer-Wise Merging): Optimizes layer-by-layer mixing coefficients wl\mathbf{w}_l to balance task contributions across depth.
  2. Data-Flow Space (Cross-Layer Routing): Optimizes inference-time activation pathways through layers of disparate models.

7. Comparative Method Matrix

| Method | Number of Models (KK) | Sparsification Strategy | Conflict Resolution | Primary Strength | Key Limitation | | :--- | :--- | :--- | :--- | :--- | :--- | | Linear (LERP) | Arbitrary (K2K \ge 2) | None | Simple weighted average | Fast, zero hyperparameter tuning | Severe destructive sign interference | | SLERP | Pairwise (K=2K = 2) | None | Hyperspherical arc interpolation | Preserves weight norm and activation variance | Restricted to pairwise merges | | Task Arithmetic | Arbitrary (K2K \ge 2) | Optional manual scaling | Linear delta addition | Supports capability subtraction/unlearning | Fragile to magnitude disparities | | TIES-Merging | Arbitrary (K2K \ge 2) | Deterministic top-k%k\% magnitude trim | Majority sign election + disjoint mean | Eliminates gradient clashes and noise | Requires tuning trim ratio pp and weight λ\lambda | | DARE-TIES | Arbitrary (K2K \ge 2) | Random Bernoulli drop (p[0.9,0.99]p \in [0.9, 0.99]) + rescaling | Majority sign election + disjoint mean | Minimal inter-model parameter collision | Non-deterministic sampling variance |


8. Implementation and Practical Engineering Recipes

Practical model merging is standardized around open-source tools such as MergeKit (Goddard et al., 2024). MergeKit executes out-of-core merging by streaming layer tensors from disk, enabling multi-model 70B merges on consumer GPUs or CPU RAM.

8.1 Example MergeKit Configuration: DARE-TIES

Below is a declarative YAML specification combining a general instruction model, a math specialist, and a coding specialist using DARE-TIES:

models:
  - model: mistralai/Mistral-7B-v0.1
    # Base model provided as reference initialization
  - model: WizardLM/WizardMath-7B-V1.1
    parameters:
      density: 0.5
      weight: 0.3
  - model: deepseek-ai/deepseek-coder-7b-instruct
    parameters:
      density: 0.5
      weight: 0.4
  - model: mistralai/Mistral-7B-Instruct-v0.2
    parameters:
      density: 0.5
      weight: 0.3

merge_method: dare_ties
base_model: mistralai/Mistral-7B-v0.1
parameters:
  int8_mask: true
dtype: bfloat16

8.2 Critical Engineering Prerequisites

  1. Strict Lineage Homogeneity: All merged models must share the exact same base model architecture and tokenizer vocabulary. Merging a Llama-3-derived checkpoint with a Mistral checkpoint causes complete representational collapse due to incompatible embedding indices and attention dimensions.
  2. Tokenizer Alignment: If fine-tuned models extended the special token vocabulary (e.g., adding distinct chat formatting tags), token embeddings must be reconciled or mapped prior to weight fusion.
  3. Safety Alignment Drift: Merging a safety-tuned model with an uncensored domain expert frequently dilutes safety guardrails, requiring post-merge evaluation across jailbreak and toxicity benchmarks.

Sources

Written by

More to read

  • Model Context Protocol (MCP) in Production AI Agents: Architecture, Transport Layers, Security Sandboxing, and Tool Federation

    Model Context Protocol (MCP) in Production AI Agents: Architecture, Transport Layers, Security Sandboxing, and Tool Federation The transition from standalone large language models to autonomous agentic systems has introduced an integration scaling problem. Early agent implementations relied on proprietary, ad hoc function-calling wrappers written specifically for each model provider or orchestration framework. Connecting $M$ distinct agent runtimes to $N$ enterprise data stores and developer to

    1 min
  • Byte-Pair Encoding (BPE) and Modern Subword Tokenization: Mathematical Foundations, Merge Dynamics, Byte-Level Encodings, and Vocabulary Compression Mechanics

    Byte-Pair Encoding (BPE) and Modern Subword Tokenization: Mathematical Foundations, Merge Dynamics, Byte-Level Encodings, and Vocabulary Compression Mechanics Tokenization is the discrete boundary interface between raw textual sequences and the continuous vector representations of autoregressive large language models. Before an attention block computes a single inner product or a feed-forward network applies an activation function, an input string must be mapped into an ordered sequence of disc

    1 min
  • Huawei Cloud Launches CodeArts Agent into General Availability Across Asia Pacific

    Huawei Cloud has officially moved its CodeArts Agent development platform from public beta to general availability across the Asia Pacific region. The commercial release makes both Basic and Professional editions accessible to international enterprise accounts, expanding the vendor's enterprise AI infrastructure stack beyond its domestic market. The rollout follows an initial open beta launched in Thailand in July 2026. CodeArts Agent is structured around multi-agent coordination across the sof

    1 min