VeriThoughts: Enabling Automated Verilog Code Generation using Reasoning and Formal Verification

Patrick Yubeaton, Andre Nakkab, Weihua Xiao, Luca Collini, Ramesh Karri, Chinmay Hegde, Siddharth Garg

TL;DR

VeriThoughts is the first large-scale reasoning dataset for hardware design, pairing over 20,000 synthesizable Verilog designs with natural language prompts, chain-of-thought (CoT) reasoning traces, and mathematically proven equivalence labels via formal verification. By fine-tuning open-source models on these reasoning traces, the authors achieve state-of-the-art open-source performance on Verilog generation benchmarks with as few as 10,000 training examples.

What Problem Does This Paper Address?

While Large Language Models (LLMs) have significantly accelerated software development, automated code generation for hardware description languages (HDLs) like Verilog lags far behind. Hardware design suffers from severe data scarcity on the open web, highly complex sequential dependencies, and a zero-tolerance policy for bugs.

Supervised fine-tuning (SFT) on reasoning traces (Chain-of-Thought) has revolutionized software coding models, but no such datasets existed for Verilog. Furthermore, generating synthetic prompt-to-code training data often introduces hallucinations, and evaluating hardware code using LLM-generated testbenches or simulation vectors is unreliable and incomplete.

Methods

The authors introduce a four-stage pipeline that marries frontier LLMs with open-source electronic design automation (EDA) formal verification tools:

Ground-Truth Verilog (V) 
   ──> Gemini 2.0 Flash Thinking ──> Specification/Prompt (Q)
   ──> DeepSeek-R1 (670B)        ──> Reasoning Trace (R) + Candidate Code (V*)
   ──> Yosys Formal Equivalence  ──> Consistency Label L_c = E(V = V*)
  1. Prompt Generation ($V \to Q$): Starting from synthesizable Verilog code $V$ filtered from the MetRex dataset, Gemini 2.0 Flash Thinking generates a prompt $Q$ specifying the module name, interface, and behavioral constraints without spoon-feeding implementation details.
  2. Reasoning & Code Synthesis ($Q \to R, V^*$): The generated question $Q$ is fed to DeepSeek-R1-670B to generate a detailed reasoning trace $R$ and a candidate implementation $V^*$.
  3. Formal Verification ($L_C \leftarrow E(V = V^*)$): Instead of using simulation testbenches, the authors run an automated Boolean Satisfiability (SAT) solver using the open-source Yosys framework. If $V$ and $V^*$ are mathematically proven functionally equivalent across all inputs, the sample is labeled self-consistent ($L_C = 1$); otherwise, it is labeled inconsistent ($L_C = 0$).
  4. Supervised Fine-Tuning: The authors fine-tune Qwen-2.5 base models (7B, 14B, and 32B) on combinations of these prompts, reasoning traces, and code targets using LoRA/full-parameter tuning via LLaMA-Factory.

Datasets

  • MetRex: The source repository of ~25.8k synthesizable Verilog designs, filtered down to ~25k entries under 10,000 characters.
  • VeriThoughts (Train): 20,173 tuples of $\{V, Q, R, V^*, L_C\}$ containing ground-truth code, generated prompts, reasoning traces, generated code, and formal verification labels.
  • VeriThoughts Benchmark (Test): A newly curated evaluation set of 291 hold-out problems validated via formal equivalence checking rather than unit tests.
  • VerilogEval 1.0 (Human Split): The standard literature benchmark consisting of 156 human-designed problems evaluated with simulation testbenches.

Key Insights and Ideas

  • Formal Verification Guarantees Quality: Manual inspection of 100 samples confirmed that 100% of the samples passing formal equivalence checking ($L_C = 1$) had zero prompt or code-generation errors.
  • Reasoning Dramatically Outperforms Instruction Tuning: Models trained with reasoning traces consistently beat standard instruction-tuned baselines across both benchmarks—often boosting pass@1 by 10% to 30%.
  • The "Hallucinated Prompt" Dividend: Counterintuitively, training models on formally inconsistent pairs $(Q, V^*)$ frequently outperformed training on self-consistent ground truth $(Q, V)$. Manual review revealed why: in 66% of failures, the prompt $Q$ failed to describe the original code $V$, but DeepSeek-R1 correctly implemented what the prompt asked for ($V^*$). Because these "failed" examples tended to feature more complex sequential circuits and longer reasoning chains, they served as richer training examples.

Key Results

  • State-of-the-Art Open-Source Verilog Generation: Fine-tuning Qwen-2.5 on just ~10k samples from VeriThoughts yielded VeriThoughts-14B, achieving 43.7% pass@1 on the VerilogEval Human benchmark. This surpassed dedicated models like DeepSeek-R1-Distill-Qwen-14B (38.7%) and Qwen3-14B (28.1%).
  • Scaled Model Performance: Scaling to VeriThoughts-32B pushed VerilogEval performance to 52.0% pass@1 (63.6% pass@10), approaching proprietary frontier models like GPT-4o (56.3% pass@1).
  • VeriThoughts Benchmark Results: On the new formally verified benchmark, VeriThoughts-14B scored 78.5% pass@1 (92.1% pass@10), trailing only Qwen3-14B and closed models like ChatGPT-o3 (92.6%).

Limitations and Future Work

  • Source Diversity: Training data was sourced entirely from the MetRex dataset; expanding to a broader array of proprietary and open-source hardware designs will be essential to cover esoteric EDA libraries and system-level protocols.
  • Tooling Constraints: Formal verification was handled via Yosys SAT-solving using sequential-to-combinational unrolling (clk2fflogic), which can struggle with deep sequential loops or very large multi-module hierarchies.
  • Single Generator Model: All reasoning traces were extracted from DeepSeek-R1-670B; exploring synthetic multi-model ensembles or reinforcement learning (RL) with formal verification rewards remains an exciting next step.

Summary updated

BibTeX
@inproceedings{yubeaton2025verithoughts,
  author = {Patrick Yubeaton and Andre Nakkab and Weihua Xiao and Luca Collini and Ramesh Karri and Chinmay Hegde and Siddharth Garg},
  title = {{VeriThoughts: Enabling Automated Verilog Code Generation using Reasoning and Formal Verification}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=3Z8fWHKqlu},
}
Figure