用微调+检索增强实现超大规模Verilog代码库的智能补全。
RTLRepoCoder: Repository-Level RTL Code Completion through the Combination of Fine-Tuning and Retrieval Augmentation
- 结合领域微调与检索增强生成,支持跨文件代码理解。
- 在公开基准上编辑相似度和精确匹配率显著超越GPT-4。
- 适合芯片设计工程师、硬件开发团队快速构建复杂RTL代码。
作为现代硬件设计的核心环节,手动编写寄存器传输级(RTL)代码如Verilog通常非常耗时。随着大语言模型(LLMs)的兴起,研究者开始探索利用LLMs生成RTL代码。然而,现有方法主要聚焦于生成简单单模块代码,难以满足实际需求。由于长上下文管理困难及复杂的跨文件依赖关系,当前方案无法在真实硬件开发中处理大规模Verilog代码库。本文首次专门针对大规模RTL开发适配LLMs,提出RTLRepoCoder,一种融合特定微调与检索增强生成(RAG)的解决方案。使用真实世界开源Verilog代码库并扩展上下文长度进行领域微调;优化的RAG系统通过检索相关代码片段提升输入上下文信息密度,包括嵌入模型、跨文件上下文分片策略和块大小等定制优化。实验表明,该方法在公开基准上达到当前最佳性能,显著优于GPT-4和先进领域专用LLMs,在编辑相似度和精确匹配率上均有大幅提升。全面实验证明了方法的有效性,并为未来研究提供洞见。
原文摘要 · Abstract (English)
As an essential part of modern hardware design, manually writing Register Transfer Level (RTL) code such as Verilog is often labor-intensive. Following the tremendous success of large language models (LLMs), researchers have begun to explore utilizing LLMs for generating RTL code. However, current studies primarily focus on generating simple single modules, which can not meet the demands in real world. In fact, due to challenges in managing long-context RTL code and complex cross-file dependencies, existing solutions cannot handle large-scale Verilog repositories in practical hardware development. As the first endeavor to exclusively adapt LLMs for large-scale RTL development, we propose RTLRepoCoder, a groundbreaking solution that incorporates specific fine-tuning and Retrieval-Augmented Generation (RAG) for repository-level Verilog code completion. Open-source Verilog repositories from the real world, along with an extended context size, are used for domain-specific fine-tuning. The optimized RAG system improves the information density of the input context by retrieving relevant code snippets. Tailored optimizations for RAG are carried out, including the embedding model, the cross-file context splitting strategy, and the chunk size. Our solution achieves state-of-the-art performance on public benchmark, significantly surpassing GPT-4 and advanced domain-specific LLMs on Edit Similarity and Exact Match rate. Comprehensive experiments demonstrate the remarkable effectiveness of our approach and offer insights for future work.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。