Commit
·
249613c
1
Parent(s):
f30ef71
Initial
Browse files
README.md
CHANGED
@@ -50,19 +50,58 @@ please read the [CONTRIBUTING](CONTRIBUTING.md) first._
|
|
50 |
#### Hugging Face
|
51 |
|
52 |
```python
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
```
|
67 |
|
68 |
---
|
|
|
50 |
#### Hugging Face
|
51 |
|
52 |
```python
|
53 |
+
import torch
|
54 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
55 |
+
|
56 |
+
model_name = "bunyaminergen/Qwen2.5-Coder-1.5B-Instruct-SFT"
|
57 |
+
|
58 |
+
quant_config = BitsAndBytesConfig(
|
59 |
+
load_in_4bit=True,
|
60 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
61 |
+
bnb_4bit_use_double_quant=True,
|
62 |
+
bnb_4bit_quant_type="nf4"
|
63 |
+
)
|
64 |
+
|
65 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
66 |
+
|
67 |
+
model = AutoModelForCausalLM.from_pretrained(
|
68 |
+
model_name,
|
69 |
+
quantization_config=quant_config,
|
70 |
+
device_map="auto"
|
71 |
+
)
|
72 |
+
|
73 |
+
model.eval()
|
74 |
+
|
75 |
+
messages = [
|
76 |
+
{"role": "system", "content": "You are a senior Python developer."},
|
77 |
+
{"role": "user", "content": "Give me a quick example of bubble sort in Python."}
|
78 |
+
]
|
79 |
+
|
80 |
+
prompt = tokenizer.apply_chat_template(
|
81 |
+
messages,
|
82 |
+
tokenize=False,
|
83 |
+
add_generation_prompt=True
|
84 |
+
)
|
85 |
+
|
86 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
87 |
+
|
88 |
+
max_new_tokens = 512
|
89 |
+
temperature = 0.9
|
90 |
+
|
91 |
+
with torch.no_grad():
|
92 |
+
outputs = model.generate(
|
93 |
+
**inputs,
|
94 |
+
max_new_tokens=max_new_tokens,
|
95 |
+
temperature=temperature,
|
96 |
+
do_sample=True,
|
97 |
+
top_p=0.95,
|
98 |
+
eos_token_id=tokenizer.eos_token_id,
|
99 |
+
pad_token_id=tokenizer.eos_token_id
|
100 |
+
)
|
101 |
+
|
102 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
103 |
+
|
104 |
+
print(result)
|
105 |
```
|
106 |
|
107 |
---
|