-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphi15.py
More file actions
27 lines (20 loc) · 787 Bytes
/
phi15.py
File metadata and controls
27 lines (20 loc) · 787 Bytes
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
import torch
import time
from transformers import AutoModelForCausalLM, AutoTokenizer
def markTime(start,msg):
print(f"{msg} {time.time() - start}")
start=time.time()
torch.set_default_device("cuda")
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1_5", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5", trust_remote_code=True)
markTime(start,"load model")
inputs = tokenizer('''def fizzbuzz:
"""
print fizzbuzz algorithm recipe given number n
"""
"""''', return_tensors="pt", return_attention_mask=False)
outputs = model.generate(**inputs, max_length=200)
markTime(start,"generate")
text = tokenizer.batch_decode(outputs)[0]
markTime(start,"decode")
print(f"Total time: {time.time() - start}")