-
Notifications
You must be signed in to change notification settings - Fork 0
/
llm_testing.py
48 lines (24 loc) · 1.84 KB
/
llm_testing.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
41
42
43
44
45
46
47
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name='KoboldAI/OPT-6.7B-Erebus'
tokenizer = AutoTokenizer.from_pretrained(model_name, cache_dir='cache')
model = AutoModelForCausalLM.from_pretrained(model_name, cache_dir='cache')
model.to('cuda')
string = "When my flight landed in China, I converted my currency and slowly fell asleep. (I had a terrifying dream about my grandmother, but that’s a story for another time). I was staying in the capital city, "
full_ids = tokenizer(string, return_tensors="pt")["input_ids"].cuda()
model_prediction_full = tokenizer.decode(
model.generate(full_ids[:, :-1], max_length=full_ids.shape[1]+1, do_sample=False)[0])
print(model_prediction_full)
string = "When my flight landed in China, I converted my currency and slowly fell asleep. (I had a terrifying dream about my grandmother, but that’s a story for another time). I was staying in the capital city, Beijing."
full_ids = tokenizer(string, return_tensors="pt")["input_ids"].cuda()
model_prediction_full = tokenizer.decode(
model.generate(full_ids[:, :-1], max_length=full_ids.shape[1], do_sample=False)[0])
print(model_prediction_full)
string = "When my flight landed in China, I converted my currency and slowly fell asleep. (I had a terrifying dream about my grandmother, but that’s a story for another time). I was staying in the capital, "
full_ids = tokenizer(string, return_tensors="pt")["input_ids"].cuda()
model_prediction_full = tokenizer.decode(
model.generate(full_ids[:, :-1], max_length=full_ids.shape[1]+2, do_sample=False)[0])
print(model_prediction_full)
model_prediction_full = tokenizer.decode(
model.generate(full_ids[:, :-1], max_length=full_ids.shape[1]+1, do_sample=False)[0])
print(model_prediction_full)