zhuyaoyu/CodeV-R1-Qwen-7B

Model

CodeV-R1-Qwen-7B

7

13 commits

3 linked in READMEs

updated Jun 20, 2025

See the code

README

CodeV-R1-Qwen-7B

Project page

RTLLM TTS Results RTLLM TTS FLOPs Results
Test-time scaling curves. Left: Inference time as a function of token length. Right: Inference time vs. estimated FLOPs consumption. When measured by FLOPs consumption, our CodeV-R1-Qwen-7B achieves better results with fewer computational resources than DeepSeek-R1, highlighting its superior efficiency.

1. Introduction

Large language models (LLMs) trained via reinforcement learning with verifiable reward (RLVR) have achieved breakthroughs on tasks with explicit, automatable verification, such as software programming and mathematical problems. Extending RLVR to electronic design automation (EDA), especially automatically generating hardware description languages (HDLs) like Verilog from natural-language (NL) specifications, however, poses three key challenges: the lack of automated and accurate verification environments, the scarcity of high‐quality NL–code pairs, and the prohibitive computation cost of RLVR.

To this end, we introduce CodeV-R1, an RLVR framework for training Verilog generation LLMs, As a continuation of the work initiated with CodeV. First, we develop a rule-based testbench generator that performs robust equivalence checking against golden references. Second, we propose a round-trip data synthesis method that pairs open-source Verilog snippets with LLM‐generated NL descriptions, verifies code–NL–code consistency via the generated testbench, and filters out inequivalent examples to yield a high-quality dataset. Third, we employ a two-stage distill-then-RL training pipeline: distillation for the cold start of reasoning abilities, followed by adaptive DAPO, our novel RLVR algorithm that can reduce training cost by adaptively adjusting sampling rate.

CodeV-R1-Qwen-7B, is a model that employs reinforcement learning (RL) fine-tuning, built upon the foundation of CodeV-R1-Distill-Qwen-7B. The distillation-based precursor, CodeV-R1-Distill-Qwen-7B, is provided here. For more training details, please refer to our paper.

2. Evaluation Results

During the evaluation phase, the maximum generation length is configured to 16,384 tokens. A temperature setting of 0.6 is applied, and 20 responses are generated per query to estimate the pass@1 score.

Our evaluation encompasses Verilog benchmarks, including VerilogEval and RTLLM. For VerilogEval v2, we examine zero-shot scenarios in both specification-to-RTL translation and code completion tasks. Concerning RTLLM, results are reported for version 1.1, which offers a broader spectrum of comparative analyses. Furthermore, we find that the acquisition of the reasoning process in Verilog problems, as facilitated by DeepSeek-R1, enhances the model's out-of-domain mathematical capabilities.

VerilogEval (v2)

ModelModel sizeTypeSpec-to-rtlCompletion
GPT-4oUndisclosedGeneral62.5%59.0%
GPT-4 TurboUndisclosedGeneral61.1%53.9%
GPT-4UndisclosedGeneral32.0%42.3%
Mistral LargeUndisclosedGeneral37.5%34.0%
Llama3.1405BGeneral57.2%56.4%
Llama3.170BGeneral42.8%35.3%
Llama370BGeneral43.9%37.8%
Llama270BGeneral5.3%1.3%
Llama3.18BGeneral19.1%2.6%
CodeLlama70BCoding34.9%37.2%
DeepSeek Coder33BCoding21.7%25.0%
CodeGemma7BCoding9.5%8.3%
DeepSeek Coder6.7BCoding29.6%24.4%
RTL-Coder6.7BVerilog RTL36.8%35.9%
CodeV-R1-distill (ours)7BVerilog RTL65.2%65.5%
CodeV-R1 (ours)7BVerilog RTL68.8%69.9%

RTLLM (v1.1)

ModelModel sizeTypePass@1
GPT-4oUndisclosedGeneral33.8%
GPT-3.5 TurboUndisclosedGeneral28.3%
Llama3.1405BGeneral38.9%
Nemotron-4340BGeneral18.9%
Llama3.18BGeneral19.1%
CodeLlama7BCoding17.9%
CodeQwen7BCoding24.1%
Starcoder215BCoding15.5%
DeepSeek Coder6.7BCoding23.1%
DeepSeek-Coder-V216BCoding33.1%
DeepSeek-Coder-V2236BCoding34.5%
RTL-Coder6.7BVerilog RTL36.8%
CraftRTL6.7BVerilog RTL53.1%
CodeV-R1-distill (ours)7BVerilog RTL56.2%
CodeV-R1 (ours)7BVerilog RTL72.9%

For RTLLM v1.1, we also plot results showing pass rate against model size.

RTLLM TTS Results

4. Usage

CodeV-R1-Distill-Qwen-7B can be utilized in the same manner as Qwen or Llama models.

For instance, you can easily start a service using vLLM:

vllm serve zhuyaoyu/CodeV-R1-Distill-Qwen-7B --tensor-parallel-size 2 --max-model-len 16384 --enforce-eager

Usage Recommendations

During training and evaluation, we use a system prompt

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>.

It is recommended to use this prompt during inference.

5. License

CodeV-R1-Qwen-7B is derived from Qwen-2.5 series, which are originally licensed under Apache 2.0 License, and now finetuned with 87k samples curated with DeepSeek-R1.

6. Citation

If you find our model helpful, please cite our paper:

@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}, 
}
conversational
endpoints_compatible
qwen2
safetensors
text-generation
text-generation-inference
transformers
verilog

zhuyaoyu/CodeV-R1-Qwen-7B

Model

CodeV-R1-Qwen-7B

7

13 commits

3 linked in READMEs

updated Jun 20, 2025

See the code

README

CodeV-R1-Qwen-7B

Project page

RTLLM TTS Results RTLLM TTS FLOPs Results
Test-time scaling curves. Left: Inference time as a function of token length. Right: Inference time vs. estimated FLOPs consumption. When measured by FLOPs consumption, our CodeV-R1-Qwen-7B achieves better results with fewer computational resources than DeepSeek-R1, highlighting its superior efficiency.

1. Introduction

Large language models (LLMs) trained via reinforcement learning with verifiable reward (RLVR) have achieved breakthroughs on tasks with explicit, automatable verification, such as software programming and mathematical problems. Extending RLVR to electronic design automation (EDA), especially automatically generating hardware description languages (HDLs) like Verilog from natural-language (NL) specifications, however, poses three key challenges: the lack of automated and accurate verification environments, the scarcity of high‐quality NL–code pairs, and the prohibitive computation cost of RLVR.

To this end, we introduce CodeV-R1, an RLVR framework for training Verilog generation LLMs, As a continuation of the work initiated with CodeV. First, we develop a rule-based testbench generator that performs robust equivalence checking against golden references. Second, we propose a round-trip data synthesis method that pairs open-source Verilog snippets with LLM‐generated NL descriptions, verifies code–NL–code consistency via the generated testbench, and filters out inequivalent examples to yield a high-quality dataset. Third, we employ a two-stage distill-then-RL training pipeline: distillation for the cold start of reasoning abilities, followed by adaptive DAPO, our novel RLVR algorithm that can reduce training cost by adaptively adjusting sampling rate.

CodeV-R1-Qwen-7B, is a model that employs reinforcement learning (RL) fine-tuning, built upon the foundation of CodeV-R1-Distill-Qwen-7B. The distillation-based precursor, CodeV-R1-Distill-Qwen-7B, is provided here. For more training details, please refer to our paper.

2. Evaluation Results

During the evaluation phase, the maximum generation length is configured to 16,384 tokens. A temperature setting of 0.6 is applied, and 20 responses are generated per query to estimate the pass@1 score.

Our evaluation encompasses Verilog benchmarks, including VerilogEval and RTLLM. For VerilogEval v2, we examine zero-shot scenarios in both specification-to-RTL translation and code completion tasks. Concerning RTLLM, results are reported for version 1.1, which offers a broader spectrum of comparative analyses. Furthermore, we find that the acquisition of the reasoning process in Verilog problems, as facilitated by DeepSeek-R1, enhances the model's out-of-domain mathematical capabilities.

VerilogEval (v2)

ModelModel sizeTypeSpec-to-rtlCompletion
GPT-4oUndisclosedGeneral62.5%59.0%
GPT-4 TurboUndisclosedGeneral61.1%53.9%
GPT-4UndisclosedGeneral32.0%42.3%
Mistral LargeUndisclosedGeneral37.5%34.0%
Llama3.1405BGeneral57.2%56.4%
Llama3.170BGeneral42.8%35.3%
Llama370BGeneral43.9%37.8%
Llama270BGeneral5.3%1.3%
Llama3.18BGeneral19.1%2.6%
CodeLlama70BCoding34.9%37.2%
DeepSeek Coder33BCoding21.7%25.0%
CodeGemma7BCoding9.5%8.3%
DeepSeek Coder6.7BCoding29.6%24.4%
RTL-Coder6.7BVerilog RTL36.8%35.9%
CodeV-R1-distill (ours)7BVerilog RTL65.2%65.5%
CodeV-R1 (ours)7BVerilog RTL68.8%69.9%

RTLLM (v1.1)

ModelModel sizeTypePass@1
GPT-4oUndisclosedGeneral33.8%
GPT-3.5 TurboUndisclosedGeneral28.3%
Llama3.1405BGeneral38.9%
Nemotron-4340BGeneral18.9%
Llama3.18BGeneral19.1%
CodeLlama7BCoding17.9%
CodeQwen7BCoding24.1%
Starcoder215BCoding15.5%
DeepSeek Coder6.7BCoding23.1%
DeepSeek-Coder-V216BCoding33.1%
DeepSeek-Coder-V2236BCoding34.5%
RTL-Coder6.7BVerilog RTL36.8%
CraftRTL6.7BVerilog RTL53.1%
CodeV-R1-distill (ours)7BVerilog RTL56.2%
CodeV-R1 (ours)7BVerilog RTL72.9%

For RTLLM v1.1, we also plot results showing pass rate against model size.

RTLLM TTS Results

4. Usage

CodeV-R1-Distill-Qwen-7B can be utilized in the same manner as Qwen or Llama models.

For instance, you can easily start a service using vLLM:

vllm serve zhuyaoyu/CodeV-R1-Distill-Qwen-7B --tensor-parallel-size 2 --max-model-len 16384 --enforce-eager

Usage Recommendations

During training and evaluation, we use a system prompt

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>.

It is recommended to use this prompt during inference.

5. License

CodeV-R1-Qwen-7B is derived from Qwen-2.5 series, which are originally licensed under Apache 2.0 License, and now finetuned with 87k samples curated with DeepSeek-R1.

6. Citation

If you find our model helpful, please cite our paper:

@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}, 
}
conversational
endpoints_compatible
qwen2
safetensors
text-generation
text-generation-inference
transformers
verilog