Sliding-Window Merging for Compacting Patch-Redundant Layers in LLMs

Xuan Ding, Rui Sun, Yunjian Zhang, Xiu Yan, Yueqi Zhou, Kaihao Huang, Suzhong Fu, Angelica I. Avilés-Rivero, Chuanlong Xie, Yao Zhu

TL;DR

Large Language Models (LLMs) often contain "patches" of consecutive layers that perform nearly identical functions. This paper introduces Sliding-Window Merging (SWM), a technique that identifies these redundant blocks and merges them into single layers through parameter consolidation, significantly reducing model depth and speeding up inference while preserving much higher accuracy than traditional layer-deletion methods.

What Problem Does This Paper Address?

As LLMs grow in scale, deploying them in resource-constrained environments becomes a massive challenge. Researchers typically turn to pruning to shrink these models.

  • Width-wise pruning (removing attention heads or neurons) reduces memory but often fails to solve computational bottlenecks related to the sequence length (temporal dimension).
  • Depth-wise pruning (removing entire layers) is much more effective at speeding up inference, but it usually involves simply deleting layers. This "hard cut" often disrupts the flow of information through the network, leading to significant drops in accuracy that are hard to recover even with retraining.

The authors set out to find a more "surgical" way to reduce model depth by first understanding the functional relationships between layers.

Methods

The researchers propose a two-part approach: discovery and compression.

  1. Discovery via CKA: They use Centered Kernel Alignment (CKA) to measure the similarity between the outputs of different layers. Their analysis revealed a "patch-like" redundancy: large blocks of consecutive intermediate layers produce highly correlated representations.
  2. Sliding-Window Merging (SWM): Instead of deleting these redundant layers, SWM merges them.
  3. The Algorithm: Starting from the deepest layers and moving toward the shallow ones, a sliding window identifies groups of layers with high similarity (based on a predefined threshold).
  4. Parameter Consolidation: For a group of redundant layers, they designate one as a "base layer" and incorporate the parameter differences (the "deltas") of the other layers into it. This ensures that the unique information in the redundant layers is consolidated rather than discarded.
  5. Adaptive Thresholding: The method dynamically adjusts the window size by comparing the cosine similarity of the compressed model's output against the original model using a few calibration samples.

Finally, they use LoRA (Low-Rank Adaptation) to fine-tune the compressed model, helping it recover any lost performance with minimal data.

Datasets

  • Calibration: A small subset (10 samples) from BookCorpus was used to calculate similarities during the pruning process.
  • Evaluation: The models were tested on seven common-sense reasoning benchmarks: BoolQ, PIQA, HellaSwag, WinoGrande, ARC-easy, ARC-challenge, and OpenbookQA.
  • Retraining: For the recovery phase, they used 50,000 samples from the Refined Alpaca dataset for instruction tuning.

Key Insights and Ideas

  • The "Patch-Redundancy" Phenomenon: LLMs aren't just redundant in a general sense; they exhibit a specific structure where intermediate layers often perform incremental refinements. Because of the residual connections ($x_{l+1} = x_l + F(x_l)$), if the layer's transformation $F$ is small, the layers become functionally almost identical.
  • Merging > Deleting: The core "aha moment" is that parameter consolidation preserves "knowledge integrity." By adding the differences between layers back into a base layer, the model retains the cumulative effect of the redundant block.
  • Boundary Layers are Sacred: The CKA analysis showed that the very first and very last layers of the model have low similarity to others. These "boundary layers" are task-critical and are excluded from merging to prevent irreversible performance damage.
  • Synergy with Width Pruning: The authors found that depth-wise merging and width-wise pruning are complementary. Combining them allows for more aggressive compression than using either method alone.

Key Results

  • Superior Accuracy: On the Vicuna-7B model with a 35% pruning rate, SWM outperformed the popular LLM-Pruner by 1.654% in average zero-shot task performance.
  • Inference Speedup: Depth pruning via SWM significantly improved throughput. For LLaMA2-7B at 35% pruning, SWM achieved a throughput of 67.77 tokens/s compared to the original model's 46.90 tokens/s.
  • Efficiency: Unlike width-wise pruning, which can actually increase latency in some hardware configurations due to irregular memory access, SWM's depth reduction provides a clean, linear speedup in inference time.
  • Robustness: The method proved robust across different architectures (LLaMA2, LLaMA3, Vicuna) and scales (7B and 13B parameters).

Limitations and Future Work

  • Threshold Sensitivity: The performance of SWM depends on choosing the right similarity threshold. While the authors use a grid search to optimize this, a more automated, per-layer adaptive thresholding could be more efficient.
  • Retraining Requirement: While SWM performs well "zero-shot" (without retraining), the best results still require a LoRA recovery phase, which adds computational overhead.
  • Future Direction: The authors suggest that future research should focus on a more unified framework that automatically balances width and depth pruning based on specific hardware constraints.

Summary updated

BibTeX
@inproceedings{ding2026sliding,
  author = {Xuan Ding and Rui Sun and Yunjian Zhang and Xiu Yan and Yueqi Zhou and Kaihao Huang and Suzhong Fu and Angelica I. Avilés-Rivero and Chuanlong Xie and Yao Zhu},
  title = {{Sliding-Window Merging for Compacting Patch-Redundant Layers in LLMs}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i25.39222},
}
Figure