miange commited on
Commit
804fbca
1 Parent(s): c760666

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -12
README.md CHANGED
@@ -101,19 +101,14 @@ The XVERSE-13B-256K model can be loaded for chat using the following code:
101
  ```python
102
  import torch
103
  from transformers import AutoTokenizer, AutoModelForCausalLM
104
- from transformers.generation.utils import GenerationConfig
105
- model_path = "xverse/XVERSE-13B-256K"
106
- tokenizer = AutoTokenizer.from_pretrained(model_path)
107
- model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto')
108
- model.generation_config = GenerationConfig.from_pretrained(model_path)
109
  model = model.eval()
110
- history = [{"role": "user", "content": "1955年谁是美国总统?他是什么党派?"}]
111
- response = model.chat(tokenizer, history)
112
- print(response)
113
- history.append({"role": "assistant", "content": response})
114
- history.append({"role": "user", "content": "他任职了多少年"})
115
- response = model.chat(tokenizer, history)
116
- print(response)
117
  ```
118
 
119
  更多细节,包括对话 demo 、模型微调及量化等,请参考我们的[Github](https://github.com/xverse-ai/XVERSE-13B)。
 
101
  ```python
102
  import torch
103
  from transformers import AutoTokenizer, AutoModelForCausalLM
104
+ tokenizer = AutoTokenizer.from_pretrained("xverse/XVERSE-13B-256K")
105
+ model = AutoModelForCausalLM.from_pretrained("xverse/XVERSE-13B-256K", trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto')
 
 
 
106
  model = model.eval()
107
+ inputs = tokenizer('北京的景点:故宫、天坛、万里长城等。\n深圳的景点:', return_tensors='pt').input_ids
108
+ inputs = inputs.cuda()
109
+ generated_ids = model.generate(inputs, max_new_tokens=64, eos_token_id=tokenizer.eos_token_id, repetition_penalty=1.1)
110
+ print(tokenizer.batch_decode(generated_ids, skip_special_tokens=True))
111
+
 
 
112
  ```
113
 
114
  更多细节,包括对话 demo 、模型微调及量化等,请参考我们的[Github](https://github.com/xverse-ai/XVERSE-13B)。