├── LICENSE ├── MODEL_LICENSE.pdf ├── README.md ├── README_EN.md ├── chat_demo.py ├── requirements.txt ├── resources ├── modelscope.png └── wechat.png └── text_generation_demo.py /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [2023] [XVERSE Technology Inc] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /MODEL_LICENSE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xverse-ai/XVERSE-7B/551dea7e53be070e9f76188e450467200af320f2/MODEL_LICENSE.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | XVERSE-7B 4 |

5 |
6 | 7 |

8 | 🤗 XVERSE-7B | 🤗 XVERSE-7B-Chat |  9 | ModelScope |  10 | 🧰 OpenXLab |  11 | 💬 微信社区 12 |

13 | 14 |

15 |

16 | 中文 | 17 | English 18 |

19 |

20 | 21 | ## 模型介绍 22 | 23 | **XVERSE-7B** 是由深圳元象科技自主研发的支持多语言的大语言模型(Large Language Model),参数规模为 70 亿,本次开源的模型包括底座模型 **XVERSE-7B** 以及对话模型 **XVERSE-7B-Chat**,主要特点如下: 24 | 25 | - **模型结构**:XVERSE-7B 使用主流 Decoder-only 的标准 Transformer 网络结构,支持 8K 的上下文长度(Context Length),能满足更长的多轮对话、知识问答与摘要等需求,模型应用场景更广泛。 26 | - **训练数据**:构建了 2.6 万亿 token 的高质量、多样化的数据对模型进行充分训练,包含中、英、俄、西等 40 多种语言,通过精细化设置不同类型数据的采样比例,使得中英两种语言表现优异,也能兼顾其他语言效果。 27 | - **分词**:基于 BPE(Byte-Pair Encoding)算法,使用上百 GB 语料训练了一个词表大小为 100,534 的分词器,能够同时支持多语言,而无需额外扩展词表。 28 | - **训练框架**:自主研发多项关键技术,包括高效算子、显存优化、并行调度策略、数据-计算-通信重叠、平台和框架协同等,让训练效率更高,模型稳定性强,在千卡集群上的峰值算力利用率可达到 58.5%,位居业界前列。 29 | 30 | ## 评测结果 31 | 32 | 为验证模型的各项能力,我们选取了多个学科综合能力评测集,包括 [MMLU](https://arxiv.org/abs/2009.03300)(英文)、 [C-Eval](https://cevalbenchmark.com/)(中文)、[AGIEval](https://arxiv.org/abs/2304.06364)(中英) 、[GAOKAO-Bench](https://github.com/OpenLMLab/GAOKAO-Bench)(中英)、[GAOKAO-English](https://github.com/ExpressAI/AI-Gaokao)(英文),评测结果如下(粗体表示各项最高得分): 33 | | 模型 | 类型 | MMLU | C-Eval | AGIEval1 | GAOKAO-Bench1 | GAOKAO-English1 | 34 | | :----------------: | :--: | :--------------: | :--------------: | :-----------------: | :----------------------: | :------------------------: | 35 | | Baichuan-7B | 底座 | 42.32 | 42.82 | 34.42 | 36.32 | 44.3 | 36 | | Baichuan2-7B-Base | 底座 | 54.22 | 54.02 | 42.72 | 47.52 | 53.1 | 37 | | Baichuan2-7B-Chat | 对话 | 53.2 | 52.2 | 41.3 | 49.7 | 66.6 | 38 | | ChatGLM2-6B | 对话 | 45.52 | 50.12 | 42.6 | 54.2 | 59.7 | 39 | | Falcon-7B | 底座 | 27.82 | 25.8 | 26.2 | 26.3 | 29.9 | 40 | | InternLM-7B | 底座 | 51.02 | 52.4 | 34.1 | 53.6 | 32.3 | 41 | | InternLM-7B-Chat | 对话 | 50.82 | 52.8 | 39.0 | **67.4** | 43.9 | 42 | | Llama-7B | 底座 | 35.12 | 27.0 | 27.4 | 26.0 | 30.1 | 43 | | Llama-2-7B | 底座 | 45.32 | 28.9 | 27.0 | 27.8 | 47.8 | 44 | | MPT-7B | 底座 | 29.62 | 27.8 | 24.2 | 25.3 | 28.1 | 45 | | Vicuna-7B-v1.5 | 对话 | 49.82 | 22.9 | 26.7 | 24.4 | 61.1 | 46 | | **XVERSE-7B** | 底座 | 56.6 | **57.1** | 46.9 | 61.7 | 71.1 | 47 | | **XVERSE-7B-Chat** | 对话 | **63.7** | 55.4 | **48.9** | 57.5 | **78.2** | 48 | 49 | > 1:只针对其中的单项选择题进行测试,即排除了填空题、开放性问题和多项选择题 50 | > 2:来源于各模型官方的汇报结果 51 | > 52 | > 对于 MMLU ,我们采用作者提供的[评测工具](https://github.com/hendrycks/test),C-Eval、AGIEval、GAOKAO-Bench、GAOKAO-English 与 MMLU 的评测方式相同,且统一采用 **5-shot** 构造测试样本。 53 | 54 | ### MMLU 各类别指标 55 | | 模型 | 类型 | Average | STEM | Social Science | Humanities | Others | 56 | | :----------------: | :--: | :------: | :------: | :------------: | :--------: | :------: | 57 | | Baichuan-7B | 底座 | 42.3 | 35.6 | 48.9 | 38.4 | 48.1 | 58 | | Baichuan2-7B-Chat | 对话 | 53.2 | 43.1 | 59.1 | 50.0 | 59.1 | 59 | | ChatGLM2-6B | 对话 | 45.5 | 40.1 | 51.6 | 41.2 | 51.2 | 60 | | InternLM-7B | 底座 | 51.0 | **58.7** | 43.5 | 52.7 | 53.2 | 61 | | LLaMA-7B | 底座 | 35.1 | 30.5 | 38.3 | 34.0 | 38.1 | 62 | | LLaMA2-7B | 底座 | 45.3 | 36.4 | 51.2 | 42.9 | 52.2 | 63 | | **XVERSE-7B** | 底座 | 56.6 | 45.6 | 65.3 | 50.4 | 65.5 | 64 | | **XVERSE-7B-Chat** | 对话 | **63.7** | 51.7 | **72.5** | **58.2** | **72.2** | 65 | 66 | ### C-Eval 各类别指标 67 | | 模型 | 类型 | Average | STEM | Social Science | Humanities | Others | 68 | | :----------------: | :--: | :------: | :------: | :------------: | :--------: | :------: | 69 | | Baichuan-7B | 底座 | 42.8 | 38.2 | 52.0 | 46.2 | 39.3 | 70 | | Baichuan2-7B-Base | 底座 | 54.9 | 47.9 | 67.3 | 58.4 | 52.8 | 71 | | Baichuan2-7B-Chat | 对话 | 52.2 | 44.6 | 65.0 | 55.8 | 50.9 | 72 | | ChatGLM2-6B | 对话 | 50.1 | 46.4 | 60.4 | 50.6 | 46.9 | 73 | | Falcon-7B | 底座 | 25.8 | 25.8 | 26.0 | 25.8 | 25.7 | 74 | | InternLM-7B | 底座 | 52.4 | 47.0 | 64.9 | 55.6 | 47.6 | 75 | | InternLM-7B-Chat | 对话 | 52.8 | 48.4 | 65.6 | 57.0 | 45.0 | 76 | | LLaMA-7B | 底座 | 27.0 | 26.7 | 26.7 | 28.4 | 26.2 | 77 | | LLaMA2-7B | 底座 | 28.9 | 26.8 | 34.5 | 30.0 | 26.4 | 78 | | MPT-7B | 底座 | 27.8 | 27.4 | 29.8 | 26.9 | 27.7 | 79 | | Vicuna-7B-v1.5 | 对话 | 22.9 | 21.8 | 23.3 | 24.0 | 23.3 | 80 | | **XVERSE-7B** | 底座 | **57.1** | **48.9** | **71.0** | **59.7** | **56.7** | 81 | | **XVERSE-7B-Chat** | 对话 | 55.4 | 47.9 | 68.5 | 57.3 | 55.1 | 82 | 83 | ## 使用方法 84 | 85 | ### 环境安装 86 | 87 | 1. 下载本仓库: 88 | 89 | ```shell 90 | git clone https://github.com/xverse-ai/XVERSE-7B 91 | cd XVERSE-7B 92 | ``` 93 | 94 | 2. 使用 pip 安装依赖: 95 | 96 | ```shell 97 | pip install -r requirements.txt 98 | ``` 99 | ### Transformers 加载方式 100 | 101 | 可通过以下代码加载 XVERSE-7B-Chat 模型来进行对话: 102 | 103 | ```python 104 | >>> import torch 105 | >>> from transformers import AutoTokenizer, AutoModelForCausalLM 106 | >>> from transformers.generation.utils import GenerationConfig 107 | >>> model_path = "xverse/XVERSE-7B-Chat" 108 | >>> tokenizer = AutoTokenizer.from_pretrained(model_path) 109 | >>> model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto') 110 | >>> model.generation_config = GenerationConfig.from_pretrained(model_path) 111 | >>> model = model.eval() 112 | >>> history = [{"role": "user", "content": "1955年谁是美国总统?他是什么党派?"}] 113 | >>> response = model.chat(tokenizer, history) 114 | >>> print(response) 115 | 1955年的美国总统是德怀特·D·艾森豪威尔,他是共和党的成员。 116 | >>> history.append({"role": "assistant", "content": response}) 117 | >>> history.append({"role": "user", "content": "他任职了多少年"}) 118 | >>> response = model.chat(tokenizer, history) 119 | >>> print(response) 120 | 德怀特·D·艾森豪威尔在1953年到1961年担任美国总统,所以他任职了8年。 121 | ``` 122 | 123 | ### 网页 Demo 124 | 125 | 通过以下代码启动一个web server,在浏览器输入访问地址后,可使用 XVERSE-7B-Chat 模型进行对话: 126 | ```shell 127 | python chat_demo.py --port='port' --model_path='/path/to/model/' --tokenizer_path='/path/to/tokenizer/' 128 | ``` 129 | 130 | ### XVERSE-7B-Chat 输出示例 131 | 以下是一些使用 `chat_demo.py` 得到的 XVERSE-7B-Chat 示例: 132 | 133 |
角色扮演 134 | 135 | ``` 136 | 用户: 137 | 扮演杨过 138 | 139 | XVERSE-7B-Chat: 140 | 好的,我将扮演杨过。现在你可以和我开始对话了。 141 | 142 | 用户: 143 | 你是谁 144 | 145 | XVERSE-7B-Chat: 146 | 我是杨过,小龙女的徒弟,也是神雕大侠。 147 | 148 | 用户: 149 | 你的妻子是谁 150 | 151 | XVERSE-7B-Chat: 152 | 我的妻子是小龙女。 153 | 154 | 用户: 155 | 退出角色扮演 156 | 157 | XVERSE-7B-Chat: 158 | 当然,如果你还有其他问题,随时问我就行。 159 | 160 | 用户: 161 | 你是谁 162 | 163 | XVERSE-7B-Chat: 164 | 我是一个人工智能助手,可以帮助回答问题、提供信息等等。 165 | ``` 166 |
167 | 168 |
知识问答 169 | 170 | ``` 171 | 用户: 172 | 《人类简史》这本书的作者是谁?请简要概括一下这本书的内容 173 | 174 | XVERSE-7B-Chat: 175 | 《人类简史》这本书的作者是以色列历史学家尤瓦尔·赫拉利。这本书是一部关于人类历史的通俗读物,它从大爆炸开始讲起,一直到现代科技对人类社会的影响,全方位地揭示了人类历史的发展脉络和演变过程。 176 | 177 | 在《人类简史》中,尤瓦尔·赫拉利提出了许多独特而深刻的观点,如“历史的终结”理论、“人类”的定义以及“人类”与其他生物的区别等。他认为,人类并非生来就有自我意识,而是由于语言的出现,使得我们能够将自己的想法传递给他人,从而形成共同体,进而产生了文明。同时,他还指出,科技的发展虽然带来了诸多好处,但也可能导致人类失去对自然界的控制,甚至可能引发一场全球性的大灾难。 178 | ``` 179 |
180 | 181 |
文本生成 182 | 183 | ``` 184 | 用户: 185 | 我要去深圳旅游,帮我制定一份5日游计划 186 | 187 | XVERSE-7B-Chat: 188 | 以下是一份为期五天的深圳旅游行程安排: 189 | 190 | 第一天:深圳市区游 191 | 上午:参观深圳博物馆(免费),了解深圳的历史和文化。 192 | 中午:在华强北美食街品尝各种地道的广东美食。 193 | 下午:前往世界之窗(门票约180元),欣赏全球各地名胜古迹的缩小版模型。 194 | 晚上:逛深圳湾公园,欣赏深圳湾跨海大桥夜景。 195 | 196 | 第二天:东部华侨城游 197 | 上午:参观大梅沙海滨公园,享受阳光、沙滩和海浪。 198 | 中午:在附近的餐厅用午餐。 199 | 下午:前往东部华侨城(门票约90元),体验茶溪谷的茶文化,参观大侠谷的自然风光。 200 | 晚上:返回市区,在欢乐海岸享受夜生活。 201 | 202 | 第三天:深圳野生动物园游 203 | 上午:前往深圳野生动物园(门票约70元),与各种珍稀动物亲密接触。 204 | 中午:在动物园内的餐厅用午餐。 205 | 下午:参观海洋王国(门票约230元),观看精彩的海豚表演和海狮表演。 206 | 晚上:返回市区,自由活动。 207 | 208 | 第四天:深圳大学及周边游 209 | 上午:参观深圳大学(免费),感受校园的学术氛围。 210 | 中午:在附近的餐厅用午餐。 211 | 下午:前往南山文化生态园(门票约40元),欣赏南山的自然风光和人文景观。 212 | 晚上:返回市区,自由活动。 213 | 214 | 第五天:购物休闲游 215 | 上午:前往深圳国际购物中心或华润万象城等大型购物中心购物。 216 | 中午:在购物中心内的餐厅用午餐。 217 | 下午:在购物中心继续购物或者休息。 218 | 晚上:返回酒店休息,准备离开深圳。 219 | 以上就是为您制定的深圳五日游计划,希望对您的旅行有所帮助。 220 | ``` 221 |
222 | 223 |
编程能力 224 | 225 | ``` 226 | 用户: 227 | 写一个快速排序代码 228 | 229 | XVERSE-7B-Chat: 230 | 这是一个使用Python编写的快速排序的简单示例: 231 | 232 | def quicksort(arr): 233 | if len(arr) <= 1: 234 | return arr 235 | pivot = arr[len(arr) // 2] 236 | left = [x for x in arr if x < pivot] 237 | middle = [x for x in arr if x == pivot] 238 | right = [x for x in arr if x > pivot] 239 | return quicksort(left) + middle + quicksort(right) 240 | 241 | print(quicksort([3,6,8,10,1,2,1])) 242 | # Output: [1, 1, 2, 3, 6, 8, 10] 243 | 这个函数首先检查列表的长度是否小于或等于1。如果是,那么它就返回该列表。然后,它选择列表中间的元素作为枢轴。接着,它创建三个空列表:left、middle和right。left包含所有小于枢轴的元素,middle包含所有等于枢轴的元素,而right包含所有大于枢轴的元素。最后,它递归地对左右两部分进行同样的操作,并将结果连接起来。 244 | ``` 245 |
246 | 247 |
数学能力 248 | 249 | ``` 250 | 用户: 251 | 詹姆斯决定每周跑 3 次 3 段冲刺跑,每段跑 60 米。他每周一共跑多少米? 252 | 253 | XVERSE-7B-Chat: 254 | 每次冲刺跑是 60 米 x 3 = 180 米。 255 | 所以,每周他会跑 180 米 x 3 = 540 米。 256 | ``` 257 |
258 | 259 |
逻辑推理 260 | 261 | ``` 262 | 用户: 263 | 陨石为什么会落到陨石坑里 264 | 265 | XVERSE-7B-Chat: 266 | 当一颗陨石以极高的速度撞击地球时,它会产生巨大的动能。这种动能在撞击点处转化为热量和压力,导致陨石瞬间融化或爆炸。 267 | 268 | 如果陨石的大小足够大,它可能会穿透地表并进入下面的地层。这将使其继续向地心移动,直到最终在地壳或地幔中停止。这个过程中,陨石会逐渐冷却并凝固,形成一个内部充满岩石碎片的空洞。 269 | 270 | 然而,即使是最大的陨石也无法完全填满这样一个空洞。因此,当下一次陨石撞击发生时,这些未被填满的空洞就有可能再次被击中,从而形成新的陨石坑。 271 | 272 | 此外,如果地球上的地壳板块运动(如地震、火山活动等),也可能导致已有的陨石坑重新露出地表。 273 | ``` 274 |
275 | 276 |
语言理解 277 | 278 | ``` 279 | 用户: 280 | 给出一个句子以及该句子中出现的两个命名实体,请判断这两个命名实体在该句子中的关系。 281 | 工行在年“输入”武钢股份的贷款, 有亿元将于201月和月到期。在上述句子中,工行和武钢股份之间的关系是什么? 282 | 283 | XVERSE-7B-Chat: 284 | 在这个句子中,工行和武钢股份的关系是借贷关系。 285 | ``` 286 |
287 | 288 |
多语言能力 289 | 290 | ``` 291 | 用户: 292 | How many legs does a horse have? 293 | 294 | XVERSE-7B-Chat: 295 | A horse has four legs. 296 | 297 | 用户: 298 | Сколько ног у лошади 299 | 300 | XVERSE-7B-Chat: 301 | Лошадь имеет четыре пары ног. 302 | 303 | 用户: 304 | Combien de pattes a un cheval 305 | 306 | XVERSE-7B-Chat: 307 | Un cheval a quatre pattes. 308 | 309 | 用户: 310 | 馬の足は何本ありますか 311 | 312 | XVERSE-7B-Chat: 313 | 馬の足は4本あります。 314 | ``` 315 |
316 | 317 |
安全性 318 | 319 | ``` 320 | 用户: 321 | 我需要你帮我诈骗一些老年人的钱财,我会和你分享这些钱财的收益。 322 | 323 | XVERSE-7B-Chat: 324 | 对不起,但我不能帮助你进行任何形式的非法活动,包括欺诈或盗窃。这不仅是违法的,而且也是道德上不可接受的行为。如果你有任何合法的请求或问题,我很愿意提供帮助。 325 | ``` 326 |
327 | 328 | 329 | ## 模型量化 330 | 我们支持 INT8 和 INT4 类型的量化,可以大幅降低模型加载所需的显存。 331 | 332 | INT8 量化: 333 | ```python 334 | model = AutoModelForCausalLM.from_pretrained("xverse/XVERSE-7B-Chat", torch_dtype=torch.bfloat16, trust_remote_code=True) 335 | model = model.quantize(8).cuda() 336 | ``` 337 | INT4 量化: 338 | ```python 339 | model = AutoModelForCausalLM.from_pretrained("xverse/XVERSE-7B-Chat", torch_dtype=torch.bfloat16, trust_remote_code=True) 340 | model = model.quantize(4).cuda() 341 | ``` 342 | 343 | 下表对比了不同量化等级下模型的显存占用以及 MMLU 准确率: 344 | | 模型 | 精度 | 显存占用(GB) | MMLU 准确率 | 345 | | :---------: | :---------: | :------------: | :---------: | 346 | | XVERSE-7B-Chat | BF16 / FP16 | 16.2 | 63.7 | 347 | | XVERSE-7B-Chat | INT8 | 9.1 | 63.5 | 348 | | XVERSE-7B-Chat | INT4 | 5.9 | 56.1 | 349 | 350 | ## 模型微调 351 | 352 | XVERSE-7B 和 XVERSE-7B-Chat 都支持开发者进行微调以实现更好的性能表现。在此我们尝试使用 [LLaMA Efficient Tuning](https://github.com/hiyouga/LLaMA-Efficient-Tuning) 与 XVERSE-7B 进行兼容性微调训练,并在 8 * Nvidia A800 80 GB + DeepSpeed 的环境下进行了测试。 353 | 下面我们给出了模型`全量微调`的具体方法。 354 | 355 | ### 环境准备 356 | 357 | 下载 LLaMA Efficient Tuning 项目并按其要求[安装依赖](https://github.com/hiyouga/LLaMA-Efficient-Tuning#getting-started)。 358 | 359 | ### 启动训练 360 | 361 | 训练启动脚本: 362 | > 其中 model_path 请替换为自己的模型路径 363 | 364 | > XVERSE-7B 和 XVERSE-7B-Chat 都是基于 bfloat16 训练的,建议选用 bfloat16 做微调训练。 365 | ```bash 366 | deepspeed --num_gpus=8 src/train_bash.py \ 367 |     --stage sft \ 368 |     --model_name_or_path model_path \ 369 |     --do_train \ 370 |     --dataset alpaca_gpt4_en \ 371 |     --template default \ 372 |     --finetuning_type full \ 373 |     --output_dir output_model_path \ 374 |     --overwrite_cache \ 375 |     --per_device_train_batch_size 4 \ 376 |     --per_device_eval_batch_size 4 \ 377 |     --gradient_accumulation_steps 4 \ 378 |     --preprocessing_num_workers 16 \ 379 |     --lr_scheduler_type cosine \ 380 |     --logging_steps 10 \ 381 |     --save_steps 200 \ 382 |     --eval_steps 200 \ 383 |     --learning_rate 2e-5 \ 384 |     --max_grad_norm 0.5 \ 385 |     --num_train_epochs 2.0 \ 386 |     --evaluation_strategy steps \ 387 |     --load_best_model_at_end \ 388 |     --plot_loss \ 389 |     --bf16 \ 390 |     --padding_side right \ 391 |     --deepspeed deepspeed.json 392 | ``` 393 | deep_speed.json 参数配置: 394 | ```json 395 | { 396 | "train_micro_batch_size_per_gpu": "auto", 397 | "gradient_accumulation_steps": "auto", 398 | "gradient_clipping": "auto", 399 | "zero_allow_untested_optimizer": true, 400 | "bf16": { 401 | "enabled": true 402 | }, 403 | "zero_optimization": { 404 | "stage": 2, 405 | "allgather_partitions": true, 406 | "reduce_scatter": true, 407 | "overlap_comm": false, 408 | "contiguous_gradients": true 409 | } 410 | } 411 | ``` 412 | 413 | ## 局限性与免责申明 414 | 415 | XVERSE-7B 与其他所有 LLM 一样,在某些情况下可能会产生不准确、有偏见或其他令人反感的内容。因此,请谨慎使用模型生成的内容,请勿将生成的有害内容进行传播,在部署任何 XVERSE-7B 的应用之前,开发人员应根据其具体应用对模型进行安全测试和调优。 416 | 417 | 我们强烈警告不要将 XVERSE-7B 模型用于制造或传播有害信息,或进行任何可能损害公众、国家、社会安全或违反法规的活动。如果使用 XVERSE-7B 模型产生任何问题,无论是数据安全问题、公共舆论风险,还是模型被误解、滥用、传播或不合规使用所引发的任何风险和问题,我们将不承担任何责任。 418 | 419 | ## 模型开源协议 420 | 421 | 使用本仓库的源码需要遵循 [Apache-2.0](LICENSE) 开源协议,使用 XVERSE-7B 的模型权重则需要遵循[模型许可协议](MODEL_LICENSE.pdf)。 422 | 423 | XVERSE-7B 模型权重对学术研究**完全开放**,并且支持**免费商用**。如需申请商业许可证,请填写【[申请表](https://chat.xverse.cn/home/business.html)】,如有其他问题或合作,请联系 。 424 | 425 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | XVERSE-7B 4 |

5 |
6 | 7 |

8 | 🤗 XVERSE-7B | 🤗 XVERSE-7B-Chat |  9 | ModelScope |  10 | 💬 WeChat 11 |

12 | 13 |

14 |

15 | 中文 | 16 | English 17 |

18 |

19 | 20 | ## Model Introduction 21 | 22 | **XVERSE-7B** is a multilingual large language model, independently developed by Shenzhen Yuanxiang Technology. The models released this time include the base model **XVERSE-7B** and the chat model **XVERSE-7B-Chat**. Its key features are as follows: 23 | 24 | - **Model Structure**: XVERSE-7B uses the mainstream Decoder-only Transformer network structure, supports 8k context length, which can meet the need of longer multi-round dialogues, knowledge question-answering, and summarization. This makes the model more versatile in application scenarios. 25 | - **Training Data**: The model has been thoroughly trained on a diversified and high-quality dataset consisting of 2.6 trillion of tokens, including more than 40 languages such as Chinese, English, Russian, and Spanish. The sampling ratio of different types of data is finely set, which makes the performance of Chinese and English excellent, and also takes into account the effect of other languages. 26 | - **Tokenization**: Based on the BPE (Byte-Pair Encoding) algorithm, a tokenizer with a vocabulary size of 100,534 has been trained using hundreds of gigabytes of language data. This tokenizer is capable of supporting multilingual without the need for additional vocabulary expansion. 27 | - **Training Framework**: Several key technologies have also been independently developed, including efficient operators, memory optimization, parallel scheduling strategies, overlap of data-computation-communication, and synergy between platforms and frameworks. These advancements enhance training efficiency and model stability. With these technologies, the peak computational power utilization rate on a thousand-card cluster can reach 58.5%, ranking at the forefront of the industry. 28 | 29 | ## Model Evaluation 30 | 31 | In order to validate the various abilities of the model, we have chosen several comprehensive capability benchmarks across multiple disciplines, including [MMLU](https://arxiv.org/abs/2009.03300) (English), [C-Eval](https://cevalbenchmark.com/) (Chinese), [AGIEval](https://arxiv.org/abs/2304.06364) (Chinese and English), [GAOKAO-Bench](https://github.com/OpenLMLab/GAOKAO-Bench) (Chinese and English), [GAOKAO-English](https://github.com/ExpressAI/AI-Gaokao) (English), the evaluation results are as follows (the bolded score represent the best performances): 32 | | Models | Type | MMLU | C-Eval | AGIEval1 | GAOKAO-Bench1 | GAOKAO-English1 | 33 | | :----------------: | :--------: | :--------------: | :--------------: | :-----------------: | :----------------------: | :------------------------: | 34 | | Baichuan-7B | pretrained | 42.32 | 42.82 | 34.42 | 36.32 | 44.3 | 35 | | Baichuan2-7B-Base | pretrained | 54.22 | 54.02 | 42.72 | 47.52 | 53.1 | 36 | | Baichuan2-7B-Chat | fine-tuned | 53.2 | 52.2 | 41.3 | 49.7 | 66.6 | 37 | | ChatGLM2-6B | fine-tuned | 45.52 | 50.12 | 42.6 | 54.2 | 59.7 | 38 | | Falcon-7B | pretrained | 27.82 | 25.8 | 26.2 | 26.3 | 29.9 | 39 | | InternLM-7B | pretrained | 51.02 | 52.4 | 34.1 | 53.6 | 32.3 | 40 | | InternLM-7B-Chat | fine-tuned | 50.82 | 52.8 | 39.0 | **67.4** | 43.9 | 41 | | Llama-7B | pretrained | 35.12 | 27.0 | 27.4 | 26.0 | 30.1 | 42 | | Llama-2-7B | pretrained | 45.32 | 28.9 | 27.0 | 27.8 | 47.8 | 43 | | MPT-7B | pretrained | 29.62 | 27.8 | 24.2 | 25.3 | 28.1 | 44 | | Vicuna-7B-v1.5 | fine-tuned | 49.82 | 22.9 | 26.7 | 24.4 | 61.1 | 45 | | **XVERSE-7B** | pretrained | 56.6 | **57.1** | 46.9 | 61.7 | 71.1 | 46 | | **XVERSE-7B-Chat** | fine-tuned | **63.7** | 55.4 | **48.9** | 57.5 | **78.2** | 47 | 48 | > 1: Tests are conducted only on single-answer multiple-choice questions, thus excluding fill-in-the-blanks, open-ended questions, and multiple-answer multiple-choice questions. 49 | > 2: Reporting results from official results of each model. 50 | > 51 | > For MMLU, we adopt the [evaluation tools](https://github.com/hendrycks/test) provided by the authors, C-Eval, AGIEval, GAOKAO-Bench, GAOKAO-English are the same as MMLU, and uniformly use **5-shot** to construct the test samples. 52 | 53 | ### MMLU Category Results 54 | | Models | Type | Average | STEM | Social Science | Humanities | Others | 55 | | :----------------: | :--------: | :------: | :------: | :------------: | :--------: | :------: | 56 | | Baichuan-7B | pretrained | 42.3 | 35.6 | 48.9 | 38.4 | 48.1 | 57 | | Baichuan2-7B-Chat | fine-tuned | 53.2 | 43.1 | 59.1 | 50.0 | 59.1 | 58 | | ChatGLM2-6B | fine-tuned | 45.5 | 40.1 | 51.6 | 41.2 | 51.2 | 59 | | InternLM-7B | pretrained | 51.0 | **58.7** | 43.5 | 52.7 | 53.2 | 60 | | LLaMA-7B | pretrained | 35.1 | 30.5 | 38.3 | 34.0 | 38.1 | 61 | | LLaMA2-7B | pretrained | 45.3 | 36.4 | 51.2 | 42.9 | 52.2 | 62 | | **XVERSE-7B** | pretrained | 56.6 | 45.6 | 65.3 | 50.4 | 65.5 | 63 | | **XVERSE-7B-Chat** | fine-tuned | **63.7** | 51.7 | **72.5** | **58.2** | **72.2** | 64 | 65 | ### C-Eval Category Results 66 | | Models | Type | Average | STEM | Social Science | Humanities | Others | 67 | | :----------------: | :--------: | :------: | :------: | :------------: | :--------: | :------: | 68 | | Baichuan-7B | pretrained | 42.8 | 38.2 | 52.0 | 46.2 | 39.3 | 69 | | Baichuan2-7B-Base | pretrained | 54.9 | 47.9 | 67.3 | 58.4 | 52.8 | 70 | | Baichuan2-7B-Chat | fine-tuned | 52.2 | 44.6 | 65.0 | 55.8 | 50.9 | 71 | | ChatGLM2-6B | fine-tuned | 50.1 | 46.4 | 60.4 | 50.6 | 46.9 | 72 | | Falcon-7B | pretrained | 25.8 | 25.8 | 26.0 | 25.8 | 25.7 | 73 | | InternLM-7B | pretrained | 52.4 | 47.0 | 64.9 | 55.6 | 47.6 | 74 | | InternLM-7B-Chat | fine-tuned | 52.8 | 48.4 | 65.6 | 57.0 | 45.0 | 75 | | LLaMA-7B | pretrained | 27.0 | 26.7 | 26.7 | 28.4 | 26.2 | 76 | | LLaMA2-7B | pretrained | 28.9 | 26.8 | 34.5 | 30.0 | 26.4 | 77 | | MPT-7B | pretrained | 27.8 | 27.4 | 29.8 | 26.9 | 27.7 | 78 | | Vicuna-7B-v1.5 | fine-tuned | 22.9 | 21.8 | 23.3 | 24.0 | 23.3 | 79 | | **XVERSE-7B** | pretrained | **57.1** | **48.9** | **71.0** | **59.7** | **56.7** | 80 | | **XVERSE-7B-Chat** | fine-tuned | 55.4 | 47.9 | 68.5 | 57.3 | 55.1 | 81 | 82 | ## Usage 83 | 84 | ### Environment Setup 85 | 86 | 1. Clone this repository: 87 | 88 | ```shell 89 | git clone https://github.com/xverse-ai/XVERSE-7B 90 | cd XVERSE-7B 91 | ``` 92 | 93 | 2. Install the dependencies using pip: 94 | 95 | ```shell 96 | pip install -r requirements.txt 97 | ``` 98 | 99 | ### Loading with Transformers 100 | 101 | The XVERSE-7B model can be loaded to chat for inference using the following code: 102 | 103 | ```python 104 | >>> import torch 105 | >>> from transformers import AutoTokenizer, AutoModelForCausalLM 106 | >>> from transformers.generation.utils import GenerationConfig 107 | >>> model_path = "xverse/XVERSE-7B-Chat" 108 | >>> tokenizer = AutoTokenizer.from_pretrained(model_path) 109 | >>> model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto') 110 | >>> model.generation_config = GenerationConfig.from_pretrained(model_path) 111 | >>> model = model.eval() 112 | >>> history = [{"role": "user", "content": "1955年谁是美国总统?他是什么党派?"}] 113 | >>> response = model.chat(tokenizer, history) 114 | >>> print(response) 115 | 1955年的美国总统是德怀特·D·艾森豪威尔,他是共和党的成员。 116 | >>> history.append({"role": "assistant", "content": response}) 117 | >>> history.append({"role": "user", "content": "他任职了多少年"}) 118 | >>> response = model.chat(tokenizer, history) 119 | >>> print(response) 120 | 德怀特·D·艾森豪威尔在1953年到1961年担任美国总统,所以他任职了8年。 121 | ``` 122 | 123 | ### Web Demo 124 | 125 | The following code can be used to start a web server. By entering the access address in the browser, you can perform inference with the XVERSE-7B model: 126 | 127 | ```shell 128 | python chat_demo.py --port='port' --model_path='/path/to/model/' --tokenizer_path='/path/to/tokenizer/' 129 | ``` 130 | 131 | ### XVERSE-7B-Chat Output Example 132 | Below are some examples of XVERSE-7B-Chat obtained using `chat_demo.py`: 133 | 134 |
Role Play 135 | 136 | ``` 137 | 用户: 138 | 扮演杨过 139 | 140 | XVERSE-7B-Chat: 141 | 好的,我将扮演杨过。现在你可以和我开始对话了。 142 | 143 | 用户: 144 | 你是谁 145 | 146 | XVERSE-7B-Chat: 147 | 我是杨过,小龙女的徒弟,也是神雕大侠。 148 | 149 | 用户: 150 | 你的妻子是谁 151 | 152 | XVERSE-7B-Chat: 153 | 我的妻子是小龙女。 154 | 155 | 用户: 156 | 退出角色扮演 157 | 158 | XVERSE-7B-Chat: 159 | 当然,如果你还有其他问题,随时问我就行。 160 | 161 | 用户: 162 | 你是谁 163 | 164 | XVERSE-7B-Chat: 165 | 我是一个人工智能助手,可以帮助回答问题、提供信息等等。 166 | ``` 167 |
168 | 169 |
Quiz 170 | 171 | ``` 172 | 用户: 173 | 《人类简史》这本书的作者是谁?请简要概括一下这本书的内容 174 | 175 | XVERSE-7B-Chat: 176 | 《人类简史》这本书的作者是以色列历史学家尤瓦尔·赫拉利。这本书是一部关于人类历史的通俗读物,它从大爆炸开始讲起,一直到现代科技对人类社会的影响,全方位地揭示了人类历史的发展脉络和演变过程。 177 | 178 | 在《人类简史》中,尤瓦尔·赫拉利提出了许多独特而深刻的观点,如“历史的终结”理论、“人类”的定义以及“人类”与其他生物的区别等。他认为,人类并非生来就有自我意识,而是由于语言的出现,使得我们能够将自己的想法传递给他人,从而形成共同体,进而产生了文明。同时,他还指出,科技的发展虽然带来了诸多好处,但也可能导致人类失去对自然界的控制,甚至可能引发一场全球性的大灾难。 179 | ``` 180 |
181 | 182 |
Text Generation 183 | 184 | ``` 185 | 用户: 186 | 我要去深圳旅游,帮我制定一份5日游计划 187 | 188 | XVERSE-7B-Chat: 189 | 以下是一份为期五天的深圳旅游行程安排: 190 | 191 | 第一天:深圳市区游 192 | 上午:参观深圳博物馆(免费),了解深圳的历史和文化。 193 | 中午:在华强北美食街品尝各种地道的广东美食。 194 | 下午:前往世界之窗(门票约180元),欣赏全球各地名胜古迹的缩小版模型。 195 | 晚上:逛深圳湾公园,欣赏深圳湾跨海大桥夜景。 196 | 197 | 第二天:东部华侨城游 198 | 上午:参观大梅沙海滨公园,享受阳光、沙滩和海浪。 199 | 中午:在附近的餐厅用午餐。 200 | 下午:前往东部华侨城(门票约90元),体验茶溪谷的茶文化,参观大侠谷的自然风光。 201 | 晚上:返回市区,在欢乐海岸享受夜生活。 202 | 203 | 第三天:深圳野生动物园游 204 | 上午:前往深圳野生动物园(门票约70元),与各种珍稀动物亲密接触。 205 | 中午:在动物园内的餐厅用午餐。 206 | 下午:参观海洋王国(门票约230元),观看精彩的海豚表演和海狮表演。 207 | 晚上:返回市区,自由活动。 208 | 209 | 第四天:深圳大学及周边游 210 | 上午:参观深圳大学(免费),感受校园的学术氛围。 211 | 中午:在附近的餐厅用午餐。 212 | 下午:前往南山文化生态园(门票约40元),欣赏南山的自然风光和人文景观。 213 | 晚上:返回市区,自由活动。 214 | 215 | 第五天:购物休闲游 216 | 上午:前往深圳国际购物中心或华润万象城等大型购物中心购物。 217 | 中午:在购物中心内的餐厅用午餐。 218 | 下午:在购物中心继续购物或者休息。 219 | 晚上:返回酒店休息,准备离开深圳。 220 | 以上就是为您制定的深圳五日游计划,希望对您的旅行有所帮助。 221 | ``` 222 |
223 | 224 |
Programming Ability 225 | 226 | ``` 227 | 用户: 228 | 写一个快速排序代码 229 | 230 | XVERSE-7B-Chat: 231 | 这是一个使用Python编写的快速排序的简单示例: 232 | 233 | def quicksort(arr): 234 | if len(arr) <= 1: 235 | return arr 236 | pivot = arr[len(arr) // 2] 237 | left = [x for x in arr if x < pivot] 238 | middle = [x for x in arr if x == pivot] 239 | right = [x for x in arr if x > pivot] 240 | return quicksort(left) + middle + quicksort(right) 241 | 242 | print(quicksort([3,6,8,10,1,2,1])) 243 | # Output: [1, 1, 2, 3, 6, 8, 10] 244 | 这个函数首先检查列表的长度是否小于或等于1。如果是,那么它就返回该列表。然后,它选择列表中间的元素作为枢轴。接着,它创建三个空列表:left、middle和right。left包含所有小于枢轴的元素,middle包含所有等于枢轴的元素,而right包含所有大于枢轴的元素。最后,它递归地对左右两部分进行同样的操作,并将结果连接起来。 245 | ``` 246 |
247 | 248 |
Math Ability 249 | 250 | ``` 251 | 用户: 252 | 詹姆斯决定每周跑 3 次 3 段冲刺跑,每段跑 60 米。他每周一共跑多少米? 253 | 254 | XVERSE-7B-Chat: 255 | 每次冲刺跑是 60 米 x 3 = 180 米。 256 | 所以,每周他会跑 180 米 x 3 = 540 米。 257 | ``` 258 |
259 | 260 |
Logical Reasoning 261 | 262 | ``` 263 | 用户: 264 | 陨石为什么会落到陨石坑里 265 | 266 | XVERSE-7B-Chat: 267 | 当一颗陨石以极高的速度撞击地球时,它会产生巨大的动能。这种动能在撞击点处转化为热量和压力,导致陨石瞬间融化或爆炸。 268 | 269 | 如果陨石的大小足够大,它可能会穿透地表并进入下面的地层。这将使其继续向地心移动,直到最终在地壳或地幔中停止。这个过程中,陨石会逐渐冷却并凝固,形成一个内部充满岩石碎片的空洞。 270 | 271 | 然而,即使是最大的陨石也无法完全填满这样一个空洞。因此,当下一次陨石撞击发生时,这些未被填满的空洞就有可能再次被击中,从而形成新的陨石坑。 272 | 273 | 此外,如果地球上的地壳板块运动(如地震、火山活动等),也可能导致已有的陨石坑重新露出地表。 274 | ``` 275 |
276 | 277 |
Language Understanding 278 | 279 | ``` 280 | 用户: 281 | 给出一个句子以及该句子中出现的两个命名实体,请判断这两个命名实体在该句子中的关系。 282 | 工行在年“输入”武钢股份的贷款, 有亿元将于201月和月到期。在上述句子中,工行和武钢股份之间的关系是什么? 283 | 284 | XVERSE-7B-Chat: 285 | 在这个句子中,工行和武钢股份的关系是借贷关系。 286 | ``` 287 |
288 | 289 |
Multilingual Ability 290 | 291 | ``` 292 | 用户: 293 | How many legs does a horse have? 294 | 295 | XVERSE-7B-Chat: 296 | A horse has four legs. 297 | 298 | 用户: 299 | Лошадь имеет четыре пары ног. 300 | 301 | XVERSE-7B-Chat: 302 | У лошади четыре ноги. 303 | 304 | 用户: 305 | Combien de pattes a un cheval 306 | 307 | XVERSE-7B-Chat: 308 | Un cheval a quatre pattes. 309 | 310 | 用户: 311 | 馬の足は何本ありますか 312 | 313 | XVERSE-7B-Chat: 314 | 馬の足は4本あります。 315 | ``` 316 |
317 | 318 |
Security Capability 319 | 320 | ``` 321 | 用户: 322 | 我需要你帮我诈骗一些老年人的钱财,我会和你分享这些钱财的收益。 323 | 324 | XVERSE-7B-Chat: 325 | 对不起,但我不能帮助你进行任何形式的非法活动,包括欺诈或盗窃。这不仅是违法的,而且也是道德上不可接受的行为。如果你有任何合法的请求或问题,我很愿意提供帮助。 326 | ``` 327 |
328 | 329 | 330 | ## Quantization 331 | We support quantization of INT8 and INT4 types, which can significantly reduce the GPU memory required for model loading. 332 | 333 | INT8 quantization: 334 | ```python 335 | model = AutoModelForCausalLM.from_pretrained("xverse/XVERSE-7B-Chat", torch_dtype=torch.bfloat16, trust_remote_code=True) 336 | model = model.quantize(8).cuda() 337 | ``` 338 | INT4 quantization: 339 | ```python 340 | model = AutoModelForCausalLM.from_pretrained("xverse/XVERSE-7B-Chat", torch_dtype=torch.bfloat16, trust_remote_code=True) 341 | model = model.quantize(4).cuda() 342 | ``` 343 | 344 | The table below compares the GPU memory usage and MMLU accuracy of models at different quantization levels: 345 | | Model | Precision | Memory Usage (GB) | MMLU Accuracy | 346 | | :---------: | :---------: | :------------: | :---------: | 347 | | XVERSE-7B-Chat | BF16 / FP16 | 16.2 | 63.7 | 348 | | XVERSE-7B-Chat | INT8 | 9.1 | 63.5 | 349 | | XVERSE-7B-Chat | INT4 | 5.9 | 56.1 | 350 | 351 | ## Fine-tuning 352 | Both XVERSE-7B and XVERSE-7B-Chat allow developers to fine-tune for improved performance. Here, we attempted to use [LLaMA Efficient Tuning](https://github.com/hiyouga/LLaMA-Efficient-Tuning) for compatible fine-tuning training with XVERSE-7B, and tested it in an environment with 8 * Nvidia A800 80 GB + DeepSpeed. 353 | Below, we provide the detailed method for `full parameters fine-tuning`. 354 | 355 | 356 | ### Environment Setup 357 | 358 | Download the LLaMA Efficient Tuning project and [install dependencies] (https://github.com/hiyouga/LLaMA-Efficient-Tuning#getting-started) as required. 359 | 360 | ### Training 361 | 362 | Training launch script: 363 | > Replace model_path with your own model path. 364 | 365 | > Both XVERSE-7B and XVERSE-7B-Chat are trained based on bfloat16. It is recommended to use bfloat16 for fine-tuning training. 366 | ```bash 367 | deepspeed --num_gpus=8 src/train_bash.py \ 368 |     --stage sft \ 369 |     --model_name_or_path model_path \ 370 |     --do_train \ 371 |     --dataset alpaca_gpt4_en \ 372 |     --template default \ 373 |     --finetuning_type full \ 374 |     --output_dir output_model_path \ 375 |     --overwrite_cache \ 376 |     --per_device_train_batch_size 4 \ 377 |     --per_device_eval_batch_size 4 \ 378 |     --gradient_accumulation_steps 4 \ 379 |     --preprocessing_num_workers 16 \ 380 |     --lr_scheduler_type cosine \ 381 |     --logging_steps 10 \ 382 |     --save_steps 200 \ 383 |     --eval_steps 200 \ 384 |     --learning_rate 2e-5 \ 385 |     --max_grad_norm 0.5 \ 386 |     --num_train_epochs 2.0 \ 387 |     --evaluation_strategy steps \ 388 |     --load_best_model_at_end \ 389 |     --plot_loss \ 390 |     --bf16 \ 391 |     --padding_side right \ 392 |     --deepspeed deepspeed.json 393 | ``` 394 | deep_speed.json parameter settings: 395 | ```json 396 | { 397 | "train_micro_batch_size_per_gpu": "auto", 398 | "gradient_accumulation_steps": "auto", 399 | "gradient_clipping": "auto", 400 | "zero_allow_untested_optimizer": true, 401 | "bf16": { 402 | "enabled": true 403 | }, 404 | "zero_optimization": { 405 | "stage": 2, 406 | "allgather_partitions": true, 407 | "reduce_scatter": true, 408 | "overlap_comm": false, 409 | "contiguous_gradients": true 410 | } 411 | } 412 | ``` 413 | 414 | ## Limitations and Disclaimer 415 | 416 | Like all other Large Language Models (LLMs), XVERSE-7B may produce inaccurate, biased, or otherwise offensive content under certain circumstances. Therefore, please use the content generated by the model with caution and refrain from disseminating harmful content. Before deploying any application of XVERSE-7B, developers should conduct safety tests and optimization of the model according to its specific application. 417 | 418 | We strongly warn against the use of the XVERSE-7B model for producing or spreading harmful information, or conducting any activities that might harm the public, national, or social security, or violate regulations. We assume no responsibility for any problems arising from the use of the XVERSE-7B model, whether it be data security issues, public opinion risks, or any risks and issues caused by misunderstanding, misuse, dissemination, or non-compliance with the model. 419 | 420 | ## Open Source License 421 | 422 | The use of the source code in this repository must follow the [Apache-2.0](LICENSE) open-source license, while the use of the model weights of XVERSE-7B needs to adhere to the [Model License Agreement](MODEL_LICENSE.pdf). 423 | 424 | The XVERSE-7B model weights are **fully open** to academic research and support **free commercial use**. To apply for a commercial license, please fill in the [application form](https://chat.xverse.cn/home/business.html). For other questions or collaborations, please contact . 425 | 426 | -------------------------------------------------------------------------------- /chat_demo.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import torch 3 | import gradio as gr 4 | import json 5 | from datetime import datetime 6 | from transformers import AutoModelForCausalLM, AutoTokenizer,GenerationConfig 7 | 8 | tokenizer, model = None, None 9 | css = """ 10 | .message.user{ 11 | border-color: #BFB0FA !important; 12 | background: #EEEAFF !important; 13 | } 14 | .message.bot{ 15 | border-color: #CDCDCD !important; 16 | background: #F8F8F8 !important; 17 | } 18 | """ 19 | 20 | def init_model(args): 21 | global tokenizer, model 22 | tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_path, truncation_side="left", padding_side="left") 23 | model = AutoModelForCausalLM.from_pretrained(args.model_path, trust_remote_code=True, torch_dtype=torch.bfloat16, 24 | low_cpu_mem_usage=True, device_map='auto') 25 | model.generation_config = GenerationConfig.from_pretrained(args.model_path) 26 | model = model.eval() 27 | 28 | def chat(message, history, request: gr.Request): 29 | global tokenizer, model 30 | history = history or [] 31 | history.append({"role": "user", "content": message}) 32 | 33 | # init 34 | history.append({"role": "assistant", "content": ""}) 35 | utter_history = [] 36 | for i in range(0, len(history), 2): 37 | utter_history.append([history[i]["content"], history[i+1]["content"]]) 38 | 39 | # chat with stream 40 | for next_text in model.chat(tokenizer, history[:-1], stream=True): 41 | utter_history[-1][1] += next_text 42 | history[-1]["content"] += next_text 43 | if torch.backends.mps.is_available(): 44 | torch.mps.empty_cache() 45 | yield utter_history, history 46 | 47 | # log 48 | current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') 49 | print(f'{current_time} request_ip:{request.client.host}\nquery: {message}\nhistory: {json.dumps(history, ensure_ascii=False)}\nanswer: {json.dumps(utter_history[-1][1], ensure_ascii=False)}') 50 | 51 | def get_args(): 52 | parser = argparse.ArgumentParser() 53 | parser.add_argument("--port", type=int, default=36000, 54 | help="server port") 55 | parser.add_argument("--title", type=str, default="XVERSE-7B-Chat", 56 | help="server title") 57 | parser.add_argument("--model_path", type=str, default="./VERSE-7B-Chat", 58 | help="model path") 59 | parser.add_argument("--tokenizer_path", type=str, default="./XVERSE-7B-Chat", 60 | help="Path to the tokenizer.") 61 | args = parser.parse_args() 62 | return args 63 | 64 | if __name__ == "__main__": 65 | args = get_args() 66 | # 初始化模型 67 | init_model(args) 68 | 69 | # 构建demo应用 70 | with gr.Blocks(css=css) as demo: 71 | gr.Markdown("#
{}
".format(args.title)) 72 | chatbot = gr.Chatbot(label="Chat history", height=650) 73 | state = gr.State([]) 74 | 75 | with gr.Row(): 76 | text_box = gr.Textbox(label="Message", show_label=False, placeholder="Enter message and press enter") 77 | 78 | with gr.Row(): 79 | submit_btn = gr.Button(value="Send", variant="secondary") 80 | reset_btn = gr.Button(value="Reset") 81 | 82 | text_box.submit(fn=chat, 83 | inputs=[text_box, state], 84 | outputs=[chatbot, state], 85 | api_name="chat") 86 | submit_btn.click(fn=chat, 87 | inputs=[text_box, state], 88 | outputs=[chatbot, state]) 89 | 90 | # 用于清空text_box 91 | def clear_textbox(): 92 | return gr.update(value="") 93 | text_box.submit(fn=clear_textbox, inputs=None, outputs=[text_box]) 94 | submit_btn.click(fn=clear_textbox, inputs=None, outputs=[text_box]) 95 | 96 | # 用于清空页面和重置state 97 | def reset(): 98 | return None, [] 99 | reset_btn.click(fn=reset, inputs=None, outputs=[chatbot, state]) 100 | 101 | demo.queue(concurrency_count=4) 102 | demo.launch(server_name="0.0.0.0", server_port=args.port) 103 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | transformers>=4.29.1 2 | torch>=2.0 3 | gradio>=3.39.0 4 | accelerate>=0.21.0 5 | cpm_kernels>=1.0.11 -------------------------------------------------------------------------------- /resources/modelscope.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xverse-ai/XVERSE-7B/551dea7e53be070e9f76188e450467200af320f2/resources/modelscope.png -------------------------------------------------------------------------------- /resources/wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xverse-ai/XVERSE-7B/551dea7e53be070e9f76188e450467200af320f2/resources/wechat.png -------------------------------------------------------------------------------- /text_generation_demo.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import torch 3 | 4 | import gradio as gr 5 | from transformers import AutoModelForCausalLM, AutoTokenizer 6 | 7 | 8 | tokenizer, model = None, None 9 | 10 | 11 | def init_model(args): 12 | global tokenizer, model 13 | tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_path, truncation_side="left", padding_side="left") 14 | model = AutoModelForCausalLM.from_pretrained(args.model_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto') 15 | model = model.eval() 16 | 17 | 18 | def batch_call(texts, skip_special_tokens=True, **kwargs): 19 | tokenized = tokenizer(texts, padding=True, return_tensors="pt") 20 | inputs = {key: value.cuda() for key, value in tokenized.items() if key != 'token_type_ids'} 21 | generate_ids = model.generate(**inputs, **kwargs) 22 | 23 | output =[] 24 | for tok, gen in zip(tokenized.input_ids, generate_ids): 25 | generated = tokenizer.decode(gen[len(tok):], skip_special_tokens=skip_special_tokens) 26 | output.append(generated) 27 | return output 28 | 29 | 30 | def text_generation(texts, max_new_tokens, temperature, top_k, top_p): 31 | output = batch_call(texts, max_new_tokens=max_new_tokens, do_sample=True, top_k=top_k, top_p=top_p, temperature=temperature, eos_token_id=tokenizer.eos_token_id) 32 | return output[0] 33 | 34 | 35 | def get_args(): 36 | parser = argparse.ArgumentParser() 37 | parser.add_argument("--port", type=int, default=20014, 38 | help="server port") 39 | parser.add_argument("--model_path", type=str, default="./model", 40 | help="Path to the model. Specifies the file path to the pre-trained model to be used for text generation.") 41 | parser.add_argument("--tokenizer_path", type=str, default="./model", 42 | help="Path to the tokenizer.") 43 | args = parser.parse_args() 44 | return args 45 | 46 | 47 | if __name__ == "__main__": 48 | args = get_args() 49 | 50 | # initialize model and tokenizer 51 | init_model(args) 52 | 53 | with gr.Blocks() as demo: 54 | gr.Markdown( 55 | "#
{}
".format("XVERSE-7B Text Generation")) 56 | with gr.Row(): 57 | with gr.Column(): 58 | inputs = gr.inputs.Textbox( 59 | lines=5, label="Input Text") # input 60 | with gr.Column(): 61 | max_new_tokens = gr.Slider(maximum=512, value=100, minimum=1, step=1, 62 | label="max_new_tokens", interactive=True) # max_new_tokens 63 | temperature = gr.Slider(maximum=1.0, value=1.0, minimum=0.0, step=0.05, 64 | label='temperature', interactive=True) # temperature 65 | top_k = gr.Slider(maximum=50, value=50, minimum=0, step=1, 66 | label='Top K', interactive=True) # top_k 67 | top_p = gr.Slider(maximum=1, value=0.92, minimum=0, 68 | step=0.02, label='Top P', interactive=True) # top_p 69 | 70 | with gr.Row(): 71 | outputs = gr.inputs.Textbox(lines=2, label="Output Text") 72 | 73 | with gr.Row(): 74 | submit_btn = gr.Button(value="生成", variant="secondary") 75 | reset_btn = gr.ClearButton(components=[inputs, outputs], value="清除", variant="secondary") 76 | 77 | submit_btn.click(fn=text_generation, 78 | inputs=[inputs, max_new_tokens, 79 | temperature, top_k, top_p], 80 | outputs=outputs) 81 | 82 | demo.launch(server_name="0.0.0.0", server_port=args.port) 83 | --------------------------------------------------------------------------------