cs.ARSep 27, 2025

VeriGRAG: Enhancing LLM-Based Verilog Code Generation with Structure-Aware Soft Prompts

Authors: Jiayu Zhao, Zehua Pei, Zetao Guo, Bei Yu, Song Chen

Organizations: University of Science and Technology of China

Abstract

Large language models (LLMs) have demonstrated remarkable capabilities in generating Verilog code from natural language descriptions. However, Verilog code inherently encodes the structural characteristics of hardware circuits, including data path organization and interconnections among components. Effectively leveraging these structural characteristics to enhance the functional and syntactic correctness of LLM-based Verilog code generation remains a significant challenge. To address this challenge, we propose VeriGRAG, a novel framework that converts Verilog code into data path graphs and employs graph neural networks (GNNs) to encode their structural information. A multimodal retriever, trained through knowledge distillation from a cross-attention encoder to a dual encoder, then selects the graph embeddings most relevant to the input hardware description. The VeriFormer module uses learnable query tokens and two-stage training to extract code-relevant structural features and align them with the LLM's input embedding space, producing structure-aware soft prompts. Experiments on VerilogEval and RTLLM show improvements in both syntactic and functional correctness. With Qwen2.5-Coder-32B as its backbone, VeriGRAG achieves the highest functional pass@1pass@1 and pass@5pass@5 scores among the compared methods on both benchmarks.

Figures & tables

Explore similar work

CardsList
  1. Exploring the Agentic Frontier of Verilog Code Generation

    Mar 19, 2026Patrick Yubeaton, Siddharth Garg, Chinmay HegdeCode GenerationAgentic Code Generation

  2. Benchmarking LLMs for Verilog Design Flows

    Jul 23, 2026Angshuman Chakravertty, Rahul Koshti, Buddhi Prakash Sharma +1Code GenerationCode Generation Evaluation

  3. Exploring LLM-based Verilog Code Generation with Data-Efficient Fine-Tuning and Testbench Automation

    Apr 16, 2026Mu-Chi Chen, Po-Hsuan Huang, Yu-Hung Kao +6LLM Fine-TuningCode Generation