Abstract
Large Language Models (LLMs) often struggle with low-resource hardware description languages like Verilog due to tokenization mismatches and data scarcity. This paper introduces a novel approach that repurposes speculative decoding to improve both inference speed and code quality. By aligning speculative "guesses" with syntactically meaningful fragments identified via Abstract Syntax Trees (AST), the proposed method achieves up to a 5.05× speedup and a 17.19% boost in functional accuracy.
Introduction
While LLMs excel in general-purpose programming languages, their performance on Verilog is hampered by standard Byte Pair Encoding (BPE) tokenizers that split logical constructs into arbitrary sub-word units. This mismatch, combined with the relative scarcity of Verilog training data, leads to frequent syntax and functional errors. Conventional speculative decoding techniques focus primarily on latency optimization. This work demonstrates that by integrating syntactic awareness into the speculative decoding process, one can simultaneously enhance the structural integrity and generation speed of Verilog code.
Methods
The core of the approach builds upon the MEDUSA architecture, extending it with syntax-enriched labels. Instead of predicting arbitrary future tokens, the model uses an AST parser to identify "syntactically significant" boundaries—such as keywords, operators, and identifiers. A special [FRAG] (fragment) token is inserted at these boundaries to guide the speculative heads.
The decoding mechanism is modified to ensure "syntactic integrity." Speculative heads are trained to complete meaningful fragments; if a prediction crosses a structural boundary incorrectly, it is discarded. Furthermore, a dynamic labeling and parallel training algorithm is employed to mask incomplete fragments, reducing the difficulty for later speculative heads and improving overall robustness.
Datasets and Evaluation
The researchers curated a dataset of 136,134 Verilog modules by scraping GitHub and integrating existing datasets like MG-Verilog and RTLCoder. To facilitate instruction tuning, GPT-4 was used to generate natural language summaries for the scraped code. Evaluation was performed on the RTLLM and VGen benchmarks, measuring the "pass@k" metric for both functional and syntactic correctness.
Key Results
The proposed method delivers significant improvements across multiple dimensions. On the CodeLlama-7b model, it achieved a 5.05× speedup over standard next-token prediction and outperformed the original MEDUSA method by 1.42–2.29×.
Beyond speed, the quality gains are substantial: functional accuracy (pass@10) on RTLLM increased by 17.19%, and syntactic correctness (pass@5) saw improvements of up to 49.94%. The method also proved effective even with limited training data, highlighting its utility for low-resource specialized languages.
Conclusion
By treating speculative decoding as a structural regularizer rather than just a speed optimization, this work bridges the gap between sub-word tokenization and the logical structure of hardware description languages. Future research may focus on reducing dependency on specific parsers and generalizing the "fragment" identification process to other formal grammars.
Summary updated