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

arXiv:2510.15914 · cs.AR, cs.AI, cs.PL · Submitted 2025-09-27 · Read on arXiv

cs.AR, cs.AI, cs.PL

Submitted: 2025-09-27

Updated: 2026-10-17

Comments: 8 pages, 6 figures. Accepted at ASP-DAC 2027; updated to the camera-ready version

License: http://creativecommons.org/licenses/by/4.0/

The gist: Large language models (LLMs) have demonstrated remarkable capabilities in generating Verilog code from natural language descriptions.

Terminology

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@1 and pass@5 scores among the compared methods on both benchmarks.

Related papers