[Paper Review] Benchmarking Large Language Models for Automated Verilog RTL Code Generation
This paper benchmarks fine-tuned large language models (LLMs) for automated Verilog RTL code generation, using a curated dataset from GitHub and Verilog textbooks. Fine-tuning significantly improves syntactic correctness (25.9% overall) and functional correctness, with the CodeGen-16B model outperforming even the commercial Codex model (6.5% vs. 6.5% functional correctness), demonstrating the value of domain-specific fine-tuning for hardware description languages.
Automating hardware design could obviate a significant amount of human error from the engineering process and lead to fewer errors. Verilog is a popular hardware description language to model and design digital systems, thus generating Verilog code is a critical first step. Emerging large language models (LLMs) are able to write high-quality code in other programming languages. In this paper, we characterize the ability of LLMs to generate useful Verilog. For this, we fine-tune pre-trained LLMs on Verilog datasets collected from GitHub and Verilog textbooks. We construct an evaluation framework comprising test-benches for functional analysis and a flow to test the syntax of Verilog code generated in response to problems of varying difficulty. Our findings show that across our problem scenarios, the fine-tuning results in LLMs more capable of producing syntactically correct code (25.9% overall). Further, when analyzing functional correctness, a fine-tuned open-source CodeGen LLM can outperform the state-of-the-art commercial Codex LLM (6.5% overall). Training/evaluation scripts and LLM checkpoints are available: https://github.com/shailja-thakur/VGen.
Motivation & Objective
- To evaluate the ability of large language models (LLMs) to generate syntactically and functionally correct Verilog code from natural language specifications.
- To address the lack of large-scale, high-quality Verilog datasets for training and evaluating LLMs.
- To design a comprehensive evaluation framework with testbenches and compilation checks to measure functional correctness across varying problem difficulties.
- To compare the performance of open-source and commercial LLMs after fine-tuning on domain-specific Verilog corpora.
- To investigate the impact of model size and training data composition on code generation quality.
Proposed method
- Constructed a large-scale Verilog training corpus by aggregating open-source GitHub repositories and digitized Verilog textbook PDFs, followed by rigorous preprocessing to extract clean code snippets.
- Fine-tuned five pre-trained LLMs—ranging from 345M to 16B parameters—on the curated Verilog dataset to specialize them for RTL code generation.
- Designed a suite of 20 diverse Verilog coding problems with increasing difficulty, each accompanied by functional testbenches to validate correctness.
- Implemented a multi-stage evaluation pipeline: code generation at various temperature and beam search settings, followed by syntax checking via Verilog compilation and functional verification via testbench execution.
- Used Pass@n metrics to evaluate functional correctness across multiple completions per prompt, with n=10 being the primary evaluation setting.
- Conducted ablation studies to assess the impact of training data composition, comparing models trained on GitHub-only versus GitHub + textbook data.
Experimental results
Research questions
- RQ1Can fine-tuned LLMs generate syntactically correct and synthesizable Verilog code from natural language descriptions?
- RQ2How does model size (e.g., 345M to 16B parameters) affect the quality of generated Verilog code?
- RQ3Does fine-tuning on domain-specific Verilog data improve functional correctness compared to using pre-trained models?
- RQ4How does the composition of the training data (e.g., GitHub vs. textbooks) influence model generalization and performance?
- RQ5Can open-source LLMs outperform commercial models like Codex when properly fine-tuned on Verilog-specific data?
Key findings
- Fine-tuning LLMs on a curated Verilog corpus increased the overall syntactic correctness of generated code to 25.9%, compared to only 11.9% for pre-trained models.
- The fine-tuned CodeGen-16B model achieved 41.9% functional correctness across all test scenarios, outperforming the non-fine-tuned code-davinci-002 model, which achieved 35.4% functional correctness.
- The best-performing model (CodeGen-16B FT) passed all testbenches for 6.5% of problems when generating 10 completions per prompt, significantly outperforming Codex in functional correctness.
- Fine-tuning on a combination of GitHub and textbook Verilog data improved Pass@10 by 1.4 percentage points compared to GitHub-only fine-tuning, indicating the value of diverse, high-quality training data.
- Despite strong performance, some complex problems (e.g., LFSR, shift/rotate) remained challenging, with 0–1 out of 540 completions passing, suggesting limitations in reasoning and expression construction.
- Prompt engineering and testbench design significantly influence evaluation outcomes, as ambiguous problem descriptions (e.g., reset type) led to inconsistent model outputs and test failures.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.