用模型合并技术打造通用代码克隆检测器,无需重新训练即可跨领域高效工作。
A Unified Model for Cross-Domain Clone Detection via Model Merging

- 通过参数融合与层拼接等方法,将多个专用模型合并为统一跨域检测器。
- 合并后模型在通用数据集上达0.865综合F1,接近多任务训练93%性能。
- 对AI生成代码克隆泛化能力更强,适合需要跨语言、跨生成方式的场景。
代码克隆类型日益多样,从语法复制到跨语言语义克隆,再到AI生成副本,导致检测方法碎片化。现有深度学习模型在训练分布外性能下降超70%。部署多个专用模型不现实,而训练统一模型需同时访问所有数据。本文研究模型合并技术,仅基于已训练检查点进行操作。评估了五种任务向量合并、贪婪层拼接及跨分词器对齐,在四个代码模型、三个基准和十二种配置下测试。相同基础模型的TIES合并法表现优异,跨两模型族与三随机种子验证,于UniXcoder上达0.865综合F1,达到多任务训练93%性能,且合并过程无需训练数据。WUDI在同分布下最佳(F1=0.899),但TIES对未见的AI生成克隆泛化更好,推荐为首选。跨基础合并仅带来微弱且高方差提升,表明共享预训练基底是有效合并的关键。合并模型在GPTCloneBench上优于零样本代码大模型,推理成本更低,对未见的AI生成克隆泛化能力高出4倍,体现域内性能与域外鲁棒性之间的权衡。本工作为软件工程中模型合并提供了首个系统性实证研究与实用构建方案。
原文摘要 · Abstract (English)
The growing diversity of code clone types, from syntactic copies to cross-language semantic clones to AI-generated duplicates, has created a fragmentation crisis in clone detection. Current deep learning detectors are domain specialists that degrade significantly outside their training distribution, with F1 drops exceeding 70% across domains. Deploying multiple specialized models is impractical, yet training a single cross-domain detector requires simultaneous access to all training data. To address this, we investigate model merging, a family of post-hoc techniques that operate solely on trained checkpoints. We evaluate parameter merging with five task-vector methods, architecture merging via greedy layer stitching, and cross-tokenizer alignment across four code models, three benchmarks, and twelve configurations. Same-base TIES merging creates effective cross-domain detectors, validated across two model families and three random seeds, reaching 0.865 combined F1 on UniXcoder, 93% of multi-task performance without any training data at the merging step. WUDI achieves the highest in-distribution combined F1 at 0.899, but TIES generalizes better to unseen AI-generated clones, making it our recommended method. Cross-base merging yields only marginal and high-variance gains across all five methods, indicating that task vector compatibility through a shared pre-trained base is the binding factor for effective merging. Merged detectors also outperform zero-shot code LLMs on GPTCloneBench at lower inference cost and generalize up to 4x better than multi-task training to unseen AI-generated clones, suggesting a trade-off between in-domain performance and OOD robustness. This work provides one of the first systematic empirical studies of model merging for software engineering and a practical recipe for building cross-domain clone detectors.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。