Recently, fine-tuning pre-trained code models such as CodeBERT on downstream tasks has achieved great success in many software testing and analysis tasks. While effective and prevalent, fine-tuning the pre-trained parameters incurs a large computational cost. In this paper, we conduct an extensive experimental study to explore what happens to layer-wise pre-trained representations and their encoded code knowledge during fine-tuning. We then propose efficient alternatives to fine-tune the large pre-trained code model based on the above findings. Our experimental study shows that (1) lexical, syntactic and structural properties of source code are encoded in the lower, intermediate, and higher layers, respectively, while the semantic property spans across the entire model. (2) The process of fine-tuning preserves most of the code properties. Specifically, the basic code properties captured by lower and intermediate layers are still preserved during fine-tuning. Furthermore, we find that only the representations of the top two layers change most during fine-tuning for various downstream tasks. (3) Based on the above findings, we propose Telly to efficiently fine-tune pre-trained code models via layer freezing. The extensive experimental results on five various downstream tasks demonstrate that training parameters and the corresponding time cost are greatly reduced, while performances are similar or better. Replication package including source code, datasets, and online Appendix is available at: \url{https://github.com/DeepSoftwareAnalytics/Telly}.
翻译:近年来,如 CodeBERT 等预训练代码模型的微调在软件测试和分析任务中取得了巨大成功。然而,微调预训练参数会带来巨大的计算代价。本文通过大规模实验研究,探讨了微调过程中不同层的预训练表征及其编码的代码知识的变化。在此基础上,提出了一种在保持模型性能的前提下有效微调预训练代码模型的方法。实验结果表明,源代码的词法、句法和结构属性主要编码在较低、中层,语义属性则涵盖整个模型。微调过程主要改变模型顶部层的表征。根据这些发现,我们提出了 Telly 这一通过层冻结实现高效微调预训练代码模型的方法。在五个不同应用场景的持续任务中,Telly 实现了训练参数和时间成本的显著降低,同时 performance 取得了与原有方法相当甚至更好的结果。源代码、数据集和在线附录均已开放共享。(翻译为自然语言可读性所作,如有不妥之处请包容指正。)