Open the workspace
Algorithms 101

Model merging explained: soups, task arithmetic, TIES, DARE and SLERP

How model merging combines fine-tuned LLMs without training: soups, task arithmetic, TIES, DARE and SLERP, with the math, a worked example and a toy run.

Model merging combines the weights of two or more fine-tuned models into a single model, without further training and without the inference cost of an ensemble. The simplest version averages the parameters of several fine-tunes of the same base (a model soup). More selective versions work on task vectors, the difference between a fine-tuned model and its base: they add them with a scaling factor (task arithmetic), trim small entries and resolve sign disagreements before adding (TIES), randomly drop most entries and rescale the rest (DARE), or interpolate along an arc instead of a straight line (SLERP). In the post-training stack merging sits after training, as a cheap combination step: fold a maths fine-tune and a coding fine-tune into one model, recover general ability lost during a narrow SFT run, or average the checkpoints of a hyperparameter sweep instead of keeping only the best one.

Where the methods come from#

Merging works because fine-tuned models that share a pre-trained initialisation tend to land in the same low-loss region. Frankle et al. (2020) formalised the idea as linear mode connectivity: two networks are linearly connected if every point on the straight line between their weights has low loss. They found that networks trained from different random initialisations generally are not, while copies trained onward from a shared, sufficiently trained starting point are. Fine-tuning from one pre-trained model is the extreme case of a shared starting point, and Wortsman et al. (2022a) observed that such fine-tunes often lie in a single low-error basin. That observation underlies every method here.

MethodPaperCore idea
Model soupsWortsman, Ilharco, Gadre et al., ICML 2022Average fine-tunes from a hyperparameter sweep; greedy soup adds a model only if validation accuracy improves.
Task arithmeticIlharco, Ribeiro, Wortsman et al., ICLR 2023Task vector ; add, negate or combine with a scale .
TIES-MergingYadav, Tam, Choshen, Raffel, Bansal, NeurIPS 2023Trim small entries, elect a sign per parameter, average only agreeing entries.
DARELe Yu, Bowen Yu, Haiyang Yu, Fei Huang, Yongbin Li, 2023 (ICML 2024)Drop each delta entry with probability , rescale survivors by .
SLERPShoemake, SIGGRAPH 1985 (for quaternions)Interpolate along the great-circle arc between two weight vectors.

Model soups showed the effect at scale: averaging fine-tunes of a ViT-G model from a hyperparameter sweep reached 90.94% top-1 on ImageNet, a state-of-the-art result at the time, at the inference cost of one model. Wortsman et al. (2022b) had earlier used the same interpolation between a zero-shot and a fine-tuned CLIP (WiSE-FT) to recover robustness lost in fine-tuning. Task arithmetic turned averaging into an algebra over skills. TIES and DARE address what goes wrong when you add several task vectors at once: they interfere. SLERP came to LLM merging through community practice and the open-source mergekit library (Goddard et al., 2024), which implements all of these methods behind a single configuration file.

The math, method by method#

Let be the base (pre-trained or instruction-tuned) weights and the weights of models fine-tuned from it. Define task vectors . Every method below outputs a merged .

Uniform and greedy soups

The greedy soup sorts the candidates by validation accuracy and adds each to the running average only if the average's validation accuracy does not drop. Soups are intended for models fine-tuned on the same task with different hyperparameters, where the average lands nearer the centre of a flat basin. Wortsman et al. relate the benefit to the flatness of the loss around the solutions. A simple way to see it: if the loss is roughly convex along the line between two models, Jensen's inequality gives their average a loss no higher than the mean of their losses.

Task arithmetic

With this is the uniform soup. Larger keeps more of each task's update; Ilharco et al. choose on held-out validation data. Negation, , removes a behaviour (they use it to reduce toxic generation), and analogies of the form can improve a task with no data for it.

TIES-Merging

Adding task vectors fails in two ways: many entries are small, redundant changes that add noise, and where two tasks moved a parameter in opposite directions their sum cancels both. TIES runs three steps per parameter :

The elected sign is the sign of the summed trimmed values, so it is decided by total magnitude rather than by vote count. The disjoint mean averages only over models that agree, so an entry kept by one model is not diluted by zeros from the others. The paper's default is and ; a search over and found best and between 0.9 and 1.1 equivalent.

DARE

DARE ("Drop And REscale") is a preprocessing step, not a merge rule: it sparsifies each task vector at random while keeping its expected value, and the result is fed to task arithmetic or TIES (dare_linear and dare_ties in mergekit). The claim behind it is that SFT deltas of large language models are small (the paper reports values typically within 0.002) and extremely redundant, so 90% or even 99% of them can be dropped without hurting the fine-tuned model. Sparser task vectors overlap less, so they interfere less when summed.

SLERP

For two weight vectors with angle ,

For unit vectors the linear midpoint has norm , shorter than either endpoint; SLERP stays on the arc and keeps the norm. In practice mergekit applies SLERP per tensor (with optionally varying by layer and by tensor type) and only between two models. Its variant nuslerp can instead interpolate task vectors relative to a base.

Task vectors from a shared base base theta0 theta_Atau_A theta_Btau_B average (soup) task arithmetic,lambda = 0.7 Scaled task vectors can move past the midpoint. LERP vs SLERP (two vectors) origin a b slerp t = 0.5norm 1.00 lerpnorm 0.71 At 10 degrees apart, lerp norm is 0.996.
Figure 1. Left: fine-tunes of one base are the base plus a task vector; a soup is the midpoint, task arithmetic scales the sum of task vectors. Right: SLERP follows the arc and keeps the norm; linear interpolation cuts the chord. For two fine-tunes of the same LLM the angle between full weight vectors is small, so the two are nearly identical.

Worked example: three task vectors by hand#

Take three task vectors over five parameters:

p1p2p3p4p5
0.50-0.100.300.02-0.40
0.400.20-0.600.01-0.30
-0.100.300.20-0.030.05
Task arithmetic, 0.2670.133-0.0330.000-0.217
TIES (keep top 3 of 5, )0.450.30-0.600.00-0.35

Trim. Keeping the three largest magnitudes in each vector zeroes 's p2 and p4, 's p2 and p4, and 's p4 and p5. Elect. The sums of trimmed values are , so the elected signs are . Disjoint mean. For p1, the agreeing entries are 0.5 and 0.4, mean 0.45; 's is discarded. For p2, only 's 0.3 survived trimming, so it is kept at full strength rather than divided by three. For p3, the values 0.3, and 0.2 sum to , so the single large negative entry wins and the merged value is , where task arithmetic averages to . That last parameter shows TIES's bias in both directions: it protects a large, confident change from being cancelled, and it also discards two smaller changes that together pointed the other way.

DARE on with and seeded mask gives : two survivors, each doubled. The expected value equals , but a single draw does not, which is why DARE relies on the very high redundancy of large-model deltas. SLERP: for two unit vectors at 90 degrees, the linear midpoint has norm while SLERP's has norm 1.0; at 30 degrees the gap is 0.966 versus 1.0; at 10 degrees, 0.996 versus 1.0.

Toy run: merging two fine-tunes of a small network#

To compare the methods end to end, we pre-trained a small MLP (16 inputs, two tanh hidden layers of 64, 6 classes) on a broad classification task defined by a random teacher network, then fine-tuned it separately on two related tasks, A and B. Each task uses a perturbed copy of the teacher and inputs drawn from its own region of input space, so the tasks share structure with pre-training but disagree in places. Fine-tuning used Adam for 600 steps; every merge coefficient was chosen on a validation split and evaluated on a separate test split; 5 seeds. All numbers are the script's output.

ModelTask A accuracyTask B accuracyMean
Base (pre-trained)44.5%49.4%47.0%
Fine-tuned on A75.2%43.2%59.2%
Fine-tuned on B40.5%70.1%55.3%
Uniform average (soup)58.4%58.9%58.6%
SLERP, 58.4%58.9%58.6%
Task arithmetic (tuned )68.6%61.1%64.8%
TIES, 53.2%53.8%53.5%
TIES, 63.7%56.4%60.1%
TIES, (sign election only)65.9%57.7%61.8%
DARE + task arithmetic67.2%56.1%61.7%
Toy run: one merged model, two tasks (mean of 5 seeds)0204060804449base7543FT on A4170FT on B5859average6961task arith.5354TIES 20%6756DARE + TAtest accuracyaccuracy on task Aaccuracy on task B
Figure 2. Test accuracy on each task for the individual fine-tunes and four merges (mean of 5 seeds). Task arithmetic with a tuned scale gives the best single model for both tasks; no merge matches the specialist on its own task.

Several results are worth reading carefully. Task arithmetic with tuned on validation (it chose 0.7 to 1.0) beat the plain average by 6 points, because halves each task's update. SLERP matched the average to the reported precision: the full weight vectors of the two fine-tunes had cosine similarity of about 0.987, so the arc and the chord are almost the same path (the linear midpoint's norm was 0.997 of SLERP's). In this small, dense network TIES's default 20% trim hurt: it fell below the plain average, and accuracy recovered as grew. The two task vectors disagreed in sign on about 47% of entries, yet electing signs without trimming still did not beat tuned task arithmetic. DARE's random dropping cost about 3 points against task arithmetic.

The reason is the premise behind TIES and DARE: redundancy. Here the fine-tuning deltas were 10 to 13% of the base weights' norm, and dropping 90% of a single model's delta took task A accuracy from 75.2% to 68.8% (99% dropped: 47.3%, near the base). The DARE paper reports that LLM SFT deltas are far smaller and more redundant, so the same operations remove noise rather than signal. The lesson for practice is not that TIES and DARE do not work. It is that their defaults encode an assumption about the models you are merging, and you should check it, for example by sparsifying one model alone and measuring what it loses, before trusting the defaults.

The procedure, step by step#

base = load("base-model")                  # common ancestor; must match architecture and tokenizer
ckpts = [load(p) for p in candidate_paths] # fine-tunes of that base
taus = [{k: c[k] - base[k] for k in base} for c in ckpts]
for method, grid in [("task_arithmetic", lambdas), ("ties", ties_grid), ("dare_ties", dare_grid)]:
    for params in grid:
        merged = merge(base, taus, method, **params)          # per tensor, in float32
        score[method, params] = evaluate(merged, validation_suites)
best = argmax(score)                        # pick on validation, report on held-out test
save(merge(base, taus, *best), "merged")

What you need. Two or more checkpoints with identical architecture, fine-tuned from the same base (or from one another). Same tokenizer and vocabulary, or an explicit plan for embeddings. A validation set for every capability you want to keep, because merge coefficients are hyperparameters and the only way to choose them is to evaluate. No training data is needed for the merge itself. Adapters. LoRA adapters trained on the same base can be merged by first materialising each product as a dense delta; averaging the and factors separately is not equivalent, since .

Where merging fits in a post-training pipeline#

Merging is most useful as a cheap step between expensive ones. Four patterns cover most of its use in practice.

Recovering what a narrow fine-tune broke. A model fine-tuned hard on one domain often loses general instruction following or robustness. Interpolating part of the way back toward the starting checkpoint, with between 0.5 and 0.9, frequently keeps most of the domain gain and much of the general ability. This is WiSE-FT applied to language models, and it is the first thing to try when a fine-tune regresses on a broad evaluation.

Combining specialists trained in parallel. Teams that train separate maths, coding and tool-use fine-tunes from one base can merge them instead of rebuilding a multi-task data mix. Expect each skill to lose a few points relative to its specialist; whether that is acceptable depends on how the model will be served. If skills can be routed at inference time, separate adapters avoid the loss entirely.

Averaging checkpoints of one run. Averaging the last few checkpoints of an SFT or preference run, or several seeds of the same recipe, is a uniform soup. It usually smooths out the noise of picking a single checkpoint and costs nothing but evaluation.

Merging after alignment stages. Merging a preference-tuned or RL-tuned model back toward its SFT parent trades some of the alignment gain for less drift, which can be a useful knob when the later stage over-optimised. Treat the interpolation coefficient like a KL budget chosen after the fact, and evaluate safety and the targeted behaviour at each setting.

Hyperparameters#

MethodParameterStarting valueHow to tune
Soupwhich models to includegreedy by validationSort by validation score, add while the average improves.
Task arithmetic (or per-model weights)0.5 to 1.0Grid on validation; with many tasks the best usually falls below 1.
TIESdensity , , (paper)Check how much one model loses at that density first; raise if it is a lot.
DAREdrop rate (density ), for LLM SFT deltasLower when deltas are large (long training, continued pre-training, RL).
SLERP, optionally per layer0.5Layer-wise schedules (for example more of one model in attention, the other in MLP) are common; validate each.

Compute and memory#

Merging needs no gradients and no GPU. It is a streaming element-wise operation over tensors, so memory is a few tensors at a time if done lazily, and time is dominated by reading and writing checkpoints. For a 7B model in bf16 (about 14 GB per checkpoint), merging three models plus a base reads roughly 56 GB and writes 14 GB, minutes on a CPU. Do arithmetic in float32 even for bf16 inputs; small deltas lose precision when subtracted in bf16. The real cost is evaluation: every coefficient setting is a new model to benchmark, so a grid of 20 settings across 5 evaluation suites is 100 evaluation runs. That still compares favourably with multi-task fine-tuning, which needs all the training data in one place and a full training run.

Failure modes and how to detect them#

No shared basin. Models fine-tuned from different bases, or trained long enough to leave the base's basin (continued pre-training on large corpora, long RL runs), may not be linearly connected. The merged model's loss on a simple held-out set will be higher than both endpoints'. Check by evaluating a few points on the straight line between two models before merging; a barrier in the middle means do not merge.

Interference. Each skill degrades a little in the merge, and with many models a lot. Track every source model's own benchmark in the merged model, not only an aggregate. Sign-conflict rate between task vectors is a useful cheap diagnostic.

Format and template conflicts. Merging an instruction model that uses one chat template with one that uses another produces a model that follows neither reliably. Align templates and special tokens before merging.

Scale miscalibration. too large over-amplifies task vectors and produces degenerate outputs (repetition, broken formatting); too small and the merge regresses to the base. Always sweep it.

Benchmark overfitting. Merges are cheap, so it is easy to try hundreds and pick the best on a public leaderboard. Choose coefficients on validation data that is disjoint from the data you report.

Safety regression. Merging a capability fine-tune into an aligned model can dilute refusal behaviour. Include safety evaluations in the selection suite.

When to merge, and which method#

SituationUse
Several runs of the same task from a hyperparameter sweepGreedy soup.
A fine-tune lost general ability or robustnessInterpolate back toward the base (WiSE-FT style), choosing on both in-domain and general evaluations.
Two or three skill fine-tunes of the same baseTask arithmetic with tuned ; then try TIES or DARE and keep whichever validates best.
Many fine-tunes (five or more) of a large modelTIES or DARE-TIES; interference grows with the number of models.
Exactly two models, want a smooth blendSLERP, possibly with a per-layer schedule.
Remove a behaviour (toxicity, a memorised fact pattern)Task vector negation, then evaluate side effects.
Different base models or architecturesDo not merge; use distillation.
Need specialist-level quality on every taskMulti-task fine-tuning, or keep separate LoRA adapters and route.

Implementation#

The core operations in PyTorch, per tensor:

import torch

def task_arithmetic(base, tunes, lam):
    return {k: base[k] + lam * sum(t[k] - base[k] for t in tunes) for k in base}

def ties(base, tunes, density=0.2, lam=1.0):
    out = {}
    for k in base:
        taus = torch.stack([(t[k] - base[k]).float().flatten() for t in tunes])
        n_keep = max(1, int(density * taus.shape[1]))
        thr = taus.abs().topk(n_keep, dim=1).values[:, -1:]          # per-model threshold
        taus = torch.where(taus.abs() >= thr, taus, torch.zeros_like(taus))
        sign = torch.sign(taus.sum(0))                                # elect by total mass
        agree = (torch.sign(taus) == sign) & (taus != 0)
        merged = (taus * agree).sum(0) / agree.sum(0).clamp(min=1)    # disjoint mean
        out[k] = (base[k].float() + lam * merged.view_as(base[k])).to(base[k].dtype)
    return out

def dare(tau, p=0.9, generator=None):
    keep = torch.rand(tau.shape, generator=generator, device=tau.device) >= p
    return tau * keep / (1 - p)

def slerp(a, b, t, eps=1e-8):
    a32, b32 = a.float().flatten(), b.float().flatten()
    cos = torch.dot(a32, b32) / (a32.norm() * b32.norm() + eps)
    omega = torch.arccos(cos.clamp(-1, 1))
    if omega < 1e-4:
        out = (1 - t) * a32 + t * b32
    else:
        out = (torch.sin((1 - t) * omega) * a32 + torch.sin(t * omega) * b32) / torch.sin(omega)
    return out.view_as(a).to(a.dtype)

For real checkpoints, the open-source mergekit library handles sharded weights, lazy loading, tokenizer alignment and layer-wise schedules. A TIES merge is a short YAML file passed to mergekit-yaml config.yml ./merged:

# config.yml
merge_method: ties
base_model: org/base-7b
models:
  - model: org/base-7b-math
    parameters: {density: 0.2, weight: 0.5}
  - model: org/base-7b-code
    parameters: {density: 0.2, weight: 0.5}
dtype: bfloat16

Switch merge_method to task_arithmetic, dare_ties or slerp (exactly two models, with a global t) to compare methods on the same validation suite. In POFE, merging is treated as a post-training step like any other: candidates and coefficients are chosen on validation suites and the merged checkpoint is evaluated before release.

Further reading#

Frankle et al. (2020) for why merging can work at all; Wortsman et al. (2022a, 2022b) for soups and robust interpolation; Ilharco et al. (2023) for task vectors; Yadav et al. (2023) and Yu et al. (2024) for interference-aware merging; Matena and Raffel (2022) for Fisher-weighted averaging, which weights each parameter by an estimate of its importance; Goddard et al. (2024) for the tooling most LLM merges use.

Frequently asked questions#

What is model merging?

Combining the parameters of two or more fine-tuned models, usually sharing one base, into a single model without additional training. Methods range from plain weight averaging (model soups) to task arithmetic, TIES, DARE and SLERP.

What is a task vector?

The difference between a fine-tuned model's weights and its base model's weights. Ilharco et al. (2023) showed task vectors can be added to combine skills, negated to remove a behaviour, and scaled by a coefficient lambda chosen on validation data.

What is the difference between TIES and DARE?

TIES trims each task vector to its largest entries (20% by default), elects a sign per parameter by total magnitude, and averages only entries that agree. DARE randomly drops a fraction p of each task vector's entries and rescales the rest by 1/(1-p). DARE is a preprocessing step usually combined with task arithmetic or TIES.

When should I use SLERP instead of averaging?

SLERP interpolates two models along an arc and preserves weight norm, which matters when the weight vectors point in quite different directions. For two fine-tunes of the same base the angle is usually small and SLERP is close to linear averaging; it only supports two models at a time.

Can I merge models with different base models?

Generally no. Merging relies on the models sitting in the same low-loss basin, which fine-tunes of a common base usually do and independently trained models do not. For different bases or architectures, use distillation instead.

Does merging need a GPU?

No. Merging is element-wise arithmetic over checkpoint tensors and runs on a CPU in minutes for 7B models. The real cost is evaluating each candidate merge on validation suites to pick methods and coefficients.

References#

  1. Mitchell Wortsman, Gabriel Ilharco, Samir Yitzhak Gadre, Rebecca Roelofs, Raphael Gontijo-Lopes, Ari S. Morcos, Hongseok Namkoong, Ali Farhadi, Yair Carmon, Simon Kornblith, Ludwig Schmidt (2022). Model soups: averaging weights of multiple fine-tuned models improves accuracy without increasing inference time. arxiv.org/abs/2203.05482
  2. Mitchell Wortsman, Gabriel Ilharco, Jong Wook Kim, Mike Li, Simon Kornblith, Rebecca Roelofs, Raphael Gontijo-Lopes, Hannaneh Hajishirzi, et al. (2022). Robust fine-tuning of zero-shot models. arxiv.org/abs/2109.01903
  3. Gabriel Ilharco, Marco Tulio Ribeiro, Mitchell Wortsman, Suchin Gururangan, Ludwig Schmidt, Hannaneh Hajishirzi, Ali Farhadi (2023). Editing Models with Task Arithmetic. arxiv.org/abs/2212.04089
  4. Prateek Yadav, Derek Tam, Leshem Choshen, Colin Raffel, Mohit Bansal (2023). TIES-Merging: Resolving Interference When Merging Models. arxiv.org/abs/2306.01708
  5. Le Yu, Bowen Yu, Haiyang Yu, Fei Huang, Yongbin Li (2024). Language Models are Super Mario: Absorbing Abilities from Homologous Models as a Free Lunch. arxiv.org/abs/2311.03099
  6. Ken Shoemake (1985). Animating rotation with quaternion curves. doi.org/10.1145/325165.325242
  7. Jonathan Frankle, Gintare Karolina Dziugaite, Daniel M. Roy, Michael Carbin (2020). Linear Mode Connectivity and the Lottery Ticket Hypothesis. arxiv.org/abs/1912.05671
  8. Michael Matena, Colin Raffel (2022). Merging Models with Fisher-Weighted Averaging. arxiv.org/abs/2111.09832
  9. Charles Goddard, Shamane Siriwardhana, Malikeh Ehghaghi, Luke Meyers, Vlad Karpukhin, Brian Benedict, Mark McQuade, Jacob Solawetz (2024). Arcee's MergeKit: A Toolkit for Merging Large Language Models. arxiv.org/abs/2403.13257

Bring a model and a metric.

Tell us what the model should get better at. A post-training engineer replies within one business day with a plan, a compute estimate and an eval design.