arXiv:2505.24183cs.LGcs.AR2025-05NeurIPS被引 44

用强化学习提升代码生成,让AI更准地把自然语言转成Verilog

QiMeng-CodeV-R1: Reasoning-Enhanced Verilog Generation

  • 构建规则测试台实现代码等价性验证,解决硬件验证难题
  • 通过双向数据合成生成高质量语义对,提升训练数据可信度
  • 两阶段训练降低计算成本,小模型性能超越大模型

基于可验证奖励的强化学习(RLVR)大模型在软件编程和数学问题上取得突破。然而将其应用于电子设计自动化(EDA),尤其是从自然语言(NL)描述自动生成硬件描述语言(Verilog),面临三大挑战:缺乏自动化准确的验证环境、高质量的NL-代码配对数据稀缺、以及RLVR训练成本过高。为此,我们提出CodeV-R1,一种面向Verilog生成的RLVR框架。首先,开发基于规则的测试台生成器,实现与基准参考的稳健等价性检查。其次,提出往返数据合成方法,将开源Verilog片段与LLM生成的自然语言描述配对,通过生成的测试台验证代码-语言-代码一致性,并过滤不等价样本,构建高质量数据集。第三,采用两阶段“蒸馏-再强化”训练流程:先通过蒸馏初始化推理能力,再使用新型自适应DAPO算法,动态调整采样率以降低训练开销。最终模型CodeV-R1-7B在VerilogEval v2和RTLLM v1.1上分别达到68.6%和72.9%的pass@1,较先前最优提升12~20%,甚至超越671B的DeepSeek-R1在RTLLM上的表现。模型、代码与数据集已开源,助力EDA与大模型研究。

原文摘要 · Abstract (English)

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. 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. The resulting model, CodeV-R1-7B, achieves 68.6% and 72.9% pass@1 on VerilogEval v2 and RTLLM v1.1, respectively, surpassing prior state-of-the-art by 12~20%, while even exceeding the performance of 671B DeepSeek-R1 on RTLLM. We have released our model, training code, and dataset to facilitate research in EDA and LLM communities.

Verilog生成强化学习EDA代码合成

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。