BAAI
/

shunxing1234 commited on
Commit
e77ef02
1 Parent(s): 265f599

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -0
README.md CHANGED
@@ -35,9 +35,32 @@ We will continue to release improved versions of Aquila model as open source. Fo
35
 
36
  ### 1. Inference
37
 
 
 
 
 
38
 
 
 
 
 
 
 
39
 
 
40
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
  ## License
 
35
 
36
  ### 1. Inference
37
 
38
+ ```python
39
+ from transformers import AutoTokenizer, AutoModelForCausalLM
40
+ import torch
41
+ from cyg_conversation import covert_prompt_to_input_ids_with_history
42
 
43
+ tokenizer = AutoTokenizer.from_pretrained("BAAI/AquilaChat-7B")
44
+ model = AutoModelForCausalLM.from_pretrained("BAAI/AquilaChat-7B")
45
+ model.eval()
46
+ model.to("cuda:0")
47
+ vocab = tokenizer.vocab
48
+ print(len(vocab))
49
 
50
+ text = "请给出10个要到北京旅游的理由。"
51
 
52
+ tokens = covert_prompt_to_input_ids_with_history(text, history=[], tokenizer=tokenizer, max_token=512)
53
+
54
+ tokens = torch.tensor(tokens)[None,].to("cuda:0")
55
+
56
+
57
+ with torch.no_grad():
58
+ out = model.generate(tokens, do_sample=True, max_length=512, eos_token_id=100007)[0]
59
+
60
+ out = tokenizer.decode(out.cpu().numpy().tolist())
61
+
62
+ print(out)
63
+ ```
64
 
65
 
66
  ## License