WANGNingroci
commited on
Commit
•
224f922
1
Parent(s):
a5a0dfd
Upload README.md
Browse files
README.md
CHANGED
@@ -1,39 +1,121 @@
|
|
1 |
-
|
2 |
-
license: apache-2.0
|
3 |
-
task_categories:
|
4 |
-
- text-generation
|
5 |
-
language:
|
6 |
-
- en
|
7 |
-
tags:
|
8 |
-
- code
|
9 |
-
pretty_name: opencores
|
10 |
-
size_categories:
|
11 |
-
- n<1K
|
12 |
-
---
|
13 |
-
|
14 |
-
# Dataset Card for Opencores
|
15 |
-
|
16 |
-
We gathered high-quality specification-code pairs from Opencores, a community aimed to developing digital open-source hardware using electronic design automation (EDA).
|
17 |
-
We then filtered out data instances exceeding 4096 characters in length and those that could not be parsed into Abstract Syntax Trees (AST).
|
18 |
-
The final dataset comprises approximately 800 data instances.
|
19 |
-
|
20 |
-
## Dataset Features
|
21 |
-
|
22 |
-
- instruction (string): The nature language instruction for Verilog code design.
|
23 |
-
- input (string): For dataset loading efficiency, no valid meaning.
|
24 |
-
- output (string): The expected Verilog code.
|
25 |
-
- name (string): Name of Verilof module.
|
26 |
-
|
27 |
-
## Loading the dataset
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
```
|
30 |
-
from datasets import load_dataset
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
```
|
35 |
|
36 |
## Citation
|
|
|
|
|
37 |
```
|
38 |
@article{wang2024large,
|
39 |
title={Large Language Model for Verilog Generation with Golden Code Feedback},
|
@@ -41,4 +123,7 @@ print(ds[0])
|
|
41 |
journal={arXiv preprint arXiv:2407.18271},
|
42 |
year={2024}
|
43 |
}
|
44 |
-
```
|
|
|
|
|
|
|
|
1 |
+
# Veriseek
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
Official implement of paper "Large Language Model for Verilog Generation with Golden Code Feedback". The best model weight is available at https://huggingface.co/WANGNingroci/VeriSeek.
|
4 |
+
|
5 |
+
![veriseek](images/result.png)
|
6 |
+
|
7 |
+
## Table of Contents
|
8 |
+
- [Update Log](#update-log)
|
9 |
+
- [Project Description](#project-description)
|
10 |
+
- [Installation](#installation)
|
11 |
+
- [Usage](#usage)
|
12 |
+
- [Generation](#Generation)
|
13 |
+
- [Pretrain](#Pretrain)
|
14 |
+
- [PPO](#PPO)
|
15 |
+
- [Citation](#Citation)
|
16 |
+
- [Acknowledgement](#Acknowledgement)
|
17 |
+
|
18 |
+
## Update Log
|
19 |
+
- 2024.08.02: Add citation information.
|
20 |
+
- 2024.07.22: Initial version of Veriseek. Add training code and config file.
|
21 |
+
|
22 |
+
## Project Description
|
23 |
+
This study introduces a novel approach utilizing reinforcement learning with golden code feedback to enhance the performance of pre-trained models. Leveraging open-source data and base models, we have achieved state- of-the-art (SOTA) results with a substantial margin. Notably, our 6.7B parameter model VeriSeek demonstrates superior performance compared to current best-in- class 13B and 16B models. Furthermore, through a comprehensive analysis of the limitations in direct fine-tuning and the training dynamics of reinforcement learning, we posit that the development of comprehensive supervisory signals, which are align with the inherent parallel semantics of Verilog code, is critical to effective generation.
|
24 |
+
|
25 |
+
## Installation
|
26 |
+
To install this project, follow these steps:
|
27 |
+
|
28 |
+
1. Clone the repository: `git clone https://github.com/CatIIIIIIII/veriseek.git`
|
29 |
+
2. Navigate to the project directory: `cd veriseek`
|
30 |
+
3. Install the dependencies: `conda env create -f environment.yml`
|
31 |
+
|
32 |
+
## Usage
|
33 |
+
|
34 |
+
Before training, you should configure the `src/scripts/single_node.sh` file for training, `src/configs/accelerate/accel.yaml` for accelerate, `src/configs/deepspeed/ds_z3_config.json` for deepspeed. The configuration file contains the following options:
|
35 |
+
|
36 |
+
### Generation
|
37 |
+
|
38 |
+
To generate reponse, run the following demo:
|
39 |
+
|
40 |
+
```python
|
41 |
+
import torch
|
42 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
43 |
+
|
44 |
+
def stop_at_stop_token(decoded_string, stop_tokens):
|
45 |
+
"""
|
46 |
+
Produces the prefix of decoded_string that ends at the first occurrence of
|
47 |
+
a stop_token.
|
48 |
+
WARNING: the decoded_string *must not* include the prompt, which may have stop tokens
|
49 |
+
itself.
|
50 |
+
"""
|
51 |
+
min_stop_index = len(decoded_string)
|
52 |
+
for stop_token in stop_tokens:
|
53 |
+
stop_index = decoded_string.find(stop_token)
|
54 |
+
if stop_index != -1 and stop_index < min_stop_index:
|
55 |
+
min_stop_index = stop_index
|
56 |
+
return decoded_string[:min_stop_index]
|
57 |
+
|
58 |
+
|
59 |
+
prompt = """
|
60 |
+
Please act as a professional verilog designer.
|
61 |
+
|
62 |
+
Implement a data width conversion circuit that converts 8-bit data input to 16-bit data output. The module provides two output ports: valid_out, which indicates the validity of the output data, and data_out, which represents the converted 16-bit output data. The first arriving 8-bit data should be placed in the higher 8 bits of the 16-bit data output. The valid_out and data_out signals are generated in the next clock cycle after the two data inputs. When there is only one data input, valid_out and data_out are not generated immediately. Instead, they wait for the arrival of the next data input to complete the concatenation of the two data inputs before generating valid_out and data_out.
|
63 |
+
|
64 |
+
Module name:
|
65 |
+
width_8to16
|
66 |
+
|
67 |
+
Input ports:
|
68 |
+
clk: Clock signal used for synchronous operation.
|
69 |
+
rst_n: Active-low reset signal. Defined as 0 for reset and 1 for reset signal inactive.
|
70 |
+
valid_in: Input signal indicating the validity of the input data.
|
71 |
+
data_in: 8-bit input data to be converted.
|
72 |
+
|
73 |
+
Output ports:
|
74 |
+
valid_out: Output signal indicating the validity of the output data.
|
75 |
+
data_out: 16-bit output data resulting from the width conversion.
|
76 |
+
Implementation:
|
77 |
+
The data_out register is triggered on the positive edge of the clock signal (posedge clk) or the negative edge of the reset signal (negedge rst_n).
|
78 |
+
On reset, indicated by !rst_n, the data_out register is cleared to 0.
|
79 |
+
If the input data is valid (valid_in) and the flag signal is active, the data_out register is updated by concatenating the contents of the data_lock register (8 bits) and the data_in register (8 bits) to form a 16-bit output. The first valid data is temporarily stored, and when the second valid data is inputted, they are concatenated to produce the output valid_out and data_out.
|
80 |
+
|
81 |
+
Give me the complete code.
|
82 |
+
|
83 |
+
"""
|
84 |
+
|
85 |
+
gpu_id = 0
|
86 |
+
model_name = "WANGNingroci/VeriSeek"
|
87 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
88 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map=gpu_id)
|
89 |
+
model.eval()
|
90 |
+
# Sample
|
91 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(gpu_id)
|
92 |
+
sample = model.generate(input_ids, max_length=1024, temperature=0.2, top_p=0.95, do_sample=True)
|
93 |
+
output = tokenizer.decode(sample[0])
|
94 |
+
|
95 |
+
stop_word = "endmodule"
|
96 |
+
output_trunc = stop_at_stop_token(output, [stop_word])
|
97 |
+
output_trunc += stop_word
|
98 |
+
print(output_trunc)
|
99 |
```
|
|
|
100 |
|
101 |
+
### Pretrain
|
102 |
+
The pretraining data is available at https://huggingface.co/datasets/WANGNingroci/vgen_cpp. Download and put it in the `data/pretrain` directory.
|
103 |
+
To pretrain the model, run the following command:
|
104 |
+
|
105 |
+
```bash
|
106 |
+
bash src/scripts/single_node.sh src/configs/pretrain/deepseek-7B.yaml
|
107 |
+
```
|
108 |
+
|
109 |
+
### PPO
|
110 |
+
The reinforcement learning algorithm used in this project is Proximal Policy Optimization (PPO). Opencores data is available at https://huggingface.co/datasets/WANGNingroci/opencores. Download and put it in the `data/opencores` directory. To train the model with PPO, run the following command:
|
111 |
+
|
112 |
+
```bash
|
113 |
+
bash src/scripts/single_node.sh src/configs/preference/deepseek-7B_ppo_ast.yaml
|
114 |
```
|
115 |
|
116 |
## Citation
|
117 |
+
If you find this project helpful, please consider citing our paper:
|
118 |
+
|
119 |
```
|
120 |
@article{wang2024large,
|
121 |
title={Large Language Model for Verilog Generation with Golden Code Feedback},
|
|
|
123 |
journal={arXiv preprint arXiv:2407.18271},
|
124 |
year={2024}
|
125 |
}
|
126 |
+
```
|
127 |
+
|
128 |
+
## Acknowledgement
|
129 |
+
This repo benefits from [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory). Thanks for their wonderful works.
|