1xN Pattern for Pruning Convolutional Neural Networks

Mingbao Lin, Yuxin Zhang, Yuchao Li, Bohong Chen, Fei Chao, Mengdi Wang, Shen Li, Yonghong Tian, Rongrong Ji

TL;DR

The 1×N pruning pattern offers a "Goldilocks" solution for CNN compression, balancing the high accuracy of fine-grained weight pruning with the significant CPU speedups of coarse-grained filter pruning. By grouping consecutive kernels and utilizing a novel filter rearrangement workflow, the authors achieve up to 3% better accuracy than traditional filter pruning while delivering substantial inference speedups on general-purpose mobile CPUs.

What Problem Does This Paper Address?

Deep learning models, particularly Convolutional Neural Networks (CNNs), are notoriously resource-hungry. Pruning—removing redundant weights—is a standard way to slim them down. However, practitioners usually face a frustrating trade-off:

  1. Weight Pruning: Removes individual weights. It preserves accuracy beautifully but creates "irregular sparsity." General-purpose CPUs struggle with this because they can't easily skip individual zeros, leading to little or no actual speedup.
  2. Filter Pruning: Removes entire filters. This is very fast because it just results in a smaller, standard dense matrix. However, it’s a "blunt instrument" that often destroys model accuracy, especially at high compression rates.

Recent "N:M" pruning (like NVIDIA's 2:4) works well but is often locked to specific high-end GPU architectures (like the A100). This paper tackles the challenge of achieving practical speedups on general CPUs (like those in your smartphone) without sacrificing the accuracy that fine-grained pruning provides.

Methods

The authors introduce three main innovations to bridge the gap:

  • 1×N Pruning Pattern: Instead of pruning single weights or whole filters, they prune blocks of $N$ consecutive output kernels that share the same input channel index. This intermediate granularity is coarse enough for hardware to exploit but fine enough to preserve important features.
Comparison of weight, filter, and 1×N pruning scenarios.
  • Filter Rearrangement: To minimize accuracy loss, the authors propose a workflow that sorts filters based on their $\ell_1$ norm (magnitude) before pruning. By rearranging the weight matrix, they cluster high-magnitude (influential) kernels together, ensuring they aren't accidentally pruned away in a 1×N block. Crucially, they also rearrange the next layer's input channels to maintain mathematical consistency without adding any runtime overhead.
Workflow of filter rearrangement to preserve influential kernels.
  • Hardware-Efficient Encoding: The pruned weights are stored using the Block Compressed Sparse Row (BSR) format. This format is perfectly suited for the 1×N pattern, allowing the CPU to perform parallelized, block-wise vectorized operations. They use the TVM compiler and Ansor for automated code generation to ensure the implementation is highly optimized for specific hardware.
Encoding and decoding process using the BSR format for parallelized computation.

Datasets

The method was rigorously evaluated on the ILSVRC-2012 (ImageNet) dataset, which contains over 1.2 million training images across 1,000 classes. The authors tested their pattern on a variety of architectures:

  • Lightweight models: MobileNet-V1, MobileNet-V2, and MobileNet-V3 (Small & Large).
  • Standard heavyweights: ResNet-50.

Key Insights and Ideas

  • Continuity is Efficiency: The "secret sauce" for CPU speedup isn't just having zeros; it's having zeros in a predictable, continuous pattern. The 1×N requirement ensures that data can be fetched in chunks, utilizing memory buses and SIMD (Single Instruction Multiple Data) units effectively.
  • The Power of Sorting: Simply changing the order of filters before pruning (Rearrangement) significantly boosts accuracy. It’s a "free" optimization because the reordering is done offline before the model is deployed.
  • Granularity Matters: The paper demonstrates that 1×N is a flexible framework. As $N$ increases, the method behaves more like filter pruning; as $N$ decreases (to 1), it behaves like weight pruning. $N=4$ appears to be a sweet spot for many mobile CPUs.

Key Results

The 1×N pattern consistently outperformed filter pruning in accuracy and weight pruning in speed:

  • Accuracy: On MobileNet-V2 with a 50% pruning rate and $N=4$, the 1×N pattern achieved 69.706% top-1 accuracy, roughly 3.0% higher than filter pruning (66.730%).
  • Speedup: On a Cortex-A7 CPU, the 1×N pattern saved 56.04ms per inference compared to weight pruning, which achieved zero speedup.
  • High Sparsity Resilience: As shown in Figure 4, while filter pruning accuracy drops off a cliff at high sparsity rates, the 1×N pattern maintains a graceful degradation curve very similar to fine-grained weight pruning.
Accuracy vs. Pruning Rate for MobileNet-V2 and ResNet-50.

Limitations and Future Work

  • Pruning Criteria: The authors currently use the $\ell_1$ norm to determine importance. While effective, they acknowledge that more specialized criteria for the 1×N pattern might exist and are worth investigating.
  • RNN Support: While highly effective for CNNs, the authors observed fewer speedups when applying this pattern to Recurrent Neural Networks (RNNs). Generalizing the 1×N pattern to a wider variety of architectures is a key goal for future research.
  • Comparison with other Granularities: The paper notes that while other intermediate pruning granularities exist in theory, many lack practical, open-source CPU implementations for direct comparison. The authors have made their project available on GitHub to encourage further benchmarking.

Summary updated

BibTeX
@article{lin2023xn,
  author = {Mingbao Lin and Yuxin Zhang and Yuchao Li and Bohong Chen and Fei Chao and Mengdi Wang and Shen Li and Yonghong Tian and Rongrong Ji},
  title = {{1xN Pattern for Pruning Convolutional Neural Networks}},
  journal = {IEEE Trans. Pattern Anal. Mach. Intell.},
  year = {2023},
  url = {https://openreview.net/forum?id=TTZcFv4IHl},
}
Figure