Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Phi-2-super (SFT + cDPO)
|
2 |
+
|
3 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/62ceeb27e7f6014c0e9d9268/5-LQCMrXi8FN_ewcWL47v.png)
|
4 |
+
|
5 |
+
How to run inference:
|
6 |
+
```python
|
7 |
+
import transformers
|
8 |
+
import torch
|
9 |
+
|
10 |
+
if __name__ == "__main__":
|
11 |
+
model_name = "abacaj/phi-2-super"
|
12 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
|
13 |
+
|
14 |
+
model = (
|
15 |
+
transformers.AutoModelForCausalLM.from_pretrained(
|
16 |
+
model_name,
|
17 |
+
)
|
18 |
+
.to("cuda:0")
|
19 |
+
.eval()
|
20 |
+
)
|
21 |
+
|
22 |
+
messages = [
|
23 |
+
{"role": "user", "content": "Hello, who are you?"}
|
24 |
+
]
|
25 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
|
26 |
+
input_ids_cutoff = inputs.size(dim=1)
|
27 |
+
|
28 |
+
with torch.no_grad():
|
29 |
+
generated_ids = model.generate(
|
30 |
+
input_ids=inputs,
|
31 |
+
use_cache=True,
|
32 |
+
max_new_tokens=512,
|
33 |
+
temperature=0.2,
|
34 |
+
top_p=0.95,
|
35 |
+
do_sample=True,
|
36 |
+
eos_token_id=tokenizer.eos_token_id,
|
37 |
+
pad_token_id=tokenizer.pad_token_id,
|
38 |
+
)
|
39 |
+
|
40 |
+
completion = tokenizer.decode(
|
41 |
+
generated_ids[0][input_ids_cutoff:],
|
42 |
+
skip_special_tokens=True,
|
43 |
+
)
|
44 |
+
|
45 |
+
print(completion)
|
46 |
+
```
|