- [2024/6] First work-around of HaVen is done!
This repository accompanies the paper "HaVen: Hallucination-Mitigated LLM for Verilog Code Generation Aligned with HDL Engineers", accepted at DATE 2025. HaVen is a novel framework designed to enhance the alignment of large language models (LLMs) with hardware description language (HDL) engineering practices, mitigating logical, symbolic, and knowledge hallucinations in Verilog code generation.
For training and fine-tuning, install LLaMA-Factory by following their installation instructions.
pip install torch transformersVCS is a Verilog compiler required for automated testing on benchmarks. Follow these steps to install and configure VCS:
- Obtain VCS from Synopsys. Ensure you have the required license to use it.
- Install VCS following the instructions provided in the official Synopsys documentation.
- Add the VCS executable to your system's PATH environment variable.
Verify the installation by running:
vcs -helpThe training environment configuration and running methods refer to the llamafactory project.
from transformers import pipeline
import torch
prompt= "FILL IN THE QUESTION"
generator = pipeline(
model="HaVen-CodeQwen",
task="text-generation",
torch_dtype=torch.bfloat16,
device_map="auto",
)
result = generator(prompt , max_length=2048,num_return_sequences=1, temperature=0.0)
response = result[0]["generated_text"]
print("Response:", response)To perform inference on the VerilogEval benchmark, use the script located at:
model_inference/inference_VerilogEval.py
The following example demonstrates inference using the deepseek-coder-6.7b model:
python model_inference/inference_VerilogEval.py \
--model deepseek-ai/deepseek-coder-6.7b-instruct \
--n 1 \
--temperature 1.0 \
--gpu_name 7 \
--output_dir ./your_output_path \
--output_file your_output_file.jsonl \
--bench_type MachineTo perform inference on the RTLLM benchmark, use the script located at:
model_inference/inference_RTLLM.py
The following example demonstrates inference using the deepseek-coder-6.7b model:
python model_inference/inference_RTLLM.py \
--model deepseek-ai/deepseek-coder-6.7b-instruct \
--n 5 \
--temperature 0.5 \
--gpu_name 5 \
--output_dir ./your_output_pathBelow is a description of the key parameters used in the inference scripts:
-
--model
Specifies the pre-trained or fine-tuned model to use for inference. Example:deepseek-ai/deepseek-coder-6.7b-instruct. -
--n
The number of samples to generate for each input. A higher value increases diversity but requires more computational resources. -
--temperature
Controls the randomness of predictions. Values closer to0make the output more deterministic, while higher values (e.g.,1.0) allow for more diversity. -
--gpu_name
Identifies the GPU to be used for running the inference. Specify the GPU ID (e.g.,0,1,7). -
--output_dir
The directory where the inference results will be saved. Ensure the directory exists or can be created. -
--output_file(optional, VerilogEval-specific)
Specifies the name of the output file to save results. The file format is typically.jsonl. -
--bench_type(VerilogEval-specific)
Indicates the type of benchmark evaluation. Example:Machine. Refer to the benchmark documentation for valid types.
| Base Model | HaVen | |
|---|---|---|
| 7B | Qwen/CodeQwen1.5-7B-Chat | HaVen-CodeQwen |
Our repository includes a script to evaluate the model's performance on VerilogEval and RTLLM benchmarks.
-
Prepare Tasks:
- The task list of VerilogEval-Human is in
test_on_benchmark/tasks_verilogeval_human.txt. - The task list of VerilogEval-Machine is in
test_on_benchmark/tasks_verilogeval_machine.txt. - The task list of RTLLM is in
test_on_benchmark/tasks_verilogeval_RTLLM.txt. - Or you can customize the names of tasks to evaluate in
test_on_benchmark/tasks_to_do.txt.
- The task list of VerilogEval-Human is in
-
Configure Test Script:
- Open
test_on_benchmark/run.sh. - Set the following variables:
path: Path to the directory containing the generated Verilog code.n: Number of code candidates to evaluate per task.
- The generated Verilog code for HaVen is available at:
test_on_benchmark/model_output/HaVen
- Open
-
Run the Script:
bash test_on_benchmark/run.sh
If you find this repository or our research helpful, please cite our paper:
@inproceedings{haven2025,
title = {HaVen: Hallucination-Mitigated LLM for Verilog Code Generation Aligned with HDL Engineers},
author = {Yiyao Yang and Fu Teng and Pengju Liu and Mengnan Qi and Chenyang Lv and Ji Li and Xuhong Zhang and Zhezhi He},
booktitle = {Design, Automation & Test in Europe (DATE)},
year = {2025}
}
For questions or issues, feel free to open an issue or contact the authors. Thank you for using HaVen!
