-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
40 lines (29 loc) · 930 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Phi 2 Inference.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1qGlsJwf-rAF06cTMJU56iM9z3k_HZngS
"""
"""## Tokenizer and Model Prep"""
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained(
"microsoft/phi-2",
trust_remote_code = True
)
model = AutoModelForCausalLM.from_pretrained(
"microsoft/phi-2",
torch_dtype = "auto",
device_map = "auto",
trust_remote_code = True
)
prompt = """Give me a list of 13 words that have 9 letters."""
with torch.no_grad():
token_ids = tokenizer.encode(prompt, add_special_tokens=False ,return_tensors="pt")
output_ids = model.generate(
token_ids.to(model.device),
max_new_tokens=512,
do_sample=True,
temperature = 0.3
)
output = tokenizer.decode(output_ids[0][token_ids.size(1) :])
print(output)