-
Notifications
You must be signed in to change notification settings - Fork 417
/
Copy pathgenerate.py
executable file
·37 lines (31 loc) · 978 Bytes
/
generate.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
import os
import torch
from flagai.auto_model.auto_loader import AutoLoader
from flagai.data.tokenizer import Tokenizer
from flagai.model.predictor.predictor import Predictor
import bminf
state_dict = "./checkpoints_in/"
model_name = 'aquila-7b'
loader = AutoLoader("lm",
model_dir=state_dict,
model_name=model_name,
use_cache=True,
device='cuda',
fp16=True)
model = loader.get_model()
tokenizer = loader.get_tokenizer()
model.eval()
model.cuda()
texts = [
"汽车EDR是什么",
]
predictor = Predictor(model, tokenizer)
for text in texts:
print('-' * 80)
text = f'{text}'
print(f"text is {text}")
with torch.no_grad():
out = predictor.predict_generate_randomsample(text,
out_max_length=200,
top_p=0.95)
print(f"pred is {out}")