前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >我们真的需要模型压缩吗?

我们真的需要模型压缩吗?

作者头像
McGL
发布2020-11-10 11:04:05
1.2K0
发布2020-11-10 11:04:05
举报
文章被收录于专栏:PyVision

模型压缩是边缘设备部署的常用技术。可是为什么要压缩模型呢?模型可压缩说明参数过量,那为什么不从头开始训练一个合适参数量的模型呢?以及我们可以通过使用更聪明的优化方法来直接减少参数吗?请看下面分解。

作者:Mitchell A. Gordon 编译:McGL

模型压缩是一种缩小训练好的神经网络的技术。压缩后模型的执行方式通常与原始模型相似,只使用了一小部分计算资源。然而,在很多应用中的瓶颈是训练压缩之前的原来的大型神经网络。例如,BERT-base 可以在消费级 GPU (12 GB 内存)上进行训练,但 BERT-large 需要在谷歌 TPU (64 GB 内存)上进行训练,这样就劝退了很多希望在预训练模型做试验的人。[1]

模型压缩领域的结果告诉我们,我们收敛到的解通常比我们原来训练的模型参数少得多。

那么,是什么阻止了我们通过从头开始(from scratch)训练小型模型来节省 GPU 内存呢? 在这篇文章中,我们将探索从头开始训练小模型所遇到的障碍。并讨论为什么模型压缩可行,以及两种高效内存训练方法: 过参数化边界和更好的优化方法,这些方法可以减少或消除事后模型压缩的需要。我们还将总结未来的研究方向。

合适参数化(Appropriately-Parameterized)模型

合适参数化模型——一个既不过参数化也不欠参数化的模型,它有恰当数量的参数来表达任务的理想解。 我们通常不在深度学习中训练适当参数化模型。这是因为对于给定的数据集,通常不知道适当的参数数量。即使解已知,使用梯度下降来训练适当参数化模型也是出了名的困难 [2]

相反,训练过程通常是这样的:

  1. 训练一个过参数化模型。这些模型的参数通常比训练样本的数量更多。
  2. 各种正则化技术(隐式或其它) [3] 被用来约束优化倾向于“简单的解”而不是过拟合。
  3. 模型压缩通过消除冗余提取嵌在较大模型中的“简单”模型,使内存和时间效率更接近于理想的适当参数化模型。

极端的过参数化使得训练更加容易。然而,由于模型过参数化,它们记住数据 [4],而不是学习数据中的有用模式,这就需要正则化。然后,模型压缩利用这种简单性,只保留解决方案实际需要的参数。 由于我们的目标是训练使用较少 GPU 内存的神经网络,我们可以问一些显而易见的问题:

  • 为什么需要过参数化? 需要多少过参数化?
  • 我们可以通过使用更聪明的优化方法来减少过参数化吗?

接下来的两节将依次讨论这些问题。

过参数化边界

为什么需要过参数化?通过充分过参数化我们的神经网络,我们使优化曲面(landscape)有效凸(convex)。Du 等人(2019) [5] 以及 Haeffele 和 Vidal (2017) [6] 对一些简单的情况用数学方法证明了这一点,给出了在多项式时间内实现0训练损失所需的过参数化量。 实际上,过参数化正在用更多的内存使用来交换计算的难处理性。 这些边界通常被认为是松散的。这意味着,尽管我们可以预测足够数量的参数来完全拟合某些数据,但我们仍然不知道完全拟合数据所需的最小参数数量。严格的边界可能取决于从优化过程(SGD vs. GD,Adam vs. Others)到结构的所有。计算一个紧界甚至可能比训练所有可能的候选网络更加棘手。 但是在这个领域仍然有改进的空间。[7] 更严格的过参数化边界可以让我们训练更小的网络,而不需要在结构上进行网格搜索,也不用担心更大的网络可能会给我们带来更好的性能。扩展到recurrent模型,transformers,batch norm训练的模型等的证明也仍然存在问题。

更好的优化技术

根据经验,适当的参数化模型很难训练。训练一个用梯度下降的大小合适的模特通常会以悲惨的失败告终。这个模型不会收敛到适合训练数据,更不用说良好的泛化了。这在一定程度上可以用神经网络的优化曲面的非凸 / 非友好性来解释,但是对于训练适当参数化模型的计算复杂性的精确特性描述仍然是不完整的 [8] 模型压缩技术通过阐明过参数化模型倾向于收敛的解的类型给了我们一个关于如何训练适当的参数化模型的提示。模型压缩有很多种类型,每一种都利用了训练好的神经网络中常见的不同类型的“简单性” :

  • 很多权重接近于零(剪枝)
  • 权重矩阵是低秩(权重因子分解)
  • 权重可以仅用几位表示(量化)
  • 层通常学习相似的功能(权重共享)

这些“简单性”中的每一个都是由训练期间(隐式或其它)的正则化或训练数据的质量所诱导出来的。当我们知道我们正在寻找具有这些属性的解时,它为改进我们的优化技术开辟了令人兴奋的新方向。

从头开始(from Scratch)的稀疏网络

权重剪枝可能是压缩方法转化为优化改进的最成功的例子。训练好的神经网络具有很多值接近于0的的权重(30-95%) 。这些权重可以去除而不影响神经网络的输出。

我们是否可以通过从一开始就训练稀疏神经网络来减少 GPU 的使用,而不是在事后剪枝?有一阵子,我们以为答案是否定的。稀疏网络是很难训练的,优化曲面是非常非凸和不友好的。 然而,Frankel and Carbin (2018) [9] 朝这个方向迈出了第一步。他们发现,他们可以从头开始重新训练修剪过的网络,但前提是网络必须重新初始化为稠密训练期间使用的相同初始化。他们对此的解释是彩票假说(Lottery Ticket Hypothesis): 稠密网络实际上是很多适当参数化的并行稀疏模型的随机初始化组合。可以碰巧找到一个幸运的初始化并收敛到解。[10]

基于动态稀疏重参数化的深度卷积神经网络参数有效训练

最近,detmers 和 Zettlemoyer (2019) [11] ,Mostafa 等人(2019) [12] ,和 Evci 等人(2019) [13] 的研究表明,合适参数化的稀疏网络可以从头开始训练,大大减少了训练神经网络所需的 GPU 内存量。重要的不是初始化,而是探索模型稀疏子空间的能力。Lee 等人的类似工作(2018) [14] 试图通过对数据进行一次pass来快速找到合适的稀疏结构。 我相信这种模式可能会在其它类型的模型压缩中重复出现。更普遍的情况是:

  1. 压缩方法揭示了训练好的神经网络中常见的冗余现象
  2. 研究产生这种冗余的inductive biases / 正则化 [15]
  3. 创造一个聪明的优化算法以训练一个从开始就没有这种冗余的网络

下面是一个表格,其中列出了其它类型的模型压缩,以及为了让它们更接近训练的开始所做的努力 [16] (成功的程度各不相同) [17]:

未来方向

我们真的需要模型压缩吗?这篇文章的标题有些挑衅,但这个idea并不是: 通过收紧过度参数化的边界和改进我们的优化方法,我们可以减少或消除事后模型压缩的需要。显然,在我们得到一个明确的答案之前,还有很多悬而未决的问题需要回答。下面是一些我希望在未来几年内完成的工作。 过参数化

  • 通过观察数据的质量(使用低计算资源) ,我们能够得到更严格的边界吗?
  • 如果我们使用一个聪明的优化技巧(比如Rigged Lottery [13]) ,过参数化边界是如何改变的?
  • 强化学习环境是否可以得到超参数化边界?
  • 我们可以将这些边界扩展到其它常用的架构(RNNs,Transformers)吗?

优化

  • 在训练过的神经网络中还有其它我们没有利用的冗余吗?
  • 让这些变得可行:
  • 从头开始训练量化神经网络
  • 基于低秩矩阵的神经网络从头训练
  • 弄清楚为什么知识蒸馏可以改进优化。如果可能的话,在使用较少的 GPU 内存的同时使用类似的想法进行优化

正则化

  • 什么类型的正则化会导致什么类型的模型冗余(有分类会很好)
  • 剪枝和再训练如何与 L0规范化相关?什么样的隐式正则化导致了可修剪性?
  • 什么类型的正则化会导致可量化性?

参考:

  1. Much more on Deep Learning’s Size Problem. ↩
  2. A common example of this is XOR which can theoretically be represented with two hidden neurons but in practice requires using around twenty. ↩
  3. Kukačka, Jan, Vladimir Golkov, and Daniel Cremers. 2017. “Regularization for Deep Learning: A Taxonomy.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1710.10686. ↩ ↩2 ↩3
  4. Zhang, Chiyuan, Samy Bengio, Moritz Hardt, Benjamin Recht, and Oriol Vinyals. 2016. “Understanding Deep Learning Requires Rethinking Generalization.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1611.03530. ↩
  5. Du, Simon S., Jason D. Lee, Haochuan Li, Liwei Wang, and Xiyu Zhai. 2018. “Gradient Descent Finds Global Minima of Deep Neural Networks.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1811.03804. ↩
  6. Haeffele, Benjamin D., and René Vidal. 2017. “Global Optimality in Neural Network Training.” In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 7331–39. ↩
  7. And it’s very active. I’ve seen a bunch of papers (that I haven’t read) improving on these types of bounds. ↩
  8. Theoretically, though, we at least know that training a 3 neuron neural network is NP-hard. There are similar negative results for other specific tasks and architectures. There might be proof that over-parameterization is necessary and sufficient for successful training. You might be interested in this similar, foundational work. ↩
  9. Frankle, Jonathan, Gintare Karolina Dziugaite, Daniel M. Roy, and Michael Carbin. 2019. “Linear Mode Connectivity and the Lottery Ticket Hypothesis.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1912.05671. ↩
  10. Zhou (2019) explores this idea with more detailed experiments. Liu et al. (2018) found similar results for structured pruning (convolution channels, etc.) instead of weight pruning. They, however, could randomly initialize the structure pruned networks and train them just as well as the un-pruned networks. The difference between these results remains un-explained. ↩
  11. Dettmers, Tim, and Luke Zettlemoyer. 2019. “Sparse Networks from Scratch: Faster Training without Losing Performance.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1907.04840. ↩
  12. Mostafa, Hesham, and Xin Wang. 2019. “Parameter Efficient Training of Deep Convolutional Neural Networks by Dynamic Sparse Reparameterization.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1902.05967. ↩
  13. Evci, Utku, Trevor Gale, Jacob Menick, Pablo Samuel Castro, and Erich Elsen. 2019. “Rigging the Lottery: Making All Tickets Winners.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1911.11134. ↩ ↩2 ↩3
  14. Lee, Namhoon, Thalaiyasingam Ajanthan, and Philip H. S. Torr. 2018. “SNIP: Single-Shot Network Pruning Based on Connection Sensitivity.” arXiv [cs.CV]. arXiv. http://arxiv.org/abs/1810.02340. ↩
  15. More work is being done on deciding whether lottery tickets are general. ↩
  16. Note that model compression is not the only path to memory-efficient training. For example, gradient checkpointing lets you trade computation time for memory when computing gradients during backprop. ↩
  17. I would say pruning and weight sharing are almost fully explored at this point, while quantization, factorization, and knowledge distillation have the biggest opportunity for improvements. ↩
  18. Gale, Trevor, Erich Elsen, and Sara Hooker. 2019. “The State of Sparsity in Deep Neural Networks.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1902.09574. ↩
  19. What type of regularization induces these 0 weights? It’s not entirely clear. Haeffele and Vidal (2017)6 proved that when a certain class of neural networks achieve a global optimum, the parameters of some sub-network become 0. If training impicitly or explicitly prefers L0 regularized solutions, then the weights will also be sparse. ↩
  20. Lan, Zhenzhong, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. 2019. “ALBERT: A Lite BERT for Self-Supervised Learning of Language Representations.” arXiv [cs.CL]. arXiv. http://arxiv.org/abs/1909.11942. ↩ ↩2
  21. Here’s a survey. Other examples include QBERT and Bitwise Neural Networks. ↩
  22. Note that quantized networks need special hardware to really see gains, which might explain why quantization is less popular than some of the other methods. ↩
  23. inFERENCe has some thoughts about this from the Bayesian perspective. In short, flat minima (which may or may not lead to generalization) should have parameters with a low minimum-description length. Another explanation is that networks that are robust to noise generalize better, and round-off error can be thought of as a type of regularization. ↩
  24. Rastegari, Mohammad, Vicente Ordonez, Joseph Redmon, and Ali Farhadi. 2016. “XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks.” arXiv [cs.CV]. arXiv. http://arxiv.org/abs/1603.05279. ↩
  25. Zhou, Shuchang, Zekun Ni, Xinyu Zhou, He Wen, Yuxin Wu, and Yuheng Zou. 2016. “DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients.” https://www.semanticscholar.org/paper/8b053389eb8c18c61b84d7e59a95cb7e13f205b7. ↩
  26. Lin, Xiaofan, Cong Zhao, and Wei Pan. 2017. “Towards Accurate Binary Convolutional Neural Network.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1711.11294. ↩
  27. Wang, Ziheng, Jeremy Wohlwend, and Tao Lei. 2019. “Structured Pruning of Large Language Models.” arXiv [cs.CL]. arXiv. http://arxiv.org/abs/1910.04732. ↩
  28. Denton, Emily, Wojciech Zaremba, Joan Bruna, Yann LeCun, and Rob Fergus. 2014. “Exploiting Linear Structure Within Convolutional Networks for Efficient Evaluation.” arXiv [cs.CV]. arXiv. http://arxiv.org/abs/1404.0736. ↩
  29. Hinton, Geoffrey, Oriol Vinyals, and Jeff Dean. 2015. “Distilling the Knowledge in a Neural Network.” arXiv [stat.ML]. arXiv. http://arxiv.org/abs/1503.02531. ↩
  30. Kim, Yoon, and Alexander M. Rush. 2016. “Sequence-Level Knowledge Distillation.” arXiv [cs.CL]. arXiv. http://arxiv.org/abs/1606.07947. ↩
  31. Furlanello, Tommaso, Zachary C. Lipton, Michael Tschannen, Laurent Itti, and Anima Anandkumar. 2018. “Born Again Neural Networks.” arXiv [stat.ML]. arXiv. http://arxiv.org/abs/1805.04770. ↩
  32. Yang, Chenglin, Lingxi Xie, Chi Su, and Alan L. Yuille. 2018. “Snapshot Distillation: Teacher-Student Optimization in One Generation.” https://www.semanticscholar.org/paper/a167d8a4ee261540c2b709dde2d94572c6ea3fc8. ↩
  33. Chen, Defang, Jian-Ping Mei, Can Wang, Yan Feng, and Chun Chen. 2019. “Online Knowledge Distillation with Diverse Peers.” arXiv [cs.LG]. arXiv. http://arxiv.org/abs/1912.00350. ↩

来源:http://mitchgordon.me/machine/learning/2020/01/13/do-we-really-need-model-compression.html

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-11-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 PyVision 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 作者:Mitchell A. Gordon 编译:McGL
  • 合适参数化(Appropriately-Parameterized)模型
  • 过参数化边界
  • 更好的优化技术
  • 从头开始(from Scratch)的稀疏网络
  • 未来方向
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档