henil08 commited on
Commit
fe0f333
·
verified ·
1 Parent(s): 75e823c

Upload 7B-L3

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-Coder-7B-Instruct
3
+ license: apache-2.0
4
+ library_name: transformers
5
+ pipeline_tag: text-generation
6
+ datasets:
7
+ - ESCAD/OpenRTLSet
8
+ tags:
9
+ - verilog
10
+ - systemverilog
11
+ - rtl
12
+ - code
13
+ ---
14
+
15
+ # verilog-coder (7B, LoRA)
16
+
17
+ Qwen/Qwen2.5-Coder-7B-Instruct fine-tuned for Verilog/SystemVerilog generation from a natural-language
18
+ spec (optionally with the module interface). Code, data pipeline, and evaluation harness:
19
+ [https://github.com/Henil-08/verilog-coder-ft](https://github.com/Henil-08/verilog-coder-ft).
20
+
21
+ ## Training data
22
+
23
+ [OpenRTLSet](https://huggingface.co/datasets/ESCAD/OpenRTLSet): 131k Verilog modules from
24
+ GitHub, each paired with an LLM-written description. After dropping 54.6k fuzzer-generated
25
+ modules, deduplicating, and capping examples at 2048 tokens, 53.7k remain; this run used
26
+ 40,000 of them (~93% Verilog, ~7% SystemVerilog). About 30% of
27
+ training prompts describe the ports in prose instead of giving the header as code, which
28
+ keeps the model usable when no header is provided.
29
+
30
+ The raw corpus contains UVM testbench code in only 3 rows, and none of them survive
31
+ filtering. This model was not trained or evaluated on UVM and makes no claim of UVM
32
+ capability.
33
+
34
+ ## Training setup
35
+
36
+ - Method: LoRA, 1 epoch, 29,906,052 supervised tokens
37
+ - LoRA rank 64, alpha 128, dropout 0.05, targets: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
38
+ - LR 0.0001 (cosine, 3% warmup), effective batch 64, max length 2048, bf16
39
+ - HF Transformers + PEFT + DeepSpeed ZeRO-2 on 1× H100 (Modal);
40
+ 79 min of training, ~$5.37
41
+ - Loss on the code (assistant) tokens only; final eval loss 0.2653
42
+ - Selected among LoRA/QLoRA/full-fine-tune configs by pass@1 on a validation split, so the
43
+ test numbers below were not used for model selection.
44
+
45
+ ## Evaluation (pass@1, greedy decoding)
46
+
47
+ | Benchmark | Base | Fine-tuned | Items gained / lost |
48
+ |---|---|---|---|
49
+ | OpenRTLSet held-out (diff-sim) | 33.2% (131/394, 95% CI 28.8–38.0) | 46.5% (183/394, 95% CI 41.6–51.4) | +59 / -7 (McNemar p<0.001) |
50
+ | VerilogEval v2 spec-to-RTL (published prompts) | 31.4% (49/156, 95% CI 24.6–39.1) | 23.7% (37/156, 95% CI 17.7–31.0) | +10 / -22 (McNemar p=0.050) |
51
+ | VerilogEval v2 + interface code block | 38.5% (60/156, 95% CI 31.2–46.3) | 28.8% (45/156, 95% CI 22.3–36.4) | +9 / -24 (McNemar p=0.013) |
52
+
53
+ - **OpenRTLSet held-out**: 394 standalone modules not seen in training. A generated module
54
+ passes if it matches the reference's ports and its outputs equal the reference's on every
55
+ half-cycle of 500 cycles of random stimulus (Verilator). Random stimulus is evidence of
56
+ equivalence, not proof.
57
+ - **VerilogEval v2**: the official testbenches and Icarus Verilog v12 pass rule, with this
58
+ project's chat prompt (scores are not directly comparable to leaderboard numbers that use
59
+ other prompts).
60
+
61
+ ## Limitations
62
+
63
+ - **On VerilogEval this fine-tune scores below its base model** (23.7% vs 31.4% with the published prompts). Fine-tuning on OpenRTLSet's real-world modules and LLM-written descriptions improved held-out OpenRTLSet modules but cost accuracy on VerilogEval's textbook-style problems; for that style of task the base model is the better choice.
64
+ - Greedy decoding sometimes falls into repetition loops on long modules; about
65
+ 13% of eval outputs hit the 2048-token cap.
66
+ - Trained on single-module completions; multi-module designs and testbenches are out of
67
+ scope. Not evaluated for synthesis quality, timing, or area.
68
+
69
+ ## Usage
70
+
71
+ ```python
72
+ from transformers import AutoModelForCausalLM, AutoTokenizer
73
+ tok = AutoTokenizer.from_pretrained("henil08/verilog-coder-7b")
74
+ model = AutoModelForCausalLM.from_pretrained("henil08/verilog-coder-7b", dtype="auto", device_map="auto")
75
+ ```
76
+
77
+ Prompt format (system + user), as in training:
78
+
79
+ ```text
80
+ Specification:
81
+ <description>
82
+
83
+ Module interface:
84
+ ```verilog
85
+ module ...(...);
86
+ ```
87
+ ```
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 151643,
7
+ "dtype": "bfloat16",
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 3584,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 18944,
13
+ "layer_types": [
14
+ "full_attention",
15
+ "full_attention",
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention"
42
+ ],
43
+ "max_position_embeddings": 32768,
44
+ "max_window_layers": 28,
45
+ "model_type": "qwen2",
46
+ "num_attention_heads": 28,
47
+ "num_hidden_layers": 28,
48
+ "num_key_value_heads": 4,
49
+ "pad_token_id": null,
50
+ "rms_norm_eps": 1e-06,
51
+ "rope_parameters": {
52
+ "rope_theta": 1000000.0,
53
+ "rope_type": "default"
54
+ },
55
+ "sliding_window": null,
56
+ "tie_word_embeddings": false,
57
+ "transformers_version": "5.20.1",
58
+ "use_cache": true,
59
+ "use_sliding_window": false,
60
+ "vocab_size": 152064
61
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "repetition_penalty": 1.1,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "5.20.1"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35e6b03404c6c96308f2e36fe47ae80f909d72c4515637732181414d9be33ce8
3
+ size 15231272152
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
3
+ size 11421892
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": true,
24
+ "local_files_only": false,
25
+ "model_max_length": 32768,
26
+ "pad_token": "<|endoftext|>",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }