When we train two neural networks with the same architecture on the same data, they often end up in different parts of the "loss landscape." Even though they perform the same task, their internal weights are permuted differently—neuron #10 in Model A might do the same job as neuron #50 in Model B. To merge these models without destroying their performance, we must first align them, finding a permutation that maps one model's neurons onto the other's.
For simple architectures like CNNs, this is relatively straightforward. However, researchers like Moritz Imfeld and Sotiris Anagnostidis have found that standard alignment techniques fail when applied to Transformers. The reason lies in the Transformer's rigid structural dependencies: residual connections, layer normalization, and, most importantly, multi-head attention (MHA).
The Threat of Head Contamination
The fundamental challenge in Transformer merging is that the model is not a monolithic block of weights; it is a collection of specialized functional units. In MHA, the hidden dimension is split into several independent "heads," each attending to different patterns.
If you apply a naive permutation to a Transformer's weight matrix, you risk head contamination. As Filippo Rinaldi and Giacomo Capitani argue in their work on TransFusion, treating an attention layer as a flat matrix allows neurons from Head A to be mixed with neurons from Head B. This destroys the model’s internal logic, as the mathematical consistency required for the Query-Key-Value (QKV) interactions is broken. To preserve the model's function, the alignment must respect these logical boundaries.
Hierarchical Matching: Heads then Neurons
To solve this, a new consensus has emerged: alignment must be hierarchical. Instead of matching individual neurons across the entire layer, the process is split into two levels:
- Head Alignment: First, identify which attention head in Model A corresponds to which head in Model B. Yanan Li and Mengwei Xu in LoRASuite frame this as a bipartite matching problem, using the Hungarian algorithm to pair heads based on the similarity of their interaction matrices.
- Internal Alignment: Once heads are paired, permute the individual neurons or "channels" within those matched heads. Fabian Ritter-Gutierrez and Nancy F. Chen demonstrate that this preserves the functional integrity of the Transformer blocks, allowing for the merging of even disparate models like speech and music encoders.
This hierarchical approach ensures that the "group structure" of the architecture remains intact. This intuition is even applicable to pooling; Byungsoo Ko and Sanghyuk Chun showed that aligning pooling groups with the multi-head structure (GGeM pooling) reduces redundancy and improves spatial prioritization in Vision Transformers.
Finding the Shared Loss Basin
The ultimate goal of this alignment is Linear Mode Connectivity (LMC)—the idea that two independently trained models actually reside in the same "loss basin." If you can find the right permutation, you should be able to average the weights of two models and get a third model that performs just as well (or better) without any further training.
Alexander Theus and colleagues have shown that while simple permutations aren't enough for Transformers, accounting for higher-order symmetries—like those introduced by LayerNorm—allows for nearly lossless merging. Furthermore, Viet-Hoang Tran and Tan Minh Nguyen have proved that the type of positional encoding used (like RoPE) changes the model's "functional equivalence" and must be factored into the alignment algorithm to achieve LMC.
Dual-Space Constraints
While many methods focus purely on weights, Zhengqi Xu and Huiqiong Wang suggest that weight similarity alone is insufficient. Their framework, MuDSC, looks at both weight and activation spaces. By ensuring that the merged model produces similar internal activations to its parents, they overcome the performance barriers that occur when models are initialized differently.
Similarly, in the context of multi-task learning for video, Arushi Rai uses bipartite matching to ensure that different attention heads across different task pathways are attending to the same semantic information. This enforces consistency across the model's internal representations, proving that structural alignment is not just a tool for merging models, but a fundamental requirement for making Transformers more coherent and interpretable.