🚀 CodeV-R1-Qwen-7B
CodeV-R1-Qwen-7B是基于CodeV-R1框架,在Qwen/Qwen2.5-Coder-7B-Instruct基础上通过强化学习微调得到的模型。它在Verilog相关任务上表现出色,能有效解决电子设计自动化中自动生成硬件描述语言的难题。
🚀 快速开始
CodeV-R1-Distill-Qwen-7B的使用方式与Qwen或Llama模型相同。例如,你可以使用 vLLM 轻松启动服务:
vllm serve zhuyaoyu/CodeV-R1-Distill-Qwen-7B --tensor-parallel-size 2 --max-model-len 16384 --enforce-eager
✨ 主要特性
- 创新框架:引入CodeV-R1框架用于训练Verilog生成大语言模型,解决了电子设计自动化中自动生成硬件描述语言面临的缺乏自动化准确验证环境、高质量自然语言 - 代码对稀缺和强化学习验证计算成本高的问题。
- 优质数据集:提出往返数据合成方法,将开源Verilog代码片段与大语言模型生成的自然语言描述配对,通过生成的测试平台验证代码 - 自然语言 - 代码的一致性,并过滤掉不等价的示例,得到高质量数据集。
- 高效训练:采用两阶段的先蒸馏后强化学习的训练流程,先通过蒸馏启动推理能力,再使用自适应DAPO算法,可通过自适应调整采样率降低训练成本。
📚 详细文档
1. 引言
通过可验证奖励的强化学习(RLVR)训练的大语言模型(LLMs)在软件编程和数学问题等具有明确、可自动化验证的任务上取得了突破。然而,将RLVR扩展到电子设计自动化(EDA),特别是从自然语言(NL)规范自动生成硬件描述语言(HDLs)(如Verilog),面临三个关键挑战:缺乏自动化和准确的验证环境、高质量NL - 代码对的稀缺以及RLVR的计算成本过高。
为此,我们引入了CodeV-R1,这是一个用于训练Verilog生成LLM的RLVR框架,是CodeV工作的延续。首先,我们开发了一个基于规则的测试平台生成器,用于对黄金参考进行稳健的等价性检查。其次,我们提出了一种往返数据合成方法,将开源Verilog代码片段与LLM生成的NL描述配对,通过生成的测试平台验证代码 - NL - 代码的一致性,并过滤掉不等价的示例,以得到高质量的数据集。第三,我们采用了两阶段的先蒸馏后RL的训练流程:先进行蒸馏以启动推理能力,然后使用自适应DAPO,这是我们新颖的RLVR算法,可以通过自适应调整采样率来降低训练成本。
CodeV-R1-Qwen-7B是一个采用强化学习(RL)微调的模型,基于CodeV-R1-Distill-Qwen-7B构建。基于蒸馏的前身CodeV-R1-Distill-Qwen-7B可在此处获取。有关更多训练细节,请参考我们的论文。
2. 评估结果
在评估阶段,最大生成长度配置为16,384个令牌。应用温度设置为0.6,并为每个查询生成20个响应以估计pass@1分数。
我们的评估涵盖了Verilog基准测试,包括VerilogEval和RTLLM。对于VerilogEval v2,我们研究了规范到RTL翻译和代码补全任务中的零样本场景。对于RTLLM,报告的是版本1.1的结果,该版本提供了更广泛的比较分析。此外,我们发现通过DeepSeek-R1促进的Verilog问题推理过程的获取,增强了模型的域外数学能力。
VerilogEval (v2)
模型 |
模型大小 |
类型 |
规范到RTL |
补全 |
GPT-4o |
未披露 |
通用 |
62.5% |
59.0% |
GPT-4 Turbo |
未披露 |
通用 |
61.1% |
53.9% |
GPT-4 |
未披露 |
通用 |
32.0% |
42.3% |
Mistral Large |
未披露 |
通用 |
37.5% |
34.0% |
Llama3.1 |
405B |
通用 |
57.2% |
56.4% |
Llama3.1 |
70B |
通用 |
42.8% |
35.3% |
Llama3 |
70B |
通用 |
43.9% |
37.8% |
Llama2 |
70B |
通用 |
5.3% |
1.3% |
Llama3.1 |
8B |
通用 |
19.1% |
2.6% |
CodeLlama |
70B |
编码 |
34.9% |
37.2% |
DeepSeek Coder |
33B |
编码 |
21.7% |
25.0% |
CodeGemma |
7B |
编码 |
9.5% |
8.3% |
DeepSeek Coder |
6.7B |
编码 |
29.6% |
24.4% |
RTL-Coder |
6.7B |
Verilog RTL |
36.8% |
35.9% |
CodeV-R1-distill (我们的模型) |
7B |
Verilog RTL |
65.2% |
65.5% |
CodeV-R1 (我们的模型) |
7B |
Verilog RTL |
68.8% |
69.9% |
RTLLM (v1.1)
模型 |
模型大小 |
类型 |
Pass@1 |
GPT-4o |
未披露 |
通用 |
33.8% |
GPT-3.5 Turbo |
未披露 |
通用 |
28.3% |
Llama3.1 |
405B |
通用 |
38.9% |
Nemotron-4 |
340B |
通用 |
18.9% |
Llama3.1 |
8B |
通用 |
19.1% |
CodeLlama |
7B |
编码 |
17.9% |
CodeQwen |
7B |
编码 |
24.1% |
Starcoder2 |
15B |
编码 |
15.5% |
DeepSeek Coder |
6.7B |
编码 |
23.1% |
DeepSeek-Coder-V2 |
16B |
编码 |
33.1% |
DeepSeek-Coder-V2 |
236B |
编码 |
34.5% |
RTL-Coder |
6.7B |
Verilog RTL |
36.8% |
CraftRTL |
6.7B |
Verilog RTL |
53.1% |
CodeV-R1-distill (我们的模型) |
7B |
Verilog RTL |
56.2% |
CodeV-R1 (我们的模型) |
7B |
Verilog RTL |
72.9% |
对于RTLLM v1.1,我们还绘制了显示通过率与模型大小关系的结果。
💡 使用建议
在训练和评估期间,我们使用以下系统提示:
You are a helpful assistant. The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning process and answer are enclosed within <think> </think> and<answer> </answer> tags, respectively, i.e., <think> reasoning process here </think><answer> answer here </answer>. Now the user asks you to write verilog code. After thinking, when you finally reach a conclusion, enclose the final verilog code in ```verilog ``` within <answer> </answer> tags. i.e., <answer> ```verilog
module top_module(in, out, ...) ... ``` </answer>.
建议在推理时使用此提示。
📄 许可证
CodeV-R1-Qwen-7B源自Qwen-2.5系列,该系列最初根据Apache 2.0许可证许可,现在使用从DeepSeek-R1整理的87k样本进行微调。
📚 引用
如果您发现我们的模型有帮助,请引用我们的论文:
@misc{zhu2025codevr1,
title={CodeV-R1: Reasoning-Enhanced Verilog Generation},
author={Yaoyu Zhu and Di Huang and Hanqi Lyu and Xiaoyun Zhang and Chongxiao Li and Wenxuan Shi and Yutong Wu and Jianan Mu and Jinghua Wang and Yang Zhao and Pengwei Jin and Shuyao Cheng and Shengwen Liang and Xishan Zhang and Rui Zhang and Zidong Du and Qi Guo and Xing Hu and Yunji Chen},
year={2025},
eprint={2505.24183},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2505.24183},
}