Skip to main content
QUICK REVIEW

[论文解读] DynaBERT: Dynamic BERT with Adaptive Width and Depth

Lu Hou, Zhiqi Huang|arXiv (Cornell University)|Apr 8, 2020
Topic Modeling参考文献 40被引用 119
一句话总结

DynaBERT 训练一个具备宽度和深度自适应的 BERT 模型,能够部署具有不同资源使用量的子网络,利用知识蒸馏和网络重连来保持准确性。

ABSTRACT

The pre-trained language models like BERT, though powerful in many natural language processing tasks, are both computation and memory expensive. To alleviate this problem, one approach is to compress them for specific tasks before deployment. However, recent works on BERT compression usually compress the large BERT model to a fixed smaller size. They can not fully satisfy the requirements of different edge devices with various hardware performances. In this paper, we propose a novel dynamic BERT model (abbreviated as DynaBERT), which can flexibly adjust the size and latency by selecting adaptive width and depth. The training process of DynaBERT includes first training a width-adaptive BERT and then allowing both adaptive width and depth, by distilling knowledge from the full-sized model to small sub-networks. Network rewiring is also used to keep the more important attention heads and neurons shared by more sub-networks. Comprehensive experiments under various efficiency constraints demonstrate that our proposed dynamic BERT (or RoBERTa) at its largest size has comparable performance as BERT-base (or RoBERTa-base), while at smaller widths and depths consistently outperforms existing BERT compression methods. Code is available at https://github.com/huawei-noah/Pretrained-Language-Model/tree/master/DynaBERT.

研究动机与目标

  • 在异构硬件的边缘设备上推动高效部署 BERT。
  • 通过在一个模型内选择不同宽度和深度的子网络来实现灵活推理。
  • 通过从全尺寸教师模型进行知识蒸馏,在各种配置下保持高精度。
  • 通过宽度自适应的教师辅助方法缩小教师与学生之间的尺寸差距。
  • 证明动态子网络在标准基准上可以达到甚至超过固定大小压缩基线。

提出的方法

  • 通过改变注意力头数量和 FFN 神经元数量(宽度)以及 Transformer 层数(深度),来定义 Transformer 层的宽度和深度自适应。
  • 两阶段训练:首先训练一个具有宽度自适应的 DynaBERT_W,采用网络重连并从重连后的教师进行蒸馏;然后使用 DynaBERT_W 作为教师,训练具备宽度和深度自适应的 DynaBERT。
  • 使用网络重连对重要的头/神经元进行排序和对齐,使它们在子网络之间共享。
  • 在 logits、嵌入和隐藏状态之间应用知识蒸馏,以在不同宽度和深度之间将知识从教师传递给学生。
  • 对于 DynaBERT_W,使用固定的重连教师和多种宽度配置;对于完整的 DynaBERT,则从最宽深度的教师蒸馏到深度和宽度被缩减的子网络。
  • 从 TinyBERT 获取数据增强,以为蒸馏提供任务特定的示例。

实验结果

研究问题

  • RQ1是否可以训练一个单一的 BERT 模型以支持多种宽度和深度配置,同时相比固定大小模型保持最小的精度损失?
  • RQ2在训练中引入宽度和深度自适应是否能带来比固定大小压缩方法更好的性价比?
  • RQ3网络重连和蒸馏对 GLUE 和 SQuAD 任务的性能影响如何?
  • RQ4将宽度自适应模型用作教师助手是否有助于缩小大子网络与小子网络之间的差距?
  • RQ5在各种效率约束下,DynaBERT_W 与 DynaBERT 与最先进的固定大小蒸馏和仅深度自适应方法相比如何?

主要发现

  • 当配置为全宽度/全深度时,DynaBERT 在最大尺寸下在基准上达到与 BERT_BASE 相当的性能。
  • 在相同的效率约束下,宽度和/或深度降低的子网络始终优于固定大小的压缩方法。
  • 宽度自适应比仅深度自适应更稳健,并且对于较小的配置,DynaBERT_W(宽度自适应)通常优于 DynaBERT_D(深度自适应)。
  • 在相似资源预算下,DynaBERT 子网络在 GLUE 与 SQuAD 任务中通常超过 DistilBERT、TinyBERT 和 LayerDrop。
  • 将 DynaBERT_W 作为教师助手相比直接从重连后的全模型蒸馏,可提升蒸馏性能。
  • 训练后每个子网络无需进一步微调,即可在各设备上高效部署。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。