Abstract
Model sparsity is a promising approach to reducing parameters or FLOPs of convolutional neural networks (CNNs). Compared to unstructured or coarse-grained structured sparsity, fine-grained structured sparsity, e.g., N:M sparse pattern, can achieve a better balance between accuracy and efficiency on general computing platforms like CPUs and GPUs. In particular, the 2:4 sparsity can accelerate CNN inference by 2$\times$ speed and with negligible accuracy drop. However, N:M sparsity needs to be supported by GPU within specific hardware circuits and hardly achieves significant speedups on common GPUs. To accelerate CNNs with general-purposed computing resources and simultaneously retain the model accuracy as much as possible, this paper proposes complementary sparsity (CS). CS denotes that only one weight can be retained for weights spaced at the same distance. On the one hand, CS features high mask flexibility, which is naturally favorable to high model accuracy. Moreover, we propose a CS-specific sparse training method to improve CS-based CNNs' accuracy under high parameter sparsities (>75%). On the other hand, CS itself is memory-access balanced and robust to pattern hyperparameters, which can be utilized to speedup CS-based convolution computation on CPUs and common GPUs. We thus propose a CS convolution parallel computing algorithm that adapts to common GPUs without sparse tensor cores. Experimental results show that compared to other sparsity patterns, the proposed CS can achieve the optimal trade-off in terms of accuracy and latency for CPUs and common GPUs, respectively. Codes are available at https://gitee.com/mindspore/models/tree/master/research/cv/CS.
Introduction
Deep learning models are often over-parameterized, containing many weights that can be pruned without significant accuracy loss. However, there has historically been a trade-off between accuracy and hardware efficiency. Unstructured sparsity maintains high accuracy but is difficult to accelerate on standard hardware due to chaotic memory access. Conversely, coarse-grained structured sparsity (like channel pruning) is hardware-friendly but often severely degrades model performance.
While fine-grained structured patterns like NVIDIA's 2:4 (N:M) sparsity offer a middle ground, they typically require specialized hardware (e.g., Ampere Tensor Cores) to see real-world speedups. Researchers from Huawei Noah’s Ark Lab have introduced Complementary Sparsity (CS) to address this, creating a pattern that is flexible enough for high accuracy but structured enough to accelerate inference on general-purpose CPUs and common GPUs.
Methodology: Complementary Sparsity
The core of the proposed method is the CS Pattern. In a vector of weights, CS dictates that only one weight can be retained for weights spaced at a specific distance ($M$). For example, in a 50% sparse vector, if the $i$-th weight is kept, the $(i+M)$-th weight must be pruned, and vice versa. This "complementary" logic ensures that non-zero weights are distributed predictably, making the pattern "memory-access balanced."
Training and Acceleration
The authors utilize a two-phase training strategy to maintain accuracy:
- Gradual Sparse Training: The model starts dense, and sparsity is increased linearly. Weights are periodically "reselected" to ensure the most important ones are preserved within the CS constraints.
- Retraining: Once the sparse mask is fixed, the model is fine-tuned to recover accuracy.
To achieve speedups on standard GPUs, a "weight reuse-based" algorithm was developed. By pre-loading related sub-blocks into the GPU's shared memory, the system can perform sparse convolutions using "implicit GEMM" (General Matrix Multiplication) without the overhead typically associated with sparse formats.
Key Results
The researchers evaluated CS on ImageNet-1k and CIFAR-100 across various architectures, including ResNet-50 and MobileNetv2.
- High Accuracy: On ImageNet, CS-based ResNet-50 achieved 76.37% accuracy at 50% sparsity, nearly matching the 77.3% dense baseline. Even at an extreme 93.75% sparsity, it reached 71.07% accuracy, outperforming N:M (1:16) sparsity.
- Significant Speedups: On a Tesla V100 (which lacks sparse tensor cores), CS achieved 2.59x to 3.07x speedups at high sparsity levels compared to optimized cuDNN dense libraries. On Intel Xeon Gold CPUs, individual layers saw speedups as high as 7.7x.
- Energy Efficiency: At 93.75% sparsity, ResNet-50 inference energy consumption dropped significantly, from 7.25J (at 50% sparsity) to 3.28J per inference.
Conclusion
Complementary Sparsity (CS) provides a robust alternative to hardware-locked sparsity patterns. By balancing mask flexibility with structured memory access, CS enables high-performance sparse inference on the general-purpose computing platforms most widely used today. Future work will focus on adapting these patterns for Transformer architectures and reducing the training overhead for large-scale models.
Summary updated