techlist.io

Block Sparse

1 posts

OpenAI2017-12-053 min readCurated summary

Block-sparse GPU kernels

# Block-Sparse GPU Kernels for Neural Networks OpenAI releases highly optimized GPU kernels for neural networks whose weight matrices are block-sparse, meaning most blocks are exactly zero. Depending on the sparsity level, these kernels run orders of magnitude faster than cuBLAS or cuSPARSE, and the authors use them to reach state-of-the-art results in text sentiment analysis and in generative modeling of text and images. The post presents the kernels as a promising but not definitive foundation, and invites the community to explore the architectures they make practical. ## Why Sparse Weights Matter - Sparse weight matrices contain a large number of entries exactly equal to zero. - Matrix multiplication and convolution with block-sparse weights cost only in proportion to the number of non-zero blocks. - For a fixed parameter and compute budget, sparsity allows much wider and deeper networks, such as LSTMs with tens of thousands of hidden units, while the largest LSTMs trained at the time had only thousands. ## The Kernels - They support block-sparse weights in both fully connected and convolutional layers. - In convolutional layers, sparsity applies to input and output feature dimensions, while spatial connectivity is unchanged. - Sparsity is defined per block, with kernels optimized for 8x8, 16x16, and 32x32 blocks. The block-level pattern is fully configurable. - Skipped zero blocks mean compute and parameter storage scale with the number of non-zero weights rather than the number of input and output features. - Benchmarks on a Titan X Pascal GPU (CUDA 8), with 12288 hidden units, 32x32 blocks, and minibatch size 32, show speed-ups over cuBLAS at various sparsity levels. Speed-ups over cuSPARSE were even larger. ## Using the Kernels - The post includes a TensorFlow example that creates a random block-level sparsity pattern, builds a `BlocksparseMatMul` object with a chosen block size, initializes block-sparse weights from `bsmm.w_shape`, and runs the multiplication as a graph operation. ## Small-World LSTMs - Small-world graphs connect any two nodes through a small number of steps, even at very large scale, and brain connectivity shows similar properties. - The authors hypothesized that small-world sparse connectivity keeps information propagating quickly despite high sparsity. - Using this structure, they trained LSTMs with nearly 20,000 hidden units, about 5 times wider than a dense network with similar parameter counts, improving results on text generation and semi-supervised sentiment classification. ## Results - **Sentiment:** Using the setup from their sentiment neuron experiment, the sparse model beat the dense model on all sentiment datasets. On the document-level IMDB dataset, error dropped from 5.91% (Miyato et al., 2016) to 5.01%, a state-of-the-art result. Previous results had only performed best on shorter sentence-level datasets. - **Text compression:** With equal parameter counts (about 100 million), bits-per-character fell from 1.059 to 1.048 using sparse, wide LSTMs. - **Images:** Replacing regular 2D convolutions with sparse kernels in PixelCNN++ on CIFAR-10, while deepening the network and keeping other hyperparameters fixed, reduced bits-per-dimension from 2.92 to 2.90, a new state of the art on that dataset. ## Open Research Directions - **Inference speed-up:** How much wall-clock speed-up can pruning after training achieve when combined with these kernels? - **Learning sparsity structure:** Can gradients learn the sparsity pattern as well as the weights, similar to how biological brains partly determine connectivity during development? Related work includes learning block-sparse RNNs and L0 regularization. - **Application domains:** Sparse layers allow huge weight matrices at the same parameter count and compute cost as smaller dense models. Which domains will benefit most?