Network Compression (网络压缩)

Network Compression

  • Smaller Model: Deploying ML models in resource-constrained environments
    在这里插入图片描述

We will not talk about hard-ware solution today.

Network Pruning (网络剪枝)

Network can be pruned

  • Networks are typically over-parameterized (there is significant redundant weights or neurons) ⇒ \Rightarrow Prune them!

Network Pruning

在这里插入图片描述

  • Evaluate the Importance:
    • Importance of a weight (Weight pruning): absolute values (接近 0 的参数可以被认为是不必要的), life long (类似于 life long learning 中计算参数重要性 b i b_i bi 的方法) …
    • Importance of a neuron (Neuron pruning): the number of times it wasn’t zero on a given data set ……
  • After pruning, the accuracy will drop (hopefully not too much). Fine-tuning on training data for recover (Don’t prune too much at once, or the network won’t recover.)

Weight pruning

  • The network architecture becomes irregular ⇒ \Rightarrow Hard to implement, hard to speedup …… (首先,Weight pruning 比较难在 Pytorch 等框架上部署,其次,如果把剪掉的 weight 值设为 0,其实并没有减少模型的规模)
    在这里插入图片描述在这里插入图片描述

上图中 Sparsity 表示被剪枝的 weight 百分比 (注意被剪枝的权重可以达到 95% 以上);可以看到在一些层上 Speedup 甚至是小于 1 的,剪枝后速度变得更慢了

Neuron pruning

  • Easy to implement, easy to speedup ……
    在这里插入图片描述

Why Pruning?

  • How about simply train a smaller network?
    • It is widely known that smaller network is more difficult to learn successfully. (Larger network is easier to optimize?)
    • Lottery Ticket Hypothesis: 大的网络可以看作许多小的网络的组合,可能更容易被训练
      在这里插入图片描述在 Lottery Ticket Hypothesis 的论文中,作者发现在将一个训练好的大网络剪枝后 (weight pruning),如果将得到的小网络参数重新随机初始化并加以训练,得到的效果是不好的,但如果用原先大网络中随机初始化的参数作为初始值加以训练,就可以得到不错的效果
      在这里插入图片描述“sign-ificance” of initial weights: Keeping the sign is critical: 在 Deconstructing Lottery Tickets: Zeros, Signs, and the Supermask 这篇论文中,作者发现如果要在训练剪枝后得到的小网络时得到好的效果,关键是要使小网络参数的初始值符号与原来大网络的初始值符号一致:
      在这里插入图片描述但上述说法还停留在假说阶段,在 Rethinking the Value of Network Pruning 中,作者发现如果对剪枝后的小网络训练足够多的 epoch,也能达到不错的效果,并认为 Lottery Ticket Hypothesis 只在学习率较小且使用 weight pruning 时才能被观察到

Knowledge Distillation (知识蒸馏)


  • Knowledge Distillation: Teacher network + Student network; 让学生网络的输出逼近教师网络的输出
    • e.g. 在下图中,学生网络不仅可以学到要输出 1,还可以学到 1 和 7 很相似这一信息
      在这里插入图片描述
  • Temperature for softmax: 使教师网络的输出更加平滑
    在这里插入图片描述
  • Teacher network 也可以利用集成学习:
    在这里插入图片描述

Parameter Quantization (权重量化)

  • (1) Using less bits to represent a value: e.g. float8
  • (2) Weight clustering: 用某一个参数代表一群参数 (可以在训练时要求参数之间比较接近,训练结束后再使用 Weight clustering 压缩模型)
    在这里插入图片描述
  • (3) Represent frequent clusters by less bits, represent rare clusters by more bits. e.g. Huffman encoding
  • (4) Binary Weights: Your weights are always +1 or -1

Architecture Design

Low rank approximation (低秩分解)

  • 假设 M M M N N N 层的神经元数量都很多,我们可以 M M M N N N 中间加上一层,神经元数量为 K K K,达到减少参数量的目的
    在这里插入图片描述 W = U V W=UV W=UV,这样近似降低了 W W W 秩的上界
    在这里插入图片描述也可以简单地用 SVD 分解或 PQ 分解来直接对原始权重矩阵进行分解

Depthwise Separable Convolution (深度可分离卷积)

Depthwise Convolution

在这里插入图片描述

  • Each filter only considers one channel: Filter number = Input channel number
  • There is no interaction between channels ⇒ \Rightarrow Pointwise Convolution

Pointwise Convolution

  • The filters are 1 × 1 1\times1 1×1 matrices
    在这里插入图片描述

Depthwise Separable Convolution v.s. Convolution

  • Depthwise Separable Convolution: k × k × I + I × O k\times k \times I + I\times O k×k×I+I×O
  • Convolution: k × k × I × O k\times k\times I\times O k×k×I×O
    k × k × I + I × O k × k × I × O = 1 O + 1 k × k \frac{k\times k \times I + I\times O}{k\times k\times I\times O}=\frac{1}{O}+\frac{1}{k\times k} k×k×I×Ok×k×I+I×O=O1+k×k1

More

  • 分组卷积
  • 全局池化代替全连接层
  • 1 × 1 1\times1 1×1 卷积实现通道降维来降低模型计算量
  • BN 层合并: 在训练检测模型时,BN 层可以有效加速收敛,并在一定程度上防止模型的过拟合,但在前向测试时,BN 层的存在也增加了多余的计算量。由于测试时 BN 层的参数已经固定,因此可以在测试时将 BN 层的计算合并到卷积层,从而减少计算量,实现模型加速

To learn more ……

Dynamic Computation

  • Dynamic Computation: The network adjusts the computation it need. (e.g. 在嵌入式设备上使用较少运算量、电量较少时使用较少运算量)
    在这里插入图片描述

Dynamic Depth

Dynamic Width

在这里插入图片描述

Computation based on Sample Difficulty

  • 根据任务的难度,让网络自行决定需要的宽度和深度
    在这里插入图片描述

To learn more…

  • SkipNet: Learning Dynamic Routing in Convolutional Networks
  • Runtime Neural Pruning
  • BlockDrop: Dynamic Inference Paths in Residual Networks

References

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值