yuyijiong commited on
Commit
609c1a1
1 Parent(s): 99c3b1b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -0
README.md CHANGED
@@ -15,5 +15,41 @@ pipeline_tag: text-generation
15
  | LongAlpaca-7b-32k-chinese | atom-7b | 8k->32k PI | 指令微调 | 长度32k以内的多文档问答、论文总结、论文问答、sharegpt数据 |
16
  | LongAlpaca-7b-32k-chinese-v2 | CausalLM-7b | 8k->32k Yarn | 增量预训练+指令微调 |长度32k的中文预训练数据 + 长度32k以内的多文档多轮问答、论文多任务多轮问答、sharegpt、中英翻译数据 |
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
 
15
  | LongAlpaca-7b-32k-chinese | atom-7b | 8k->32k PI | 指令微调 | 长度32k以内的多文档问答、论文总结、论文问答、sharegpt数据 |
16
  | LongAlpaca-7b-32k-chinese-v2 | CausalLM-7b | 8k->32k Yarn | 增量预训练+指令微调 |长度32k的中文预训练数据 + 长度32k以内的多文档多轮问答、论文多任务多轮问答、sharegpt、中英翻译数据 |
17
 
18
+ ## 使用方法:
19
+ ```python
20
+ from transformers import AutoModelForCausalLM, AutoTokenizer
21
+ from transformers.generation import GenerationConfig
22
+ import os
23
+ os.environ["CUDA_VISIBLE_DEVICES"] = "0"
24
+
25
+ model_path="yuyijiong/LongAlpaca-7b-32k-chinese"
26
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
27
+
28
+ # use auto mode, automatically select precision based on the device.
29
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", load_in_8bit=True, trust_remote_code=True).eval()
30
+
31
+
32
+ question="中国的首都是什么?"
33
+ input_text = "<|im_start|>user\n" + question + "<|im_end|>\n" + "<|im_start|>assistant\n"
34
+ input_ids = tokenizer(input_text, return_tensors='pt').input_ids.to(model.device)
35
+
36
+ with torch.no_grad():
37
+
38
+ with torch.autocast('cuda'):
39
+ output = model.generate(input_ids=input_ids,
40
+ max_new_tokens=max_new_tokens,
41
+ do_sample=True,
42
+ temperature=0.85,
43
+ top_k=None,
44
+ top_p=0.9,
45
+ use_cache=True,
46
+ eos_token_id=[tokenizer.convert_tokens_to_ids('<|im_end|>') , tokenizer.convert_tokens_to_ids('<|endoftext|>')]
47
+ **kwargs)
48
+
49
+ reply = tokenizer.decode(output[0], skip_special_tokens=False)
50
+ reply_return=reply.split('<|im_start|>assistant\n')[-1]
51
+
52
+ print('模型回答:', reply_return)
53
+ ```
54
 
55