iKING-ROC commited on
Commit
9b242cd
·
1 Parent(s): 4d62730

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +173 -0
README.md ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: chinese-alpaca-plus-7b
3
+ emoji: 📚
4
+ colorFrom: gray
5
+ colorTo: red
6
+ language:
7
+ - zh
8
+ tags:
9
+ - chatglm
10
+ - pytorch
11
+ - zh
12
+ - Text2Text-Generation
13
+ license: "other"
14
+ widget:
15
+ - text: "为什么天空是蓝色的?"
16
+ ---
17
+
18
+ # Chinese Alpaca Plus 7B Model
19
+
20
+ **发布中文LLaMA, Alpaca Plus版(7B)模型**
21
+
22
+
23
+ 推出中文LLaMA, Alpaca Plus版(7B),相比基础版本的改进点如下:
24
+
25
+ - 进一步扩充了训练数据,其中LLaMA扩充至120G文本(通用领域),Alpaca扩充至4M指令数据(重点增加了STEM相关数据)
26
+ - Alpaca训练时采用了更大的rank,相比原版具有更低的验证集损失
27
+ - 评测结果显示,Alpaca-Plus-7B相比基础版Alpaca-7B效果更优,部分任务接近或超过13B版本
28
+ - 这一轮比拼:7B获得65.3分,13B获得70.9分,Plus-7B效果75.3分,具体评测结果请参考[效果评测](https://github.com/ymcui/Chinese-LLaMA-Alpaca/blob/main/examples/README.md)
29
+
30
+ 本模型是`原生LLaMA-7B`合并`中文LLaMA LoRA`和`中文Alpaca LoRA`后的模型权重`chinese-alpaca-plus-7b-hf`,并转化为HuggingFace版本权重(.bin文件),可以直接使用或者继续训练。
31
+
32
+ 13b-hf权重链接:https://huggingface.co/shibing624/chinese-alpaca-plus-13b-hf
33
+
34
+ test case:
35
+
36
+ |input_text|predict|
37
+ |:-- |:--- |
38
+ |为什么天空是蓝色的?|天空是蓝色的,是因为大气层中的气体分子会散射太阳光中的蓝色光,使得我们看到的天空是蓝色的。|
39
+
40
+
41
+ ## release model weight
42
+
43
+ - chinese-llama-plus-7b 模型权重链接:https://huggingface.co/minlik/chinese-llama-plus-7b-merged
44
+ - chinese-alpaca-plus-7b 模型权重链接:https://huggingface.co/shibing624/chinese-alpaca-plus-7b-hf
45
+ - chinese-llama-plus-13b 模型权重链接:https://huggingface.co/shibing624/chinese-llama-plus-13b-hf
46
+ - chinese-aplaca-plus-13b 模型权重链接:https://huggingface.co/shibing624/chinese-alpaca-plus-13b-hf
47
+
48
+ ## Usage
49
+
50
+ 本项目开源在textgen项目:[textgen](https://github.com/shibing624/textgen),可支持llama模型,通过如下命令调用:
51
+
52
+ Install package:
53
+ ```shell
54
+ pip install -U textgen
55
+ ```
56
+
57
+ ```python
58
+ from textgen import LlamaModel
59
+ model = LlamaModel("llama", "shibing624/chinese-alpaca-plus-7b-hf")
60
+ r = model.predict(["用一句话描述地球为什么是独一无二的。"])
61
+ print(r) # ['地球是独一无二的,因为它拥有独特的大气层、水循环、生物多样性以及其他自然资源,这些都使它成为一个独特的生命支持系统。']
62
+ ```
63
+
64
+ ## Usage (HuggingFace Transformers)
65
+ Without [textgen](https://github.com/shibing624/textgen), you can use the model like this:
66
+
67
+ First, you pass your input through the transformer model, then you get the generated sentence.
68
+
69
+ Install package:
70
+ ```
71
+ pip install sentencepiece
72
+ pip install transformers>=4.28.0
73
+ ```
74
+
75
+ ```python
76
+ import torch
77
+ import transformers
78
+ from transformers import LlamaTokenizer, LlamaForCausalLM
79
+
80
+ def generate_prompt(text):
81
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
82
+
83
+ ### Instruction:
84
+ {text}
85
+
86
+ ### Response:"""
87
+
88
+
89
+ tokenizer = LlamaTokenizer.from_pretrained('shibing624/chinese-alpaca-plus-7b-hf')
90
+ model = LlamaForCausalLM.from_pretrained('shibing624/chinese-alpaca-plus-7b-hf').half().cuda()
91
+ model.eval()
92
+
93
+ text = '为什么天空是蓝色的?'
94
+ prompt = generate_prompt(text)
95
+ input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
96
+
97
+
98
+ with torch.no_grad():
99
+ output_ids = model.generate(
100
+ input_ids=input_ids,
101
+ max_new_tokens=128,
102
+ temperature=1,
103
+ top_k=40,
104
+ top_p=0.9,
105
+ repetition_penalty=1.15
106
+ ).cuda()
107
+ output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
108
+ print(output.replace(text, '').strip())
109
+ ```
110
+
111
+
112
+ output:
113
+ ```shell
114
+ 为什么天空是蓝色的?
115
+ 天空是蓝色的,是因为大气层中的气体分子会散射太阳光中的蓝色光,使得我们看到的天空是蓝色的。
116
+ ```
117
+
118
+ ## 模型来源
119
+ release合并后的模型权重,一步到位直接使用,省电、减少碳排放。
120
+
121
+ 基于 [多LoRA权重合并(适用于Chinese-Alpaca-Plus )](https://github.com/ymcui/Chinese-LLaMA-Alpaca/wiki/%E6%89%8B%E5%8A%A8%E6%A8%A1%E5%9E%8B%E5%90%88%E5%B9%B6%E4%B8%8E%E8%BD%AC%E6%8D%A2#%E5%A4%9Alora%E6%9D%83%E9%87%8D%E5%90%88%E5%B9%B6%E9%80%82%E7%94%A8%E4%BA%8Echinese-alpaca-plus-)方法手动合并而成,具体是使用 [decapoda-research/llama-7b-hf](https://huggingface.co/decapoda-research/llama-7b-hf)
122
+ 底座模型 合并 Chinese-LLaMA-Plus-LoRA和Chinese-Alpaca-Plus-LoRA 两个LoRA权重 得到,并转化为HuggingFace版本权重(.bin文件)。
123
+
124
+
125
+ HuggingFace版本权重(.bin文件)可用于:
126
+ - 使用Transformers进行训练和推理
127
+ - 使用text-generation-webui搭建界面
128
+
129
+ PyTorch版本权重(.pth文件)可用于:
130
+ - 使用llama.cpp工具进行量化和部署
131
+
132
+ PyTorch版本权重(.pth文件)链接,8-bit量化版的Alpaca-Plus-7B:[Billsfriend/chinese-Alpaca-7b-plus-ggml-q8_0](https://huggingface.co/Billsfriend/chinese-Alpaca-7b-plus-ggml-q8_0/tree/main)
133
+
134
+
135
+ 模型文件组成:
136
+ ```
137
+ chinese-alpaca-plus-7b-hf
138
+ config.json
139
+ generation_config.json
140
+ pytorch_model-00001-of-00002.bin
141
+ pytorch_model-00002-of-00002.bin
142
+ pytorch_model.bin.index.json
143
+ special_tokens_map.json
144
+ tokenizer.json
145
+ tokenizer.model
146
+ tokenizer_config.json
147
+ ```
148
+
149
+ 硬件要求:14G显存
150
+
151
+ ### 微调数据集
152
+
153
+ 1. xx万条文本数据集(用于领域内预训练):[DUOMO-Lab/TransGPT-pt](https://huggingface.co/datasets/DUOMO-Lab/TransGPT-pt)
154
+ 2.
155
+
156
+
157
+ 如果需要训练LLaMA模型,请参考[https://github.com/DUOMO/TransGPT](https://github.com/DUOMO/TransGPT)
158
+
159
+
160
+ ## Citation
161
+
162
+ ```latex
163
+ @software{TransGPT,
164
+ author = {Wang Peng},
165
+ title = {DUOMO/TransGPT},
166
+ year = {2023},
167
+ url = {https://github.com/DUOMO/TransGPT},
168
+ }
169
+ ```
170
+
171
+
172
+ ## Reference
173
+ - https://github.com/shibing624/textgen