TL;DR
LayerMerge is a novel depth compression technique that accelerates convolutional neural networks (CNNs) by jointly pruning activation functions and convolution layers. By strategically replacing specific convolution layers with identity mappings before merging them, LayerMerge overcomes the "kernel bloat" problem that severely limits the speed gains of traditional depth compression methods.
The "Kernel Bloat" Problem in Depth Compression
In the quest for efficient AI on edge devices, researchers often employ "depth compression." This technique involves removing non-linear activation functions (like ReLU) between consecutive convolution layers so they can be mathematically collapsed into a single, equivalent layer. While this reduces the overall depth of the network, it introduces a hidden and significant cost: kernel expansion.
Mathematically, merging two $3\times3$ convolution layers results in a single layer with a $5\times5$ kernel. If you merge three, you get a $7\times7$ kernel. These larger kernels are computationally heavier. As more layers are merged, the computational overhead of the expanded kernel quickly eats up the latency savings gained from having fewer layers.
This "bloat" is especially problematic in mobile-optimized architectures like MobileNet, where the overhead of a larger kernel can actually make the "compressed" model slower than the original.
The LayerMerge Approach
To combat kernel bloat, the authors introduce LayerMerge, which treats depth compression as a joint optimization problem. Instead of only deciding which activations to remove, LayerMerge simultaneously decides which convolution layers to "prune" by replacing them with an identity function (effectively a $1\times1$ convolution with fixed weights).
The key technical contributions include:
- Joint Selection: The method optimizes two sets of indices—one for activation layers and one for convolution layers. Replacing a convolution with an identity mapping prevents it from contributing to the growth of the merged kernel size.
- Surrogate Optimization: Searching every possible combination of layers to prune is an exponential (NP-hard) problem. To resolve this, the authors formulate a surrogate objective, assigning an "importance" value to each potential merged block based on its impact on overall model performance.
- Dynamic Programming (DP): They solve this optimization problem efficiently using a DP algorithm. This allows the system to find the mathematically optimal set of layers to prune and merge to meet a specific hardware latency budget (e.g., "make this model 40% faster") in just a few seconds on a standard CPU.
Key Insights: The Identity Trick
The most elegant insight of LayerMerge is that replacing a convolution with an identity mapping acts as a "reset button" for kernel growth. Because an identity mapping is essentially a $1\times1$ kernel, it does not expand the receptive field of the layers it is merged with. This keeps the final merged kernel small and fast.
Furthermore, the paper demonstrates that optimizing activations and convolutions separately is sub-optimal. Doing them together allows the DP solver to find "sweet spots" where a slightly larger kernel is acceptable because a particularly redundant activation was removed nearby. Unlike many pruning methods that use FLOPs as a proxy for speed, LayerMerge uses actual latency measurements on target hardware (like an RTX 2080 Ti) to build its optimization tables, ensuring theoretical gains translate to real-world performance.
Experimental Results
The researchers evaluated LayerMerge across image classification (ImageNet on ResNet-34 and MobileNetV2) and image generation (CIFAR10 on a DDPM). It consistently outperformed existing baselines in the accuracy-vs-latency trade-off:
- MobileNetV2-1.0: Achieved a 1.63× speedup in PyTorch with 72.99% accuracy, slightly improving on the original model's 72.89% after fine-tuning. Previous methods lost significant accuracy at similar speedups.
- ResNet-34: Achieved a 1.10× speedup with 0.77% higher accuracy than the leading depth compression baseline.
- Diffusion Models (DDPM): Achieved a 1.13× speedup with a lower (better) FID score (4.16) compared to the original model (4.18), proving the method works even for complex generative tasks where maintaining structural integrity is difficult.
Limitations and Future Work
While highly effective for CNNs, the current formulation is architecture-specific. The paper does not discuss how this might adapt to Transformer-based architectures (like ViTs or LLMs), which rely on different types of linear layers and non-linearities. Additionally, like most pruning methods, LayerMerge requires a fine-tuning phase to recover accuracy after layers are merged. Finally, the authors note that pruning can sometimes disproportionately affect performance on specific data sub-groups, highlighting a common challenge in model compression that warrants further study.
Summary updated