↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

Interpolating two models

The TIES and DARE tabs merge models through their task vectors, their differences from a shared base. SLERP needs no base. It walks from one model's weights to the other's, tensor by tensor, with one share : is the first model, the second. A plain weighted average walks the straight line between them, the chord:

Spherical linear interpolation walks the arc instead. With the angle between the two tensors, each flattened to one long vector,

Shoemake introduced it in 1985 to animate rotations stored as unit quaternions, where the arc moves at constant angular speed. White later argued for it when moving between points in a generative network's latent space, and mergekit, a widely used merging toolkit, applies it to language models one tensor at a time. This page follows mergekit's slerp exactly, from Qwen2.5-0.5B-Instruct () to Qwen2.5-Coder-0.5B-Instruct ().

The angle between two models

The angle between the two models maps for all 290 tensors. The median is 49.7°, from 1.81° to 80.7°. By kind, the medians run from a few degrees for the norm weights through 9° to 25° for the biases and 43° to 68° for the attention and MLP matrices; the embeddings sit at 70.1°.

Most of that angle is Coder's own move. In the median tensor, Instruct sits 2.9° from the base model and Coder 49.7°. The Qwen2.5-Coder report gives the reason: the Coder models were trained on 5.5 trillion further tokens, mostly code, before their instruction tuning. Walking from Instruct to Coder is therefore nearly walking from the base to Coder.

When two tensors are almost parallel, is close to 0 and the weights are unstable, so mergekit falls back to lerp when (1.81°). One tensor here does: layer 14's post_attention_layernorm weight, ringed on the map.

Arc and chord

Arc and chord draws the plane through the origin and both tensors of the selected matrix, to scale. For two unit vectors the arc keeps length 1 while the chord sags in the middle: at , lerp's tensor is as long, 0.91 at the median angle. SLERP's two weights sum to more than 1 to make up for it.

For layer 12's v_proj (Ω 41.5°, lengths 6.33 and 6.54), gives : SLERP's tensor is 6.437 long and lerp's 6.019. At the weights are 0.780 and 0.272, both above lerp's 0.75 and 0.25: the arc's point is a little longer than the chord's and pulled slightly toward the middle (at the weights swap). mergekit applies these weights to the tensors as they are, not to unit vectors, so the arc bulges where the two lengths differ.

SLERP − lerp shows the difference entry by entry. For this matrix it is 6.9% of lerp's length at and 5.1% at 0.25 and 0.75.

A barrier between the two

Swept over t plots the mean negative log-likelihood (NLL) of the reference solutions at along both paths. On GSM8K, Instruct scores 1.10 nats per token, Coder 1.57 and the base 1.39. Just 10% of the way toward Coder it is already 2.35 along the arc and 2.21 along the chord. The arc peaks at 2.97 () and the chord at 2.84 (), before both fall near Coder's value. HumanEval shows the same hump, peaking at 1.02 and 0.945 against 0.236 for Instruct and 0.187 for Coder.

Frankle et al. call two networks linearly connected when the loss along the straight path between them does not rise above the ends. Wortsman et al.'s model soups found that fine-tunes of one pretrained model often are, which is why averaging them works. These two are not, along either path: Coder's long further training moved it far from the base, near which Instruct still sits. The arc's hump comes about 0.1 earlier than the chord's, and it falls earlier too: at SLERP is at 2.05 on GSM8K and lerp still at 2.73.

What the merges keep

Every model is scored greedily on 40 GSM8K rows (Instruct's task) and 40 HumanEval problems (Coder's), the code run against each problem's tests in a sandbox. Instruct solves 15 and 25, Coder 11 and 29, the base 5 and 22.

At and both paths lose both skills: SLERP solves 1 and 0 at each, lerp 1 and 0, then 0 and 0. The plain average on the TIES tab fails the same way. Past the barrier, at , the arc keeps part of Coder's skill and the chord less: SLERP solves 17 HumanEval problems, lerp 12, and neither more than 2 GSM8K rows. On the TIES tab, task arithmetic with , which adds Instruct's small change to Coder in full, keeps both skills (16 and 30); no scored point on either path between the two models does. The Replies show each model's answer to the selected problem.

Checks and what followed

mergekit 0.1.4's own slerp, run on every real tensor at each scored , agrees with the drawer's code to within 1.5e-5, a float32 rounding difference. The page recomputes the shown matrix of each recorded merge from the two stored models, and it equals the full merge's exactly. The drawer also matches mergekit's slerp and linear merges on a small model.

WARP (Ramé et al.) later used SLERP to merge RLHF policies, but between their task vectors, the differences from a shared initialization, as the TIES and DARE tabs merge. Applied that way the angle measures how differently two fine-tunes moved, not how far apart two whole models are.

Papers

  1. Animating rotation with quaternion curves Ken Shoemake · SIGGRAPH 1985 Introduces spherical linear interpolation, for rotations as unit quaternions.
  2. Sampling Generative Networks Tom White · arXiv 2016 Argues for slerp over linear interpolation between high-dimensional vectors, the form model merging tools took up.
  3. Arcee's MergeKit: A Toolkit for Merging Large Language Models Charles Goddard et al. · EMNLP 2024 The toolkit whose slerp merge (tensor by tensor, lerp for nearly parallel tensors) the page reproduces and checks against.
  4. Model soups: averaging weights of multiple fine-tuned models improves accuracy without increasing inference time Mitchell Wortsman et al. · ICML 2022 Weight averaging of fine-tunes of one model: the linear interpolation the page compares SLERP with.
  5. Linear Mode Connectivity and the Lottery Ticket Hypothesis Jonathan Frankle et al. · ICML 2020 When the straight path between two trained networks stays low in loss, and when it does not.
  6. WARP: On the Benefits of Weight Averaged Rewarded Policies Alexandre Ramé et al. · arXiv 2024 A later use of SLERP between fine-tuned policies' task vectors in RLHF.
  7. Qwen2.5-Coder Technical Report Binyuan Hui et al. · arXiv 2024 Qwen2.5-Coder-0.5B-Instruct, the t = 1 end of the interpolation.

See also