VRank: Enhancing Verilog Code Generation from Large Language Models via Self-Consistency

Zhuorui Zhao, Ruidi Qiu, Ing-Chao Lin, Grace Li Zhang, Bing Li, Ulf Schlichtmann

Abstract

Large Language Models (LLMs) show significant promise in automating hardware design but often struggle to generate functionally correct Verilog code, typically requiring manual verification or human-written testbenches. We present VRank, a fully automated framework that leverages self-consistency and Chain-of-Thought (CoT) reasoning to select the most accurate Verilog candidate from an LLM-generated pool. By clustering candidates based on simulation behavior and using targeted reasoning for tie-breaking, VRank eliminates the need for human intervention, improving pass@1 accuracy by an average of 10.5% across multiple state-of-the-art models.

The Bottleneck in Automated Hardware Design

As chip design complexity grows, engineers are increasingly turning to LLMs to automate the generation of hardware description languages. However, Verilog generation remains error-prone due to the relative scarcity of hardware-specific training data compared to general software code.

Currently, addressing these errors requires a "human-in-the-loop" approach. Engineers must either manually inspect code, write exhaustive testbenches to provide debugging feedback, or repeatedly sample the model until a correct solution is found. This creates a significant bottleneck in the design cycle. VRank addresses this by asking: How can we automatically identify the single best, functionally correct Verilog module from a batch of candidates without requiring a human-written testbench?

Comparison of Verilog generation strategies: (a) Retry, (b) Debug, and (c) the proposed Self-Consistency approach.

The VRank Framework

VRank introduces a three-stage pipeline inspired by self-consistency techniques used in natural language processing, adapted for the strict requirements of hardware simulation.

The detailed VRank pipeline: (a) Execution-based clustering, (b) Cluster ranking, and (c) CoT-based decision making.

1. Execution-Based Clustering

The system prompts an LLM to generate multiple Verilog code candidates alongside a simple testbench. Crucially, this testbench only provides input stimuli; it does not require ground-truth reference outputs. All candidates are simulated using the generated stimuli, and those producing identical output sequences are grouped into clusters. This approach relies on the insight that while correct code is consistently alike, incorrect code tends to fail in diverse, unpredictable ways.

2. Cluster Ranking

VRank ranks these clusters using a consensus-based scoring function. A cluster receives a high score if its simulation outputs agree with the majority of other generated candidates. This acts as a reliable proxy for functional correctness without needing a golden reference.

3. Chain-of-Thought (CoT) Decision Making

In cases where the top two clusters are highly competitive but disagree on specific test cases, VRank employs a targeted "tie-breaker." It identifies the conflicting test case and feeds it back to the LLM. Using zero-shot CoT prompting, the LLM logically deduces the correct output for that specific scenario. VRank then selects the cluster that matches this logical deduction.

Key Results and Insights

Evaluation on the VerilogEval-Human benchmark (156 problems) demonstrated that VRank significantly outperforms standard sampling methods:

  • Accuracy Gains: VRank improved pass@1 accuracy by an average of 10.5% across models including GPT-4o, Llama-3-70B, and CodeV-Qwen.
  • Domain Model Stabilization: The domain-specific CodeV-Qwen model saw a massive 19.6% improvement on combinational circuits, highlighting VRank's ability to stabilize models with high variance.
  • Sample Efficiency: The framework is computationally practical; generating just 20 samples achieves approximately 90% of the performance gains seen with 50 samples.
  • Strict Consistency: Researchers found that hardware verification requires strict output matching. Attempting to use "partial credit" for similar but non-identical outputs actually reduced selection accuracy.

Conclusion

VRank effectively removes the human from the verification loop for module-level Verilog generation. By shifting the focus from generating perfect testbenches to analyzing the comparative behavior of code candidates, it provides a robust path toward fully automated hardware synthesis. Future work will explore scaling this framework to handle complex, multi-module system-on-chip (SoC) designs and integration into commercial EDA workflows.

Summary updated

BibTeX
@inproceedings{zhao2025vrank,
  author = {Zhuorui Zhao and Ruidi Qiu and Ing-Chao Lin and Grace Li Zhang and Bing Li and Ulf Schlichtmann},
  title = {{VRank: Enhancing Verilog Code Generation from Large Language Models via Self-Consistency}},
  booktitle = {ISQED},
  year = {2025},
  doi = {10.1109/isqed65160.2025.11014398},
}
Figure