Prithvik-1 commited on
Commit
85e1c7a
·
verified ·
1 Parent(s): 861568b

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +286 -0
README.md ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: llama2
5
+ tags:
6
+ - code-generation
7
+ - verilog
8
+ - systemverilog
9
+ - rtl
10
+ - hardware-design
11
+ - fifo
12
+ - semiconductor
13
+ - ip-design
14
+ - lora
15
+ - codellama
16
+ base_model: codellama/CodeLlama-7B-Instruct-hf
17
+ datasets:
18
+ - Elinnos/verilog-fifo-dataset
19
+ library_name: peft
20
+ pipeline_tag: text-generation
21
+ ---
22
+
23
+ # CodeLlama-7B Fine-Tuned for Verilog FIFO Generation
24
+
25
+ ## Model Description
26
+
27
+ This is a **LoRA fine-tuned CodeLlama-7B-Instruct** model specialized in generating clean, synthesizable Verilog/SystemVerilog code for FIFO (First-In-First-Out) designs. The model was trained on comprehensive FIFO specifications following industry best practices for RTL design.
28
+
29
+ **Model Type:** Causal Language Model (LoRA Adapter)
30
+ **Base Model:** [codellama/CodeLlama-7B-Instruct-hf](https://huggingface.co/codellama/CodeLlama-7B-Instruct-hf)
31
+ **Training Date:** 2025-11-25
32
+ **Organization:** Elinnos Systems
33
+
34
+ ## Key Features
35
+
36
+ ✅ **Complete Code Generation** - Generates full Verilog modules with proper structure
37
+ ✅ **Synthesizable RTL** - Clean, synthesizable code following best practices
38
+ ✅ **FIFO Variants** - Supports various FIFO architectures (synchronous, asynchronous, parameterized)
39
+ ✅ **Protocol Compliance** - Proper signal handling, full/empty flags, error handling
40
+ ✅ **Production-Ready** - No comments, no debug statements, clean functional code
41
+
42
+ ## Training Details
43
+
44
+ ### Dataset
45
+
46
+ - **Training Samples:** 70
47
+ - **Validation Samples:** 9
48
+ - **Test Samples:** 15
49
+ - **Total Samples:** 94
50
+ - **Dataset Format:** CodeLlama chat template format
51
+ - **Average Sequence Length:** 1536 tokens
52
+
53
+ ### Training Configuration
54
+
55
+ - **Base Model:** codellama/CodeLlama-7B-Instruct-hf
56
+ - **Training Method:** LoRA (Low-Rank Adaptation)
57
+ - **Quantization:** 4-bit NF4 (for GPU memory efficiency)
58
+ - **Training Steps:** 25 steps (5 epochs)
59
+ - **Epochs:** 5
60
+ - **Batch Size:** 4
61
+ - **Effective Batch Size:** 16 (with gradient accumulation)
62
+ - **Learning Rate:** 2e-05
63
+ - **Max Sequence Length:** 1536
64
+ - **Hardware:** NVIDIA A100-SXM4-40GB
65
+
66
+ ### LoRA Configuration
67
+
68
+ ```python
69
+ from peft import LoraConfig
70
+
71
+ LoraConfig(
72
+ r=48, # Rank
73
+ lora_alpha=96, # Scaling factor
74
+ target_modules=['q_proj', 'up_proj', 'down_proj', 'gate_proj', 'o_proj', 'k_proj', 'v_proj'],
75
+ lora_dropout=0.15,
76
+ bias="none",
77
+ task_type="CAUSAL_LM"
78
+ )
79
+ ```
80
+
81
+ **Target Modules:**
82
+ - `q_proj`
83
+ - `up_proj`
84
+ - `down_proj`
85
+ - `gate_proj`
86
+ - `o_proj`
87
+ - `k_proj`
88
+ - `v_proj`
89
+
90
+ **Trainable Parameters:** ~672M (LoRA adapter only)
91
+
92
+ ## Model Capabilities
93
+
94
+ ### What This Model Can Do
95
+
96
+ 1. **Synchronous FIFO Design**
97
+ - Dual-port memory architecture
98
+ - Write/Read pointer management
99
+ - Full/Empty flag generation
100
+ - Configurable width and depth
101
+ - Error handling (write_err, read_err)
102
+ - Threshold flags (almost_full, almost_empty)
103
+ - Occupancy output
104
+
105
+ 2. **Asynchronous FIFO Design**
106
+ - Gray code pointer synchronization
107
+ - Clock domain crossing (CDC)
108
+ - Separate read/write clocks
109
+ - Data valid signals
110
+
111
+ 3. **Advanced Features**
112
+ - Parameterized FIFO modules
113
+ - AXI-like handshake protocols
114
+ - Pipelined output stages
115
+ - Peek capability
116
+ - Clear signal support
117
+
118
+ 4. **Code Quality**
119
+ - Clean, synthesizable RTL
120
+ - No comments or debug statements
121
+ - Proper signal naming conventions
122
+ - Modular design structure
123
+
124
+ ## Usage
125
+
126
+ ### Installation
127
+
128
+ ```bash
129
+ pip install transformers peft torch bitsandbytes accelerate
130
+ ```
131
+
132
+ ### Loading the Model
133
+
134
+ ```python
135
+ import torch
136
+ from transformers import AutoModelForCausalLM, AutoTokenizer
137
+ from peft import PeftModel
138
+ from transformers import BitsAndBytesConfig
139
+
140
+ # Load base model with 4-bit quantization
141
+ base_model = AutoModelForCausalLM.from_pretrained(
142
+ "codellama/CodeLlama-7B-Instruct-hf",
143
+ quantization_config=BitsAndBytesConfig(
144
+ load_in_4bit=True,
145
+ bnb_4bit_quant_type="nf4",
146
+ bnb_4bit_compute_dtype=torch.float16,
147
+ ),
148
+ device_map="auto",
149
+ trust_remote_code=True
150
+ )
151
+
152
+ # Load fine-tuned LoRA adapter
153
+ model = PeftModel.from_pretrained(
154
+ base_model,
155
+ "Elinnos/codellama-7b-fifo-verilog"
156
+ )
157
+
158
+ # Load tokenizer
159
+ tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLlama-7B-Instruct-hf")
160
+ if tokenizer.pad_token is None:
161
+ tokenizer.pad_token = tokenizer.eos_token
162
+ tokenizer.pad_token_id = tokenizer.eos_token_id
163
+ ```
164
+
165
+ ### Generating Code
166
+
167
+ ```python
168
+ # Create prompt using CodeLlama chat template
169
+ system_prompt = "You are Elinnos RTL Code Generator v1.0, a specialized Verilog/SystemVerilog code generation agent. Your role: Generate clean, synthesizable RTL code for hardware design tasks. Output ONLY functional RTL code with no $display, assertions, comments, or debug statements."
170
+
171
+ user_prompt = "Generate a synchronous FIFO with 8-bit data width, depth 4, write_enable, read_enable, full flag, empty flag."
172
+
173
+ messages = [
174
+ {"role": "system", "content": system_prompt},
175
+ {"role": "user", "content": user_prompt}
176
+ ]
177
+
178
+ prompt = tokenizer.apply_chat_template(
179
+ messages,
180
+ tokenize=False,
181
+ add_generation_prompt=True
182
+ )
183
+
184
+ # Generate
185
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
186
+ outputs = model.generate(
187
+ **inputs,
188
+ max_new_tokens=800,
189
+ temperature=0.3,
190
+ do_sample=True,
191
+ top_p=0.9,
192
+ repetition_penalty=1.2,
193
+ eos_token_id=tokenizer.eos_token_id
194
+ )
195
+
196
+ # Decode response
197
+ response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=False)
198
+ print(response)
199
+ ```
200
+
201
+ ### Using the Simple Inference Script
202
+
203
+ ```bash
204
+ # From the codellama-migration directory
205
+ python3 simple_finetuned_model_inference.py \
206
+ --prompt "Generate a synchronous FIFO with 32-bit data width, depth 16" \
207
+ --model-path "Elinnos/codellama-7b-fifo-verilog"
208
+ ```
209
+
210
+ ## Training Code
211
+
212
+ The model was trained using the following repository:
213
+ - **Repository:** [Elinnos/codellama-fifo-finetuning](https://huggingface.co/Elinnos/codellama-fifo-finetuning)
214
+ - **Training Script:** `scripts/training/finetune_codellama.py`
215
+
216
+ ### Training Command
217
+
218
+ ```bash
219
+ python scripts/training/finetune_codellama.py \
220
+ --base-model codellama/CodeLlama-7B-Instruct-hf \
221
+ --dataset datasets/processed/split_chat_format/train.jsonl \
222
+ --output-dir training-outputs/codellama-fifo-v2-chat \
223
+ --max-length 1536 \
224
+ --num-epochs 5 \
225
+ --batch-size 4 \
226
+ --gradient-accumulation 4 \
227
+ --learning-rate 2e-05 \
228
+ --lora-r 48 \
229
+ --lora-alpha 96 \
230
+ --lora-dropout 0.15
231
+ ```
232
+
233
+ ## Evaluation
234
+
235
+ ### Training Metrics
236
+
237
+ - **Final Training Loss:** 0.626
238
+ - **Final Validation Loss:** 0.609
239
+ - **Training Loss Progression:**
240
+ - Epoch 1: 1.113
241
+ - Epoch 2: 0.996
242
+ - Epoch 3: 0.834
243
+ - Epoch 4: 0.704
244
+ - Epoch 5: 0.626
245
+
246
+ ### Model Performance
247
+
248
+ The model demonstrates strong capability in:
249
+ - Generating syntactically correct Verilog code
250
+ - Following FIFO design specifications
251
+ - Producing clean, synthesizable RTL
252
+ - Handling various FIFO configurations (width, depth, features)
253
+
254
+ ## Limitations
255
+
256
+ - Model size: Requires base CodeLlama-7B-Instruct model (~13GB)
257
+ - Context window: Maximum sequence length of 1536 tokens
258
+ - Domain: Specialized for FIFO designs, may not generalize to other RTL components
259
+ - Language: Primarily English prompts
260
+
261
+ ## Citation
262
+
263
+ If you use this model, please cite:
264
+
265
+ ```bibtex
266
+ @model{{codellama_fifo_elinnos}},
267
+ title={CodeLlama-7B Fine-Tuned for Verilog FIFO Generation},
268
+ author={Elinnos Systems},
269
+ year={2025},
270
+ url={https://huggingface.co/Elinnos/codellama-7b-fifo-verilog}
271
+ }
272
+ ```
273
+
274
+ ## License
275
+
276
+ This model follows the same license as the base CodeLlama-7B-Instruct model (Llama 2 Community License).
277
+
278
+ ## Contact
279
+
280
+ For questions or issues, please contact:
281
+ - **Organization:** Elinnos Systems
282
+ - **Repository:** [Elinnos/codellama-fifo-finetuning](https://huggingface.co/Elinnos)
283
+
284
+ ---
285
+
286
+ *Model trained by Elinnos Systems for Verilog FIFO code generation.*