lSiddharthl commited on
Commit
7629d53
1 Parent(s): 8755e6c
Files changed (1) hide show
  1. phi2.py +16 -0
phi2.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ torch.set_default_device("cuda")
5
+
6
+ model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", trust_remote_code=True)
7
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
8
+
9
+ inputs = tokenizer('''def print_prime(n):
10
+ """
11
+ Print all primes between 1 and n
12
+ """''', return_tensors="pt", return_attention_mask=False)
13
+
14
+ outputs = model.generate(**inputs, max_length=200)
15
+ text = tokenizer.batch_decode(outputs)[0]
16
+ print(text)