初始化项目,由ModelHub XC社区提供模型
Model: BAAI/AquilaChat-7B Source: Original Platform
This commit is contained in:
23
chat_test.py
Normal file
23
chat_test.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#If you need to use this code, please install the following transformers
|
||||
#https://github.com/shunxing1234/transformers
|
||||
from transformers import AutoTokenizer, AquilaForCausalLM
|
||||
import torch
|
||||
from cyg_conversation import default_conversation, covert_prompt_to_input_ids_with_history
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained("BAAI/AquilaChat-7B")
|
||||
model = AquilaForCausalLM.from_pretrained("BAAI/AquilaChat-7B")
|
||||
model.eval()
|
||||
model.to("cuda:4")
|
||||
vocab = tokenizer.vocab
|
||||
print(len(vocab))
|
||||
|
||||
text = "请给出10个要到北京旅游的理由。"
|
||||
|
||||
tokens = covert_prompt_to_input_ids_with_history(text, history=[], tokenizer=tokenizer, max_token=512)
|
||||
|
||||
tokens = torch.tensor(tokens)[None,].to("cuda:4")
|
||||
|
||||
out = model.generate(tokens, do_sample=True, max_length=512, eos_token_id=100007)[0]
|
||||
out = tokenizer.decode(out.cpu().numpy().tolist())
|
||||
|
||||
print(out)
|
||||
Reference in New Issue
Block a user