Training-Free Transformer Merging via
Sequential Local Operator Alignment

Akansh Maurya1   Ya-Wei Eileen Lin2,3   Stefanie Jegelka2,3,4   Sebastian U. Stich1   Rotem Mulayoff1
1CISPA Helmholtz Center for Information Security   2Munich Center for Machine Learning   3Technical University of Munich   4Massachusetts Institute of Technology
Model Merging
Training-Free
Transformer Circuits

TL;DR

  • Existing training-free mergers combine $\mathbf{W}_Q,\mathbf{W}_K,\mathbf{W}_V,\mathbf{W}_O$ independently — ignoring how attention operation actually operattes on inputs.
  • SLOA merges the functional operators $\mathbf{W}_Q\mathbf{W}_K^{\!\top}$ and $\mathbf{W}_V\mathbf{W}_O$ directly.
  • Same operator-alignment principle also handles LayerNorm and the MLP sub-blocks ($\mathbf{W}_1,\mathbf{W}_2$) — SLOA covers the whole transformer, not just attention.
  • Alignment is performed sequentially on activations of the partially-merged model.
  • Re-factorization lets rank act as capacity control.
  • Generalizes across modalities and scales — CLIP/ViT, RoBERTa, and LoRA-adapted LLaMA-2-7B experts.

Model Merging

  • $T$ task-specific models $\{\bm{\Phi}_1,\ldots,\bm{\Phi}_T\}$, each fine-tuned from the same pretrained $\bm{\Phi}_{\text{pre}}$ on its dataset $D_t$.
  • Goal: aggregate them into a single multi-task model without joint retraining on $D_1\cup\cdots\cup D_T$:
$$\begin{gathered} \bm{\Phi}_{\text{merge}} \;=\; g(\bm{\Phi}_1,\ldots,\bm{\Phi}_T) \\[3pt] \text{s.t.}\quad \mathcal{M}_t(\bm{\Phi}_{\text{merge}})\;\approx\;\mathcal{M}_t(\bm{\Phi}_t)\quad\forall\, t. \end{gathered}$$
  • Training-free: a small unlabeled calibration set is allowed; no gradient updates.

Transformer Architecture

Each transformer layer has two sub-modules with residual connections and LayerNorm.

Multi-Head Attention (MHA). Sum of $H$ heads:

$$\mathbf{Z}_{\text{MHA}}=\sum_{j=1}^{H}\mathrm{softmax}\!\Bigl(\tfrac{(\mathbf{X}\mathbf{W}_Q^{(j)})(\mathbf{X}\mathbf{W}_K^{(j)})^{\!\top}}{\sqrt{d_k}}\Bigr)\, \mathbf{X}\,\mathbf{W}_V^{(j)}\mathbf{W}_O^{(j)}$$
  • QK circuit $\mathbf{M}_{\text{QK}}^{(j)}=\mathbf{W}_Q^{(j)}\mathbf{W}_K^{(j)\top}$ — where attention reads.
  • VO circuit $\mathbf{M}_{\text{VO}}^{(j)}=\mathbf{W}_V^{(j)}\mathbf{W}_O^{(j)}$ — what is written.
  • Each circuit is a $d{\times}d$ operator with a hidden rank-$d_k$ bottleneck.

MLP block. Two linear projections separated by a nonlinearity $\sigma(\cdot)$:

$$\mathbf{Z}_{\text{MLP}}=\sigma\!\bigl(\mathbf{Z}\mathbf{W}_1\bigr)\mathbf{W}_2,\qquad \mathbf{W}_1\in\mathbb{R}^{d\times d_{\text{out}}},\;\mathbf{W}_2\in\mathbb{R}^{d_{\text{out}}\times d}.$$
  • SLOA aligns $\mathbf{W}_1$ on the attention output, then $\mathbf{W}_2$ on the merged post-activation $\sigma(\widehat{\mathbf{Z}}\mathbf{W}_1)$ — sequential, closed-form, same template as attention.

Motivation: Isolated merging breaks attention

Non-invariance plot

Relative functional error along linear interpolations between equivalent factorizations, grows rapidly with the scalar $c$.

  • Functional unit. Attention scores depend only on the product $\mathbf{M}_{\mathrm{QK}}=\mathbf{W}_Q\mathbf{W}_K^{\!\top}$ — not on $\mathbf{W}_Q,\mathbf{W}_K$ separately.
  • Hidden ambiguity. Any invertible $\mathbf{R}$ gives a different factorization with the same function:
    $$\bigl(\mathbf{W}_Q\mathbf{R}\bigr)\bigl(\mathbf{W}_K\mathbf{R}^{-\top}\bigr)^{\!\top} \;=\;\mathbf{W}_Q\mathbf{W}_K^{\!\top}.$$
  • Independent averaging fails. Averaging the two parameterizations element-wise gives $\bar{\mathbf{W}}_Q=\tfrac{1}{2}\mathbf{W}_Q(\mathbf{I}+\mathbf{R})$, $\bar{\mathbf{W}}_K=\tfrac{1}{2}\mathbf{W}_K(\mathbf{I}+\mathbf{R}^{-\top})$, so
    $$\bar{\mathbf{M}}_{\mathrm{QK}}=\bar{\mathbf{W}}_Q\bar{\mathbf{W}}_K^{\!\top} =\tfrac{1}{4}\mathbf{W}_Q(\mathbf{I}+\mathbf{R})(\mathbf{I}+\mathbf{R}^{-1})\mathbf{W}_K^{\!\top} \;\neq\;\mathbf{W}_Q\mathbf{W}_K^{\!\top}.$$
  • Unbounded blow-up. Scalar case $\mathbf{R}=c\mathbf{I}$:
    $$\bar{\mathbf{M}}_{\mathrm{QK}}=\dfrac{(1+c)(1+c^{-1})}{4}\,\mathbf{M}_{\mathrm{QK}} \;\;\xrightarrow[c\to\infty]{}\;\;\infty.$$
    Equality holds only at $c=1$; error grows without bound otherwise.
  • Consequence. Two task models that are functionally identical at the QK level can produce arbitrarily different merged attention scores under isolated weight averaging.

Key idea

  • Merge at the level of local functional operators, not raw weight tensors.
  • Each component's behavior is linear in its operator $\bm{\theta}$ — closed-form least squares.
  • Apply alignment sequentially: each merge corrects accumulated upstream error.
  • Factorize the merged operator back; the chosen rank controls multi-task capacity.

Method: Sequential Local Operator Alignment

SLOA illustration

SLOA aligns the effective local operators (QK, VO, MLP, LayerNorm), merges them sequentially under partially-merged activations, then factorizes each operator back into transformer-compatible weights.

Unified alignment objective

$$\bm{\theta}_{\mathrm{merge}}= \arg\min_{\bm{\theta}}\; \underbrace{\tfrac{1}{T}\!\sum_{t,i}\! \bigl\|\mathcal{A}(\widehat{\mathbf{Z}}_{t,i};\bm{\theta})- \mathcal{A}(\mathbf{Z}_{t,i};\bm{\theta}_t)\bigr\|_F^2}_{\text{activation matching}} \,+\, \underbrace{\tfrac{1}{T}\!\sum_t\!\|\bm{\theta}-\bm{\theta}_t\|^2_{\widehat{\chi}_t}}_{\text{data-aware geometry}}$$

Local operators & data-aware metrics

Component Local operator $\bm{\theta}$ Behavior map $\mathcal{A}(\mathbf{Z};\bm{\theta})$ Metric
LayerNorm $(\bm{\gamma},\bm{\beta})$ $\nu(\mathbf{X})\,\mathrm{diag}(\bm{\gamma})+\mathbf{1}\bm{\beta}^{\!\top}$ $\mathrm{Cov}(\nu(\chi))$
Linear map $\mathbf{W}$ $\mathbf{X}\mathbf{W}$ $\bm{\Lambda}$
QK component $\dfrac{1}{\sqrt{d_k}}\mathbf{W}_Q\mathbf{W}_K^{\!\top}$ $\mathbf{X}\bm{\theta}\mathbf{X}^{\!\top}$ $\bm{\Lambda}\otimes\bm{\Lambda}$
VO component $\mathbf{W}_V\mathbf{W}_O$ $\mathbf{A}\mathbf{X}\bm{\theta}$ $\bm{\Lambda}$

$\nu(\mathbf{X})$ is the LayerNorm-normalized input; $\mathbf{A}$ is the attention matrix; $\bm{\Lambda}=\alpha\,\mathrm{diag}\bigl(\mathrm{Cov}(\mathbf{X})\bigr)+\epsilon\mathbf{I}$.

  • Activation term matches local input–output behavior on calibration data.
  • Geometry term is a Mahalanobis distance: penalizes deviation along directions the calibration activations actually use.
  • For fixed activations the objective is quadratic in $\bm{\theta}$ — closed-form regularized least squares per component.
  • Sequential: downstream operators are aligned on activations from the partially merged model $\widehat{\mathbf{Z}}$.

Rank as capacity control

After merging the QK / VO operator in $\mathbb{R}^{d\times d}$, SVD the operator $\bar{\bm{\theta}}=\mathbf{U}\bm{\Sigma}\mathbf{V}^{\!\top}$ and factorize at chosen rank $r_j$.

QK circuit (with denominator $c_j=\sqrt{r_j}$):

$$\mathbf{W}_Q^{(j)}=\mathbf{U}_{r_j}(c_j\bm{\Sigma}_{r_j})^{1/2},\quad \mathbf{W}_K^{(j)}=\mathbf{V}_{r_j}(c_j\bm{\Sigma}_{r_j})^{1/2}$$

VO circuit:

$$\mathbf{W}_V^{(j)}=\mathbf{U}_{r_j}\bm{\Sigma}_{r_j}^{1/2},\qquad \mathbf{W}_O^{(j)}=\bm{\Sigma}_{r_j}^{1/2}\mathbf{V}_{r_j}^{\!\top}$$
  • $r_j = d_k$ preserves the original head width.
  • $r_j > d_k$ retains additional task-specific singular directions.
  • The sum of task heads can span a larger subspace than any single rank-$d_k$ head — expansion avoids unnecessary truncation.

SLOA in 4 steps

  1. Collect activations $\{\mathbf{Z}_{t,i}\}$ for each operator from a small calibration set.
  2. Order operators topologically $o_1\!\prec\!\cdots\!\prec\!o_M$ (LayerNorm $\to$ QK $\to$ VO $\to$ MLP).
  3. For each $o_m$: forward through the partially-merged model to get $\widehat{\mathbf{Z}}_{t,i}$, then solve closed-form regularized LS.
  4. Factorize QK/VO via SVD at chosen rank $r_j$ and write back transformer-compatible weights.

No gradients, no labels — one deterministic pass through the operator graph.

Vision: Merging ViT-B/32 (CLIP fine-tunes)

Table 1. Average classification accuracy (%) of the merged model under three increasingly difficult settings: 8, 14, and 20 task-specific ViT-B/32 models. Higher is better; training-free methods use 256 calibration examples per task. For SLOA, $r$ is the retained QK/VO factorization rank ($r{=}64$ matches the original head dimension).

MethodSamples Avg. Accuracy (%) $\uparrow$
8 tasks14 tasks20 tasks
Fine-tuned–90.3989.2689.78
Data-FreeWeight Averaging–66.2965.3761.08
Task Arithmetic–69.4966.4760.60
TIES-Merging–71.7067.5862.76
TSV-M–83.0479.1173.66
Iso-C–82.6477.9471.16
Iso-CTS–82.8779.2473.41
Training-FreeFisher Merging25669.1266.2661.74
RegMean25682.6377.9372.20
RegMean++25684.3780.0674.51
SLOA ($r{=}64$)25684.8981.9480.06
SLOA ($r{=}128$)25685.5082.6181.03
  • Even at the original rank, SLOA is the best method on all three benchmarks; the gap widens with more tasks.
  • Margin over RegMean++ at $r{=}64$: +0.6 (8t), +1.9 (14t), +5.5 pts (20t).
  • Rank expansion $r{=}64{\to}128$ consistently helps — the merged operator's spectrum spans a larger subspace than any single head.

NLU: Merging RoBERTa on 7 GLUE tasks

Table 2. Per-task and average Metric of the merged RoBERTa model on seven GLUE tasks (CoLA, SST-2, MRPC, QQP, MNLI, QNLI, RTE). Higher is better; training-free methods use 256 calibration examples per task. SLOA ($r{=}64$) preserves the original head rank; SLOA ($r{=}128$) expands the QK/VO factorization rank.

MethodSamplesMetric $\uparrow$
CoLASST-2MRPCQQPMNLIQNLIRTEAvg
Individual–0.60180.94040.89220.91410.87200.92710.79060.8483
Data-FreeWeight Averaging–0.18080.81880.81160.73810.43830.71060.61730.6165
Task Arithmetic–0.29090.84630.81880.78690.55910.75840.64620.6724
TIES-Merging–0.19510.84290.83330.83510.65010.73090.42600.6448
TSV-M–0.34770.87390.84460.82860.61630.81240.66060.7120
Iso-C–0.26390.86010.81300.82110.73030.78820.70400.7115
Iso-CTS–0.41360.77980.63850.65000.52770.65900.65340.6174
Training-FreeFisher Merging2560.11260.87190.74190.78080.42270.53110.51500.5680
RegMean2560.27970.89330.80690.79150.72510.83360.61610.7066
RegMean++2560.24330.91700.77400.80990.75430.82990.66910.7139
SLOA ($r{=}64$)2560.56080.92320.88140.81520.76780.87550.71000.7906
SLOA ($r{=}128$)2560.57210.92390.88100.81660.77530.88240.73410.7979

bold = best in column; underline = second best. SLOA is best on 6/7 tasks; +8.4 avg. pts over the strongest baseline at $r{=}128$.

Ablations

Component ablation (20 tasks)

Decoupling QK and OV ranks

Scaling with calibration & rank (ViT-B/32, 20 tasks)

Sensitivity to regularization $\alpha$

  • Sequential alignment alone is already strong.
  • QK and OV must be merged jointly — isolating one hurts.
  • Jointly expanding QK and OV ranks gives the best, most sustained gains.
  • Optimal $\alpha$ decreases as more calibration data is available.

Task-wise comparison: SLOA vs. data-free and training-free baselines

Radar plots: SLOA vs baselines

From left to right: ViT-B/32 on 20 vision tasks vs. data-free / vs. training-free baselines; RoBERTa on 7 GLUE tasks vs. data-free / vs. training-free baselines. SLOA ($r{=}128$) consistently outperforms both data-free and training-free baselines.

Conclusions & Limitations

Take-aways

  • Treat $\mathbf{W}_Q\mathbf{W}_K^{\!\top}$ and $\mathbf{W}_V\mathbf{W}_O$ as the units to merge — not the raw matrices.
  • Sequential, data-aware alignment removes parameterization ambiguity and curbs cross-layer error accumulation.
  • Rank expansion grows multi-task capacity without training.
  • Generalizes from CLIP and RoBERTa to LoRA-adapted LLaMA-2-7B experts (SLOA-VO: 49.19 avg. vs. 46.46 for RegMean++).

Limitations

  • Needs calibration data — more than purely data-free baselines require.
  • Higher offline merging cost: 182 s vs. 84–115 s for RegMean/RegMean++ on 20-task ViT-B/16 — strictly one-time, no backprop.
  • Rank expansion increases inference cost: per-head $O(L^2 r_j)$ when $r_j>d_k$; trade-off between capacity and latency.

Future work

  • Reduce calibration / merging cost and automatically select per-head ranks under deployment budgets.
  • Compose the QK operator under rotary position embeddings (currently VO-only for LLaMA).
  • Extend operator-level merging to encoder-decoder transformers.