Introduction
A released language model is routinely fine-tuned into specialists, one per domain: instruction following, mathematics, coding, multilingual understanding, safety. Serving one specialist per domain is expensive, and training a single multi-task model requires all the data at once. Model merging asks for something cheaper: fuse the specialists' weights into one model with the parent's architecture that keeps as much of each specialist's in-domain ability as possible, while retaining the parent's general knowledge. Merging domain-specialised language models is now benchmarked in its own right [1].
The simplest rules are pure functions of the weights. A uniform average of the checkpoints [2], which is the starter of this task, keeps the merged model close to every specialist but dilutes each specialist's update by the number of specialists. Task arithmetic [3] adds the updates instead, which keeps their size but lets them interfere; TIES [4], DARE [5] and consensus masks [6] sparsify or mask the updates to reduce that interference, and Localize-and-Stitch [7] keeps only localised regions of each. Data-based rules use activation statistics or gradients: RegMean [8] and RegMean++ [9] solve a per-layer regression on input statistics, Fisher merging [10] weights parameters by their Fisher information, and AdaMerging [11] learns merge coefficients. A further family optimises the merged update directly [12], in one case without data, guided by the task vectors themselves [13].
Two features of this task make it harder than merging specialists of one shared parent.
The updates are not all relative to the same checkpoint. The method sees the checkpoint lineage, and when the parent is a post-trained model its own pre-trained base is part of that lineage. A specialist trained from the base differs from the target by its domain update and by the absence of the target's post-training; measuring it against the target would count the missing post-training as part of its update. Transporting weight differences between checkpoints of one lineage is an established idea, for instance adding a chat vector to equip a model with instruction following [14], and separating instruction-following knowledge from task-specific knowledge layer by layer [15].
The merged model must stay where the specialists were valid. Every specialist is a working model at its own distance from its parent. A merged update that is larger than any of them is an extrapolation, and nothing guarantees that the model is still good there.
Method
We call our method LA-GLS (lineage-anchored, step-bounded Gram least-squares merging). It uses no calibration data, no forward passes and no gradients: it is a closed-form function of the node weights and the lineage graph. It replaces the starter's uniform average entirely.
Lineage-anchored domain updates
For every specialist we take the update it actually learned, measured against its own parent in the lineage,
and add it to the target, not to the parent. A specialist trained from the base therefore contributes its domain update without subtracting the target's post-training, and one trained from the target or an intermediate checkpoint contributes its update in the same way. When a domain has more than one specialist, their updates are averaged first, giving one update per domain :
If a specialist's parent label is not a node of the lineage, the target is used in its place.
dev = ctx.device
anchor = lineage.nodes[lineage.target].weights
groups = {}
for lab in lineage.labels(role="expert"):
node = lineage.nodes[lab]
if node.domain not in groups:
groups[node.domain] = []
groups[node.domain].append((lab, node.parent))
doms = [d for d in lineage.domains if d in groups]
if not doms:
doms = sorted(groups, key=lambda d: str(d))
if not doms:
return {k: anchor[k].clone() for k in anchor.keys()}
def domain_tau(pairs, k):
acc = None
for e, p in pairs:
pw = lineage.nodes[p].weights if p in lineage.nodes else anchor
t = lineage.nodes[e].weights.get(k, device=dev, dtype=torch.float32) - pw.get(k, device=dev, dtype=torch.float32)
acc = t if acc is None else acc + t
return acc / len(pairs)A least-squares merge weighted by each update's own input directions
For one weight matrix (output by input) with target value , write for the domain updates of that matrix and define each update's normalised input Gram matrix
We choose the merged update to agree with each domain's update on that domain's own input directions, with a small ridge toward zero:
This has the closed form of RegMean [8], with one substitution: the input statistics that RegMean collects from data are replaced by the Gram matrix of the update itself, which makes the rule data-free, in the spirit of merging guided by the task vectors alone [13]. The ridge is scaled to the trace, ; since each has unit trace, this is times the number of non-zero domain updates, divided by the input dimension . Domain updates that are exactly zero for a matrix are skipped.
The solution behaves as intended in the two cases that matter. Write , so that . If an input direction (a right singular vector of with singular value ) is used by no other domain, the merged update along it is
that is, the domain's own update, shrunk appreciably only where its weight is small compared with the ridge. If two domains use the same input direction with weights and , then , a weighted average of the two updates rather than their sum. Directions used by no domain stay at the target. Uniform averaging dilutes the first case and task arithmetic sums the second; the least-squares merge does neither.
s_mat = None
n_mat = None
for t in taus:
fn2 = float(t.square().sum())
if fn2 <= 0.0:
continue
g_mat = (t.t() @ t) / fn2
dg = t @ g_mat
s_mat = g_mat if s_mat is None else s_mat + g_mat
n_mat = dg if n_mat is None else n_mat + dg
del g_mat, dg
if s_mat is None:
delta = mean_tau
else:
d_in = s_mat.shape[0]
lam = ridge_rel * float(torch.trace(s_mat)) / max(d_in, 1)We solve the system by a Cholesky factorisation of . If the factorisation fails, the ridge is multiplied by 10, 100 and then 1000 before falling back to a least-squares solver with the original ridge, and if that fails too, or the result is not finite, the matrix takes the plain mean of the domain updates.
Bounding the step
The unconstrained solution can be much larger than any specialist's update. We therefore bound the merged update of every matrix relative to the root-mean-square size of the domain updates:
where is the number of domains that have specialists. The budget depends on the target's last training stage. When the target is already post-trained (its last stage is supervised fine-tuning, preference optimisation or reinforcement learning), : the post-trained behaviour is already in the anchor, and the domain updates are allowed to move it by at most one specialist radius. When the target is a pre-trained or continued-pretrained model, : its specialists must together supply the post-trained behaviour, and mutually orthogonal updates of equal norm add to a vector times as long as one of them.
delta = None
eye = torch.eye(d_in, device=dev, dtype=torch.float32)
for jit in (1.0, 10.0, 100.0, 1000.0):
try:
chol = torch.linalg.cholesky(s_mat + (lam * jit) * eye)
delta = torch.cholesky_solve(n_mat.t(), chol).t()
break
except RuntimeError:
delta = None
if delta is None:
try:
delta = torch.linalg.lstsq((s_mat + lam * eye).t(), n_mat.t()).solution.t()
except RuntimeError:
delta = mean_tau
if not bool(torch.isfinite(delta).all()):
delta = mean_tau
rms_step = step_beta * (sum(float(t.square().sum()) for t in taus) / len(taus)) ** 0.5
d_norm = float(delta.norm())
if d_norm > rms_step and d_norm > 0.0:
delta = delta * (rms_step / d_norm)
del s_mat, n_mat, eyeEverything else
Token embeddings and the output head are kept at the target, as in the starter. Parameters that are not matrices, such as normalisation scales and biases, take the plain mean of the domain updates. These need no explicit bound: by the triangle inequality and the inequality between the arithmetic and quadratic means,
so the mean update already lies within the radius.
ridge_rel = 0.05
if lineage.nodes[lineage.target].stage in ("sft", "preference", "rl"):
step_beta = 1.0
else:
step_beta = max(1.0, len(doms) ** 0.5)
merged: Dict[str, torch.Tensor] = {}
for k in sorted(anchor.keys()):
kl = k.lower()
if "embed" in kl or "lm_head" in kl or kl.endswith("wte.weight"):
merged[k] = anchor[k].clone()
continue
base = anchor.get(k, device=dev, dtype=torch.float32)
taus = [domain_tau(groups[d], k) for d in doms]
mean_tau = sum(taus) / len(taus)
if base.dim() != 2:
delta = mean_tauThe rule has no per-setting constants. Its step budget switches only on the target's training stage, which is a field of the lineage interface, so LA-GLS is the same algorithm on every setting.
Results
| Method | ① | ② | ③ | ④ | ||||
|---|---|---|---|---|---|---|---|---|
| Normalised performance ↑ | TriviaQA retention ↑ | Normalised performance ↑ | TriviaQA retention ↑ | Normalised performance ↑ | TriviaQA retention ↑ | Normalised performance ↑ | TriviaQA retention ↑ | |
| Muse Wonder Full | 69.90 | 0.427 | 87.56 | 0.352 | 78.54 | 0.477 | 102.8 | 0.319 |
| Unmerged parent model | 55.29 | 0.506 | 83.67 | 0.203 | 50.55 | 0.508 | 96.12 | 0.335 |
| Instruction specialist alone | 71.48 | 0.475 | 87.18 | 0.325 | 69.88 | 0.386 | 91.83 | 0.172 |
| Math specialist alone | 69.03 | 0.463 | 89.38 | 0.238 | 69.67 | 0.340 | 92.20 | 0.152 |
| Coding specialist alone | 66.89 | 0.487 | 84.44 | 0.356 | 63.83 | 0.495 | 93.28 | 0.290 |
| Multilingual specialist alone | 52.43 | 0.385 | 71.39 | 0.341 | 50.23 | 0.456 | 94.79 | 0.267 |
| Safety specialist alone | 67.25 | 0.424 | 81.82 | 0.318 | 62.62 | 0.392 | 88.06 | 0.211 |
| Weight average | 68.06 | 0.490 | 88.49 | 0.346 | 61.65 | 0.473 | 99.12 | 0.254 |
| Task arithmetic | 76.90 | 0.353 | 82.34 | 0.279 | 73.62 | 0.311 | 91.63 | 0.151 |
| TIES | 73.09 | 0.423 | 85.74 | 0.310 | 67.22 | 0.415 | 96.92 | 0.200 |
| DARE | 74.41 | 0.353 | 81.24 | 0.273 | 74.85 | 0.296 | 89.67 | 0.154 |
| Consensus TA | 75.68 | 0.398 | 84.40 | 0.304 | 73.60 | 0.352 | 93.91 | 0.165 |
| Localize-and-Stitch | 74.74 | 0.386 | 86.04 | 0.279 | 63.66 | 0.368 | 93.32 | 0.188 |
| RegMean | 76.96 | 0.461 | 90.13 | 0.346 | 71.03 | 0.459 | 101.6 | 0.233 |
| Fisher merging | 60.71 | 0.451 | 86.60 | 0.334 | 71.73 | 0.464 | 100.4 | 0.209 |
| RegMean++ | 76.14 | 0.468 | 89.80 | 0.337 | 70.34 | 0.468 | 102.2 | 0.250 |
| WUDI | 74.13 | 0.413 | 84.38 | 0.321 | 78.74 | 0.428 | 100.5 | 0.223 |
| DOGE-TA | 75.09 | 0.419 | 87.95 | 0.329 | 71.04 | 0.397 | 99.10 | 0.189 |
| AdaMerging | 73.38 | 0.382 | 77.61 | 0.186 | 73.15 | 0.382 | 98.78 | 0.162 |
| RAM | 74.24 | 0.455 | 86.77 | 0.323 | 69.47 | 0.433 | 98.69 | 0.210 |
| Localize-and-Stitch, tuned | 74.99 | 0.387 | 85.81 | 0.280 | 63.74 | 0.368 | 93.09 | 0.187 |
- ① Gemma-2-2B base pool (parent + 5 specialists)
- ② Gemma-2-2B-it pool (parent + 5 specialists)
- ③ Llama-3.2-3B base pool (parent + 5 specialists)
- ④ Llama-3.2-3B-Instruct pool (parent + 5 specialists)
Normalised performance. On L3.2-3B-Inst LA-GLS reaches 102.80,
above every published baseline; the strongest of them there is RegMean++ [9] at
102.20. On L3.2-3B it reaches 78.54, just
below WUDI-Merging [13] at 78.74 and well above the data-based
regression merges, RegMean at 71.03 and RegMean++ at
70.34, and above the uniform average that the task starts from, at
61.65. On Gemma2-2B-it it reaches 87.56, behind
RegMean [8] (90.13), RegMean++, native_math, DOGE-TA and the
uniform average (88.49); on this setting our rule is in fact slightly worse
than the starter. Gemma2-2B is our weakest: 69.90, which is
above the uniform average (68.06) but below thirteen of the twenty published
baselines, among them task arithmetic at 76.90 and the best,
RegMean [8], at 76.96.
Retention. Retention of the parent's general knowledge is where the step bound shows. On
Gemma2-2B-it, L3.2-3B and L3.2-3B-Inst LA-GLS retains more than every published merging method: on L3.2-3B-Inst
0.319 against 0.254 for the uniform average,
0.250 for RegMean++ and 0.151 for task
arithmetic; the only row above it there is the parent itself, at 0.335.
On L3.2-3B only the parent and native_coding retain more, and on Gemma2-2B-it only native_coding
does. On Gemma2-2B the picture reverses: our 0.427 is below the
uniform average (0.490), RegMean, RegMean++, Fisher merging and RAM, below the native_instruction,
native_math and native_coding rows, and below the parent's 0.506.
Against the two closest relatives of our rule the comparison is mixed. Against WUDI-Merging, also data-free and guided by task vectors, LA-GLS retains more on every setting and has higher normalised performance on Gemma2-2B-it and L3.2-3B-Inst, lower on Gemma2-2B and L3.2-3B. Against RegMean, whose closed form we reuse with a different Gram matrix, it is ahead on both metrics on L3.2-3B and L3.2-3B-Inst, ahead on retention but behind on normalised performance on Gemma2-2B-it, and behind on both on Gemma2-2B. Task arithmetic, which sums the updates without a bound, beats us on normalised performance on Gemma2-2B while retaining less than we do on every setting, which is the trade the step bound is designed to make; on Gemma2-2B that trade did not pay.
How we got here
"""Lineage-anchored, step-bounded Gram least-squares merging (data-free).
Each expert contributes the update it actually learned, tau = expert minus
its own parent in the lineage, transported onto the target; experts trained
from the base or an intermediate checkpoint therefore add their domain update
without subtracting the target's post-training. Multiple experts in one
domain are averaged first. For every weight matrix the merged update Delta
minimises sum_i ||(Delta - D_i) D_i^T||_F^2 / ||D_i||_F^2 plus a trace-scaled
ridge toward zero, i.e. Delta = (sum_i D_i G_i)(sum_i G_i + lam I)^{-1} with
G_i = D_i^T D_i / ||D_i||_F^2: input directions used by a single domain keep
that domain's full update, shared directions are averaged instead of summed,
and unused directions stay at the target. The least-squares step is then
bounded per matrix relative to the RMS size of the specialists' own steps,
||Delta||_F <= beta * sqrt(mean_i ||D_i||_F^2): every specialist is a valid
model at its own distance from its parent, while the unconstrained solution
sits several times farther from the target and leaves the basin in which
the linearised objective holds. The budget is beta = 1 when the target is
already post-trained (its SFT behaviour is in the anchor, so domain updates
only move within one specialist radius) and beta = sqrt(#domains) for a
(continued-)pretrained target, whose specialists must jointly supply that
behaviour and whose near-orthogonal updates combine to that radius.
Embeddings stay at the target; vector parameters take the mean update
(already inside the same bound)."""- The anchor follows the lineage, not a common parent. The docstring contrasts measuring each expert against its own parent with the alternative of measuring it against the target: experts trained from the base or an intermediate checkpoint would then carry a negative copy of the target's post-training. The starter's uniform average sidesteps the question by averaging whole checkpoints, which places the merged model between specialists that may not share a parent.
- Averaging and summing are both wrong in part. The docstring states the goal of the Gram least-squares step as follows (the parenthetical contrasts are ours): a direction used by one domain should keep that domain's full update (which averaging dilutes), a shared direction should be averaged rather than summed (which task arithmetic does not do), and unused directions should stay at the target.
- The unconstrained solution was judged too far from the target. The docstring's justification for the step bound is that the unconstrained least-squares solution "sits several times farther from the target" than the specialists do and so "leaves the basin in which the linearised objective holds". This is the agent's claim.
- The budget depends on what the target already knows. The two values of come with their own argument in the docstring: a post-trained target already carries its supervised behaviour, so one specialist radius suffices, while a pre-trained target needs its specialists to supply that behaviour jointly, and near-orthogonal updates combine to a radius times larger.
- Numerical failure is handled, not assumed away. The escalating jitter, the least-squares fallback and the final fallback to the mean update suggest that ill-conditioned Gram sums were anticipated; the code does not record whether any of these paths was ever taken.
The method is explicitly data-free, although the interface offers calibration and labelled validation splits, forward passes and gradients. Nothing in the code says whether data-based variants were tried.
Limitations
- Gemma2-2B is a failure. There LA-GLS is below thirteen of the twenty published baselines on normalised performance and below the uniform average on retention, so on that setting the method barely improves on the starter's normalised performance and protects general knowledge less well than the starter does. We have no measurement that explains why; one possibility consistent with the design is that a one-radius budget is too tight for the updates that setting needs, but we did not test it.
- Retention still costs something. On Gemma2-2B, L3.2-3B and L3.2-3B-Inst the merged model retains less general knowledge than the unmerged parent; the step bound limits the loss but does not remove it.
- The Gram matrix is a proxy. We replace the input statistics of RegMean with the update's own row-space Gram matrix. That is cheap and needs no data, but it measures which input directions a specialist changed, not which directions the domain's inputs actually occupy. The calibration data the task provides is never used, and we did not compare against activation-based Gram matrices in the same framework.
- The constants are set by hand. The ridge factor , the two values of and the stage-based switch between them are design choices.
- "Full update" is approximate. The ridge shrinks every single-domain direction by , so directions that carry a small share of an update's energy are damped more than the docstring's description suggests.
- The bound is isotropic. The rescaling shrinks the whole merged update of a matrix uniformly; it does not distinguish directions where extrapolation is harmless from those where it is not.
- Cost grows with the input dimension. Each matrix needs one Gram matrix per domain and a Cholesky factorisation of their sum, so memory grows as and time as per matrix. The run's measured merge cost is not among the inputs available to us.
References
- Yifei He, Siqi Zeng, Yuzheng Hu et al. (2025). MergeBench: A Benchmark for Merging Domain-Specialized LLMs. NeurIPS.
- Mitchell Wortsman, Gabriel Ilharco, Samir Yitzhak Gadre et al. (2022). Model soups: averaging weights of multiple fine-tuned models improves accuracy without increasing inference time. ICML.
- Gabriel Ilharco, Marco Tulio Ribeiro, Mitchell Wortsman et al. (2023). Editing Models with Task Arithmetic. ICLR.
- Prateek Yadav, Derek Tam, Leshem Choshen et al. (2023). TIES-Merging: Resolving Interference When Merging Models. NeurIPS.
- Le Yu, Bowen Yu, Haiyang Yu et al. (2024). Language Models are Super Mario: Absorbing Abilities from Homologous Models as a Free Lunch. ICML.
- Ke Wang, Nikolaos Dimitriadis, Guillermo Ortiz-Jimenez et al. (2024). Localizing Task Information for Improved Model Merging and Compression. ICML.
- Yifei He, Yuzheng Hu, Yong Lin et al. (2024). Localize-and-Stitch: Efficient Model Merging via Sparse Task Arithmetic. TMLR.
- Xisen Jin, Xiang Ren, Daniel Preotiuc-Pietro et al. (2023). Dataless Knowledge Fusion by Merging Weights of Language Models. ICLR.
- The-Hai Nguyen, Dang Huu-Tien, Takeshi Suzuki et al. (2025). RegMean++: Enhancing Effectiveness and Generalization of Regression Mean for Model Merging. TMLR.
- Michael Matena, Colin Raffel (2022). Merging Models with Fisher-Weighted Averaging. NeurIPS.
- Enneng Yang, Zhenyi Wang, Li Shen et al. (2024). AdaMerging: Adaptive Model Merging for Multi-Task Learning. ICLR.
- Yongxian Wei, Anke Tang, Li Shen et al. (2025). Modeling Multi-Task Model Merging as Adaptive Projective Gradient Descent. ICML.
- Runxi Cheng, Feng Xiong, Yongxian Wei et al. (2025). Whoever Started the Interference Should End It: Guiding Data-Free Model Merging via Task Vectors. ICML.
- Shih-Cheng Huang, Pin-Zu Li, Yu-Chi Hsu et al. (2024). Chat Vector: A Simple Approach to Equip LLMs with Instruction Following and Model Alignment in New Languages. ACL.
- Yan-Lun Chen, Yi-Ru Wei, Chia-Yi Hsu et al. (2025). Layer-Aware Task Arithmetic: Disentangling Task-Specific and Instruction-Following Knowledge. ACL.
- Xiangchi Yuan, Dachuan Shi, Chunhui Zhang et al. (2026). Behavior Knowledge Merge in Reinforced Agentic Models.