一句话:通过分层实验揭示代码模型微调规律,提出基于层冻结的 Telly 实现高效微调。
预训练代码模型(如 CodeBERT)在下游软件测试与分析任务上微调效果显著,但全参数微调计算开销巨大。本文对微调过程中逐层预训练表示及其编码的代码知识进行广泛实验研究,发现源码的词法、句法与结构属性分别编码于低层、中间层与高层,而语义属性横跨整个模型;微调可保留大部分代码属性,低层与中间层捕获的基本属性仍被保留,且不同下游任务中仅顶部两层的表示变化最大。基于这些发现,作者提出 Telly,通过层冻结高效微调预训练代码模型。在五个不同下游任务上的实验表明,该方法大幅减少训练参数与时间成本,同时性能与全量微调相当或更优。
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.
@inproceedings{paperbot8045,
title = {Towards Efficient Fine-Tuning of Pre-trained Code Models: An Experimental Study and Beyond},
author = {Ensheng Shi and Yanlin Wang and Hongyu Zhang and Lun Du and Shi Han and Dongmei Zhang and Hongbin Sun},
booktitle = {ISSTA},
year = {2023},
doi = {10.1145/3597926.3598036}
}