TabCanNotTab commited on
Commit
99de67c
·
verified ·
1 Parent(s): 03d658f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +66 -0
README.md ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Example
2
+ ```python
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import torch
5
+ import re
6
+
7
+ model_name = "TabCanNotTab/SALV-Qwen2.5-Coder-7B-Instruct"
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ model_name,
10
+ torch_dtype=torch.bfloat16,
11
+ device_map="auto",
12
+ )
13
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
14
+
15
+ prompt = """
16
+ Please act as a professional verilog designer.
17
+
18
+ Implement a module of an 8-bit adder with multiple bit-level adders in combinational logic.
19
+
20
+ Module name:
21
+ adder_8bit
22
+ Input ports:
23
+ a[7:0]: 8-bit input operand A.
24
+ b[7:0]: 8-bit input operand B.
25
+ cin: Carry-in input.
26
+ Output ports:
27
+ sum[7:0]: 8-bit output representing the sum of A and B.
28
+ cout: Carry-out output.
29
+
30
+ Implementation:
31
+ The module utilizes a series of bit-level adders (full adders) to perform the addition operation.
32
+
33
+ Give me the complete code.
34
+ """
35
+
36
+ messages = [
37
+ {"role": "system", "content": "You are a helpful assistant."},
38
+ {"role": "user", "content": prompt}
39
+ ]
40
+
41
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
42
+ model_inputs = tokenizer(text, return_tensors="pt").to(model.device)
43
+
44
+ # inference
45
+ outputs = model.generate(
46
+ **model_inputs,
47
+ max_new_tokens=2048,
48
+ do_sample=True,
49
+ temperature=0.5,
50
+ top_p=0.95
51
+ )
52
+
53
+ # get response text
54
+ input_length = model_inputs.input_ids.shape[1]
55
+ generated_tokens = outputs[0][input_length:]
56
+ response = tokenizer.decode(generated_tokens, skip_special_tokens=True)
57
+
58
+ # get code text
59
+ pattern = r"```verilog\s*(.*?)\s*```"
60
+ matches = re.findall(pattern, response, re.DOTALL)
61
+ if matches:
62
+ code=matches[-1]
63
+ print(code)
64
+ else:
65
+ print("No Verilog code found in the response!")
66
+ ```