Merging Feed-Forward Sublayers for Compressed Transformers

Neha Verma, Kenton Murray, Kevin Duh · DOI

Abstract

As Transformer-based models continue to scale, efficient deployment on consumer-grade hardware remains a significant challenge. Traditional compression techniques like pruning often discard "unimportant" parameters, potentially losing valuable information. This paper proposes a novel alternative: merging redundant feed-forward (FF) sublayers. By aligning and averaging adjacent FF layers, we reduce parameter counts by over 20% while maintaining up to 99% of original performance. Our method consistently outperforms traditional layer-pruning baselines across vision, language, and translation tasks.

Introduction

The rapid growth of Large Language Models (LLMs) and Vision Transformers (ViTs) has made them increasingly difficult to deploy. Current compression strategies—pruning, quantization, and distillation—each have trade-offs. Pruning, in particular, focuses on removing weights with low magnitude, but it often ignores the inherent redundancy between layers. Previous research suggests that different layers within a Transformer often perform remarkably similar computations. This study explores whether these redundant layers can be merged into a single, shared representation rather than simply being deleted.

Methodology

The proposed compression pipeline focuses on Feed-Forward (FF) sublayers, which typically constitute two-thirds of a Transformer's non-embedding parameters. The process involves several critical steps to ensure the merged weights retain the functionality of the original layers.

The three-stage process of merging FF sublayers: applying transformations for alignment, merging parameters, and tying weights.

Neuron Alignment and Merging

Averaging weight matrices directly is ineffective because hidden neurons may be ordered differently across layers. To address this, the authors employ permutation-based alignment. By passing exemplar data through the model and computing cross-correlations of activations, they identify the optimal reordering (permutation) to align neurons in one layer to another using the Jonker-Volgenant algorithm. Once aligned, the weights ($W^{in}$ and $W^{out}$) and biases are averaged and replaced with a single set of "tied" (shared) weights.

Selection and Recovery

To identify the most "mergeable" candidates, a sliding window approach is used to test blocks of $k$ adjacent layers on a validation set. Following the merge, a brief recovery fine-tuning stage is performed. This allows the newly shared weights to adapt to their dual role, significantly "healing" any initial performance drops.

Experimental Results

The method was evaluated across diverse architectures: GPT-2 Large (Language), ViT (Vision), OPUS-MT (Translation), and OLMo-7B (Summarization).

Performance metrics across different modalities showing that Permute FF Merge significantly outperforms Vanilla merging as parameter reduction increases.

Key Performance Metrics

  • Vision Transformers (ViT): Merging one-third of the FF layers removed 21% of total parameters while maintaining 99% of the original ImageNet-1k accuracy.
  • Language Modeling (GPT-2): A similar reduction resulted in only a minor increase in perplexity on Wikitext-103 (from 16.16 to 17.27).
  • Machine Translation (OPUS-MT): The approach maintained competitive BLEU scores even at high compression ratios.

In all cases, the merging approach matched or exceeded the performance of strong layer-dropping (pruning) baselines at equivalent parameter reduction levels.

Discussion and Insights

The study revealed that FF sublayers exhibit much higher activation similarity (measured via Centered Kernel Alignment) than attention sublayers, making them the ideal target for merging. Furthermore, the alignment step is crucial; "vanilla" merging without permutation performs significantly worse as the compression ratio increases.

The method is also orthogonal to other compression techniques. For instance, combining FF merging with 8-bit quantization allowed a ViT model to be stored in just 20% of its original size with minimal impact on accuracy. Interestingly, while the initial choice of layers to merge is important, the recovery fine-tuning stage makes the final model performance remarkably robust to the specific layers selected.

Conclusion and Future Work

Merging redundant FF sublayers provides a powerful new tool for Transformer compression. While it effectively reduces memory and disk footprints, current standard hardware does not automatically translate these savings into inference speedups. Future work involves developing specialized kernels to exploit shared memory access for "wall-clock" acceleration. Additionally, exploring the "mergeability" of other architectures like Mamba or CNNs remains an open area for research.

Summary updated

BibTeX
@misc{verma2025merging,
  author = {Neha Verma and Kenton Murray and Kevin Duh},
  title = {{Merging Feed-Forward Sublayers for Compressed Transformers}},
  year = {2025},
  eprint = {2501.06126},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.06126},
}
Figure