报道正文
本文目录9 个章节
- 研究
- 产品
- 企业
- 开发者
- 公司
- 基金会(在新窗口中打开)
- 研究
- 产品
- 企业
- 开发者
- 公司
- 基金会(在新窗口中打开)
OpenAI
2017年12月6日
块稀疏 GPU 内核

插图:Ben Barry
加载中…
分享
内核
我们发布了针对一类尚未被充分探索的神经网络架构——具有块稀疏权重的网络——的高度优化 GPU 内核。根据所选的稀疏度,这些内核的运行速度可比 cuBLAS 或 cuSPARSE 快数个数量级。我们已利用它们实现了文本情感分析和文本及图像生成建模领域的最先进(state-of-the-art)结果。
深度学习领域中模型架构和算法的发展,在很大程度上受限于基础操作高效 GPU 实现的可用性。其中一个长期存在的问题是缺乏高效的稀疏线性运算 GPU 实现,我们现在正发布这一实现,并附带了使用它来实现多种稀疏模式的初步结果。这些初步结果令人鼓舞但尚非定论,我们邀请社区加入我们,共同推动这些内核所解锁的架构极限。

与稠密权重矩阵相比,稀疏权重矩阵包含大量值恰好为零的元素。稀疏权重矩阵作为模型的构建模块极具吸引力,因为与稀疏块进行矩阵乘法和卷积的计算成本仅与非零块的数量成正比。例如,稀疏性使得训练比在给定参数预算和计算预算下原本可能达到的更宽且更深的神经网络成为可能,比如拥有数万个隐藏单元的 LSTM。(目前训练的最大规模 LSTM 仅有数千个隐藏单元。)
内核

这些内核支持在全连接层和卷积层中高效使用块稀疏权重(如上图所示)。对于卷积层,内核允许在输入和输出特征维度上实现稀疏性;而在空间维度上,连通性不受影响。稀疏性是在块级别定义的(如右图所示),并针对 8x8(如本例所示)、16x16 或 32x32 的块大小进行了优化。在块级别,稀疏模式是完全可配置的。由于内核会跳过零值块的计算,因此计算成本仅与非零权重的数量成正比,而与输入/输出特征的数量无关。参数存储的成本也仅与非零权重的数量成正比。

在不同稀疏度水平下,与 cuBLAS 相比的加速因子。测试配置为:宽状态(12288 个隐藏单元)、32x32 的块大小以及 32 的小批量大小。比较是在配备 CUDA 8 的 NVIDIA Titan X Pascal GPU 上进行的。在测试的稀疏度水平下,与 cuSPARSE 相比的加速效果甚至更为显著。
使用内核
下面展示了一些在 Tensorflow 中执行稀疏矩阵乘法的示例代码。
Python
1from blocksparse.matmul import BlocksparseMatMul2import tensorflow as tf3import numpy as np45hidden_size = 40966block_size = 327minibatch_size = 6489# Create a (random) sparsity pattern10sparsity = np.random.randint(2, size=(hidden_size//block_size,hidden_size//block_size))1112# Initialize the sparse matrix multiplication object13bsmm = BlocksparseMatMul(sparsity, block_size=block_size)1415# Input to graph16x = tf.placeholder(tf.float32, shape=[None, hidden_size])1718# Initialize block-sparse weights19w = tf.get_variable("w", bsmm.w_shape, dtype=tf.float32)2021# Block-sparse matrix multiplication22y = bsmm(x, w)2324# Run25sess = tf.InteractiveSession()26sess.run(tf.global_variables_initializer())27result = sess.run([y], feed_dict = {x: np.ones((minibatch_size,hidden_size), dtype='float32')})28print(result)
小世界 LSTM
块稀疏核的一个特别有趣的用途,是利用它们来构建小世界神经网络。小世界图(在新窗口中打开)的连通方式使得图中任意两个节点之间仅通过少量步骤即可相连,即使该图包含数十亿个节点也是如此。我们实现小世界连通性的动机在于:尽管网络具有高度的稀疏性,我们仍希望信息能够快速在网络中传播。大脑展现出小世界连通模式(在新窗口中打开),这促使我们思考同样的特性是否能提升 LSTM 的性能。利用小世界稀疏连接,我们高效地训练了拥有近两万个隐藏单元的 LSTM,其宽度是参数量相当的稠密网络的 5 倍,并在文本生成建模和半监督情感分类任务上取得了更好的结果;更多细节请参阅我们的论文(在新窗口中打开)。

情感表示学习
遵循我们在情感神经元实验中使用的设置,我们训练了参数量大致相当的 LSTM,并将使用稠密权重矩阵的模型与块稀疏变体进行了比较。在所有情感数据集上,稀疏模型均优于稠密模型。我们的稀疏模型将文档级 IMDB 数据集上的最先进(state-of-the-art)错误率从 5.91% (Miyato et al, 2016(在新窗口中打开)) 降低至 5.01%。相较于我们之前的结果——那些结果仅在较短的句子级数据集上表现最佳——这是一项令人鼓舞的提升。

压缩结果
[注:本文篇幅超长,以上为核心前篇精译,后续内容保留原文呈现]
By using sparse and wide LSTMs, the bits-per-character results in our experiments dropped from 1.059 to 1.048, for equal parameter counts (~ 100 million). Architectures with block-sparse linear layers can also improve upon results obtained with densely connected linear layers. We performed a simple modification of thePixelCNN++(opens in a new window)model of CIFAR-10 natural images. A replacement of regular 2D convolutional kernels with sparse kernels, while deepening the network but keeping the rest of the hyper-parameters fixed, lead to a drop in the bits-per-dimension from 2.92 to 2.90, now state of the art on this dataset.
Research directions
Here we list some suggestions for future research.
-
Most weights in neural networkscan be pruned after training has finished(opens in a new window). How much wall-clock time speed-up is possible at inference time when using pruning together with these kernels?
-
In biological brains, the sparse structure of the network ispartially determined during development(opens in a new window), in addition to connection strengths. Can we do something similar in artificial neural networks, where we use gradients to not only learn the connection weights, but also the optimal sparsity structure? A recent paper proposed a method for learningblock-sparse RNNs(opens in a new window), and we recently proposed an algorithm forL0 regularization in neural networks(opens in a new window), which can be used towards this end.
-
We trainedLSTMs with tens of thousands of hidden units, leading to better models of text. More generally, sparse layers make it possible to train models with huge weight matrices but the same number of parameters and the same computational cost as their smaller dense counterparts. What are application domains where this will make the most difference to performance?
Authors
Scott Gray, Alec Radford, Durk Kingma
Acknowledgments
Cover Artwork: Ben Barry