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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- zh
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- codeshell
|
| 7 |
+
- wisdomshell
|
| 8 |
+
- pku-kcl
|
| 9 |
+
- openbankai
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
## Introduction
|
| 13 |
+
|
| 14 |
+
Shell是[蚌壳智能](https://openbankai.com/)联合[北京大学知识计算实验室](http://se.pku.edu.cn/kcl/)在代码大模型[CodeShell](https://github.com/WisdomShell/codeshell)基础上训练的预训练通用大模型。本仓库为Shell-7B预训练模型仓库。
|
| 15 |
+
|
| 16 |
+
Shell在保留Codeshell优异的代码能力的同时,具有以下特性:
|
| 17 |
+
|
| 18 |
+
- **更全面的通用能力**:Shell在Codeshell的基础上继续预训练了1.5 T token的中英文语料,通用能力大幅提升。在语言、知识、推理等评测中,Shell均取得了优异的性能。
|
| 19 |
+
- **依旧强大的代码能力**:Shell在继续预训练的过程中,保留了20%高质量代码数据,使得Shell在获得通用能力的同时,依旧保留了CodeShell强大的代码能力。
|
| 20 |
+
- **更强大的语义理解能力**:Shell在继承Codeshell优异代码能力的同时,形成了强大的语义理解能力。相比LLaMA2-7B,Shell在RACE-Middle (+102%)、RACE-High(+98%)、OpenbookQA(+42%)等多个语义理解数据集取得更好的性能,达到同等规模开源大模型的领先水平。
|
| 21 |
+
|
| 22 |
+
本次我们同时发布了Shell-7B的base版本和chat版本,大家可以根据自身需求选择对应的模型。
|
| 23 |
+
|
| 24 |
+
- **Shell-7B-Base**:具有强大语义理解能力的通用大模型,大家可以基于该模型微调自己的大模型。
|
| 25 |
+
- **Shell-7B-Chat**:在Shell-7B-Base微调得到的对话预训练模型,直接下载使用即可获得流畅的对话体验。
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## Performance
|
| 29 |
+
|
| 30 |
+
我们共选取了16个经典数据集对Shell进行了全面评测,评测脚本详见[模型评测](https://github.com/WisdomShell/shell/edit/main/evaluation/README.md)。具体评测结果如下。
|
| 31 |
+
| Dataset | Baichuan2-7B-Base | LLaMA-2-7B | Shell-7B |
|
| 32 |
+
| ------------ | ----------------- | ---------- | -------- |
|
| 33 |
+
| C-Eval | 56.3 | 32.5 | 50.13 |
|
| 34 |
+
| AGIEval | 34.6 | 21.8 | 30.69 |
|
| 35 |
+
| MMLU | 54.7 | 46.8 | 49.49 |
|
| 36 |
+
| CMMLU | 57 | 31.8 | 50.4 |
|
| 37 |
+
| GAOKAO-Bench | 34.8 | 18.9 | 33 |
|
| 38 |
+
| WiC | 50 | 50 | 50.47 |
|
| 39 |
+
| CHID | 82.7 | 46.5 | 83.17 |
|
| 40 |
+
| AFQMC | 58.4 | 69 | 69 |
|
| 41 |
+
| WSC | 66.3 | 66.3 | 63.46 |
|
| 42 |
+
| RACE(Middle) | 50.9 | 40.2 | 82.66 |
|
| 43 |
+
| RACE(High) | 52.5 | 37.5 | 74.24 |
|
| 44 |
+
| OpenbookQA | 32.8 | 57 | 79 |
|
| 45 |
+
| GSM8K | 24.6 | 16.7 | 20.7 |
|
| 46 |
+
| HumanEval | 17.7 | 12.8 | 23.96 |
|
| 47 |
+
| MBPP | 24 | 14.8 | 31.4 |
|
| 48 |
+
| BBH | 41.8 | 38.2 | 38.16 |
|
| 49 |
+
|
| 50 |
+
## Requirements
|
| 51 |
+
|
| 52 |
+
- python 3.8 and above
|
| 53 |
+
- pytorch 2.0 and above are recommended
|
| 54 |
+
- transformers 4.32 and above
|
| 55 |
+
- CUDA 11.8 and above are recommended (this is for GPU users, flash-attention users, etc.)
|
| 56 |
+
|
| 57 |
+
## Quickstart
|
| 58 |
+
|
| 59 |
+
Shell系列模型已经上传至 <a href="https://huggingface.co/WisdomShell/CodeShell" target="_blank">Hugging Face</a>,开发者可以通过Transformers快速调用Shell-7B和Shell-Chat-7B。
|
| 60 |
+
|
| 61 |
+
在开始之前,请确保已经正确设置了环境,并安装了必要的代码包,以及满足上一小节的环境要求。你可以通过下列代码快速安装相关依赖。
|
| 62 |
+
|
| 63 |
+
```
|
| 64 |
+
pip install -r requirements.txt
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
接下来你可以通过Transformers使用Shell。
|
| 68 |
+
|
| 69 |
+
### 加载Shell-7B-Base
|
| 70 |
+
|
| 71 |
+
您可以通过Transformers加载Shell-7B-Base模型,Shell-7B-Base具备生成流畅自然语言的能力,您可以通过`generate`方法让模型生成相关的文字。
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
import torch
|
| 75 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 76 |
+
|
| 77 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 78 |
+
tokenizer = AutoTokenizer.from_pretrained("WisdomShell/Shell-7B-Base")
|
| 79 |
+
model = AutoModelForCausalLM.from_pretrained("WisdomShell/Shell-7B-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).to(device)
|
| 80 |
+
inputs = tokenizer('你好', return_tensors='pt').to(device)
|
| 81 |
+
outputs = model.generate(**inputs)
|
| 82 |
+
print(tokenizer.decode(outputs[0]))
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### 加载Shell-7B-Chat
|
| 86 |
+
|
| 87 |
+
类似的,您可以通过Transformers加载Shell-7B-Chat模型,并通过`chat`方法与其进行对话。
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
import torch
|
| 91 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 92 |
+
|
| 93 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 94 |
+
tokenizer = AutoTokenizer.from_pretrained("WisdomShell/Shell-7B-Chat")
|
| 95 |
+
model = AutoModelForCausalLM.from_pretrained("WisdomShell/Shell-7B-Chat", trust_remote_code=True, torch_dtype=torch.bfloat16).to(device)
|
| 96 |
+
history = []
|
| 97 |
+
output = model.chat('你是谁', history, tokenizer)
|
| 98 |
+
print(output)
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
### Shell in c/c++
|
| 102 |
+
|
| 103 |
+
由于大部分个人电脑没有GPU,Shell提供了C/C++版本的推理支持,开发者可以根据本地环境进行编译与使用,详见[CodeShell C/C++本地化版](https://github.com/WisdomShell/llama_cpp_for_codeshell)。
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
## Finetune
|
| 107 |
+
|
| 108 |
+
我们同样提供了模型微调相关代码,大家可以按照示例数据的格式准备自己的数据,进行快速微调,具体请参考[模型微调](https://github.com/WisdomShell/shell/edit/main/finetune/README.md)。
|
| 109 |
+
|
| 110 |
+
其中,多轮对话微调数据格式如下。
|
| 111 |
+
|
| 112 |
+
```json
|
| 113 |
+
[
|
| 114 |
+
{
|
| 115 |
+
"id": "identity_0",
|
| 116 |
+
"conversations": [
|
| 117 |
+
{
|
| 118 |
+
"from": "human",
|
| 119 |
+
"value": "你好"
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"from": "assistant",
|
| 123 |
+
"value": "您好,我是Shell,请问有什么可以帮助您的吗?"
|
| 124 |
+
}
|
| 125 |
+
]
|
| 126 |
+
}
|
| 127 |
+
]
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
## Demo
|
| 131 |
+
|
| 132 |
+
我们提供了Web-UI、命令行、API三种形式的Demo。
|
| 133 |
+
|
| 134 |
+
### Web UI
|
| 135 |
+
|
| 136 |
+
开发者通过下列命令启动Web服务,服务启动后,可以通过`https://127.0.0.1:8000`进行访问。
|
| 137 |
+
|
| 138 |
+
```
|
| 139 |
+
python demos/web_demo.py
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
### CLI Demo
|
| 143 |
+
|
| 144 |
+
我们也提供了命令行交互的Demo版本,开发者可以通过下列命令运行。
|
| 145 |
+
|
| 146 |
+
```
|
| 147 |
+
python demos/cli_demo.py
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
### API
|
| 151 |
+
|
| 152 |
+
CodeShell也提供了基于OpenAI API的部署方法。
|
| 153 |
+
|
| 154 |
+
```
|
| 155 |
+
python demos/openai_api.py
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
启动后即可通过HTTP请求与CodeShell交互。
|
| 159 |
+
|
| 160 |
+
```
|
| 161 |
+
curl http://127.0.0.1:8000/v1/chat/completions \
|
| 162 |
+
-H "Content-Type: application/json" \
|
| 163 |
+
-d '{
|
| 164 |
+
"model": "CodeShell-7B-Chat",
|
| 165 |
+
"messages": [
|
| 166 |
+
{
|
| 167 |
+
"role": "user",
|
| 168 |
+
"content": "你好"
|
| 169 |
+
}
|
| 170 |
+
]
|
| 171 |
+
}'
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
## License
|
| 175 |
+
|
| 176 |
+
社区使用Shell模型需要遵循[《Shell模型许可协议》](https://github.com/WisdomShell/shell/blob/main/License.pdf)及[Apache 2.0许可协议](https://www.apache.org/licenses/LICENSE-2.0)。Shell模型允许用于商业用途,但如果您计划将Shell模型或其派生产品用于商业用途,需要您确认主体符合以下条件:
|
| 177 |
+
|
| 178 |
+
1. 关联方的服务或产品的每日平均活跃用户数(DAU)不能超过100万。
|
| 179 |
+
2. 关联方不得是软件服务提供商或云服务提供商。
|
| 180 |
+
3. 关联方不存在将获得授予的商业许可,在未经许可的前提下将其再授权给其他第三方的可能性。
|
| 181 |
+
|
| 182 |
+
在满足上述条件的前提下,您需要通过向shell.opensource@openbankai.com发送电子邮件,提交《Shell模型许可协议》要求的申请材料。经审核通过后,将授予您一个全球的、非排他的、不可转让的、不可再授权的商业版权许可。
|