🚀 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},
}