FSCNN: A Fast Sparse Convolution Neural Network Inference System

Bo Ji, Tianyi ChenarXiv 2022

Abstract

Convolution neural networks (CNNs) have achieved remarkable success, but typically accompany high computation cost and numerous redundant weight parameters. To reduce the FLOPs, structure pruning is a popular approach to remove the entire hidden structures via introducing coarse-grained sparsity. Meanwhile, plentiful pruning works leverage fine-grained sparsity instead (sparsity are randomly distributed), whereas their sparse models lack special designed computing library for potential speedup. In this technical report, we study and present an efficient convolution neural network inference system to accelerate its forward pass by utilizing the fine-grained sparsity of compressed CNNs. Our developed FSCNN is established based on a set of specialized designed sparse data structures, operators and associated algorithms. Experimentally, we validate that FSCNN outperforms standard deep learning library PyTorch on popular CNN architectures such as VGG16 if sufficiently high sparsity exhibits. However, due to the contiguity issue of sparse operators, FSCNN is typically not comparable with highly optimized dense operator. Therefore, coarse-grained (structured) sparsity is our recommendation for generic model compression.

1. Introduction

While Convolutional Neural Networks (CNNs) are powerful, they are computationally heavy and often contain many redundant parameters. Pruning is a common technique to remove these redundancies. There are two main types: structured pruning (removing entire rows or channels), which is hardware-friendly but can hurt accuracy, and fine-grained pruning (removing individual weights), which preserves accuracy better but creates irregular, "holey" matrices.

Standard deep learning libraries like PyTorch and TensorFlow are highly optimized for dense matrix math. When they encounter fine-grained sparsity, they often cannot skip the "multiplication by zero" efficiently because the overhead of tracking zero locations outweighs the computational savings. FSCNN (Fast Sparse CNN) addresses this gap by providing a system specifically engineered to turn fine-grained sparsity into wall-clock speedups on standard CPUs.

2. Methodology

FSCNN is built from the ground up with several novel components designed to exploit fine-grained sparsity.

2.1 Extended Sparse Data Structures

Instead of the common Compressed Sparse Row (CSR) format, which can suffer from memory contiguity issues, FSCNN uses a "node-based" structure. This structure is extended to handle the 3D and 4D tensors typical in computer vision tasks.

Mapping of a 3D tensor to the FSCNN sparse data structure.

2.2 Sparsity Variants and Operators

The system supports two primary variants of sparse convolution:

  • Sparse Filter CNN (SF-CNN): Optimized for scenarios where model weights are sparse but inputs remain dense.
  • Sparse Input CNN (SI-CNN): Optimized for sparse input data, such as medical imaging or handwritten text.
Comparison of dense convolution, SF-CNN (sparse filters), and SI-CNN (sparse inputs).

The core engine relies on sparse-vector-dense-vector inner products, allowing the system to skip calculations for any zero-valued weight or input element.

2.3 System Optimizations

  • Operator Fusion: To minimize memory overhead, FSCNN fuses pooling and activation layers directly into the convolution operation.
  • Parallelism: The system utilizes OpenMP for multi-core CPU parallelism.

3. Experimental Evaluation

The system was evaluated using VGG16 and YOLO architectures. The focus was on inference runtime across varying levels of density (1% to 100% non-zero elements). Testing was conducted on an Intel Xeon Platinum 8163 CPU.

4. Discussion and Key Insights

  • The 5% Density Threshold: Sparse operators typically only outperform highly optimized dense operators when density is extremely low (below 5%). Above this threshold, the memory contiguity of dense data makes it faster due to better cache utilization and branch prediction.
  • Sparsity Decay: In SI-CNN, convolution operations act as a "blur," reducing sparsity in deeper layers. Consequently, the performance advantage often diminishes as data flows through the network.
  • ReLU and Fusion: The ReLU activation function helps maintain sparsity by zeroing out negative values. Furthermore, fusing convolution with pooling is mandatory for performance, as locating pooling regions in sparse formats is otherwise prohibitively slow.

5. Results

  • SF-CNN Performance: At 99% sparsity (1% density), FSCNN achieved a 1.5x to 3x speedup over PyTorch in single-process execution.
  • Batching Gains: For highly sparse models (>95%), FSCNN demonstrated approximately 6x speedups over PyTorch for both VGG16 and YOLO.
  • SI-CNN Limitations: The Sparse Input variant struggled to maintain advantages in deep networks due to sparsity decay, making it more suitable for shallow networks or specific domains.

6. Conclusion

FSCNN demonstrates that fine-grained sparsity can be leveraged for significant speedups, particularly in extremely compressed models. However, due to the overhead of managing sparse pointers and the "contiguity issue," structured (coarse-grained) sparsity remains the recommendation for general-purpose model compression. Future work may explore shallow sparse networks or GPU-based sparse structures.

Summary updated

BibTeX
@misc{ji2022fscnn,
  author = {Bo Ji and Tianyi Chen},
  title = {{FSCNN: A Fast Sparse Convolution Neural Network Inference System}},
  year = {2022},
  eprint = {2212.08815},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2212.08815},
}
Figure