├── LICENSE ├── MODEL_LICENSE.pdf ├── README.md ├── README_EN.md ├── 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-MoE-A36B/d720fb007ba87aba3f2bf73dcb26bd32d7119032/MODEL_LICENSE.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | XVERSE-MoE-A36B 4 |

5 |
6 | 7 |

8 | 🤗 Hugging Face | 9 | ModelScope | 10 | 💬 微信社区 11 |

12 | 13 |

14 |

15 | 中文 | 16 | English 17 |

18 |

19 | 20 | ## 更新信息 21 | - **[2024/09/13]** 发布 MoE 架构的 **XVERSE-MoE-A36B** 底座模型,Chat 对齐模型将在后续发布。 22 | 23 | ## 模型介绍 24 | 25 | **XVERSE-MoE-A36B** 是由深圳元象科技自主研发的支持多语言的大语言模型(Large Language Model),使用混合专家模型(MoE,Mixture-of-experts)架构,模型的总参数规模为 2554 亿,实际激活的参数量为 360 亿,本次开源的模型为底座模型 **XVERSE-MoE-A36B**,主要特点如下: 26 | 27 | - **模型结构**:XVERSE-MoE-A36B 为 Decoder-only 的 Transformer 架构,将密集模型的 FFN 层扩展为专家层,不同于传统 MoE 中每个专家的大小与标准 FFN 相同(如Mixtral 8x7B ),使用了更细粒度的专家,每个专家是标准 FFN 大小的 1/4,并设置了共享专家(Shared Expert)和非共享专家(Non-shared Expert)两类,共享专家在计算时始终被激活,非共享专家通过 Router 选择性激活。 28 | - **训练数据**:构建了海量高质量、多样化的数据对模型进行充分训练,包含中、英、俄、西等 40 多种语言,通过精细化设置不同类型数据的采样比例,使得中英两种语言表现优异,也能兼顾其他语言效果;模型使用 8K 长度的训练样本进行训练;在模型训练过程中进行了若干次数据的切换,来动态的引入持续处理的高质量数据,同时伴随数据采样比的调整。 29 | - **训练策略**:在切换数据的同时,为了使模型对新进数据进行快速且充分的学习,对学习率调度器也进行了相应调整。 30 | - **训练框架**:针对 MoE 模型中独有的专家路由和权重计算逻辑,进行了深入定制优化,开发出一套高效的融合算子,以提升计算效率。同时,为解决 MoE 模型显存占用和通信量大的挑战,设计了计算、通信和 CPU-Offload 的 Overlap 处理方式,从而提高整体吞吐量。 31 | 32 | **XVERSE-MoE-A36B** 的模型大小、架构和学习率如下: 33 | 34 | | total params | activated params | n_layers | d_model | n_heads | d_ff | n_non_shared_experts | n_shared_experts | top_k | lr | 35 | | :----------: | :--------------: | :------: | :-----: | :-----: | :--: | :------------------: | :--------------: | :---: | :----: | 36 | | 255.4B | 36.5B | 50 | 6144 | 48 | 4096 | 64 | 2 | 6 | 2.5e−4 | 37 | 38 | ## 评测结果 39 | 40 | 为了综合评估模型的性能,我们在一系列标准数据集上进行了全面测试,包括 MMLU、C-Eval、CMMLU、RACE-M、PIQA、GSM8K、MATH、MBPP 和 HumanEval,这些评估数据集覆盖了模型在多个领域的能力。并与相近参数规模的开源 MoE 和 Dense 模型(Base)以及闭源 Chat 模型进行了对比,结果如下: 41 | 42 | **对比开源 Base 模型 - MoE** 43 | | | XVERSE-MoE-A36B | Grok-1-A85B | DeepSeek-V2-A21B | Skywork-MoE-A22B | Mixtral-8x22B-A39B | DBRX-A36B | 44 | | :----------: | :-------------: | :---------: | :--------------: | :--------------: | :----------------: | :-------: | 45 | | Total Params | 255B | 314B | 236B | 146B | 141B | 132B | 46 | | MMLU | **80.8** | 73 | 78.5 | 77.4 | 77.8 | 73.7 | 47 | | C-Eval | 79.5 | - | 81.7 | 82.2 | 56.8 | 44.9 | 48 | | CMMLU | 81.7 | - | 84 | 79.5 | 59.9 | 61.3 | 49 | | GSM8K | **89.5** | 62.9 | 79.2 | 76.1 | 82.3 | 70.7 | 50 | | MATH | **53.3** | 23.9 | 43.6 | 31.9 | 34.1 | 25.6 | 51 | | HumanEval | 51.8 | 63.2 | 48.8 | 43.9 | 45.1 | 46.3 | 52 | | MBPP | 59.8 | - | 66.6 | - | 71.2 | 58 | 53 | | PIQA | **84.8** | - | 83.7 | - | 84.1 | 84.5 | 54 | | RACE-M | **88.4** | - | 73.1 | - | 85.7 | 55.9 | 55 | 56 | **对比开源 Base 模型 - Dense** 57 | | | XVERSE-MoE-A36B | XVERSE-65B-2 | Llama3.1-405B | Nemotron-4-340B | Qwen1.5-110B | Qwen2-72B | Qwen1.5-72B | Llama3.1-70B | 58 | | :----------: | :-------------: | :----------: | :-----------: | :-------------: | :----------: | :-------: | :---------: | :----------: | 59 | | Total Params | 255B | 65B | 405B | 340B | 110B | 72B | 72B | 70B | 60 | | MMLU | 80.8 | 74.4 | 85.2 | 81.1 | 80.4 | 84.2 | 77.5 | 79.3 | 61 | | C-Eval | 79.5 | 72.4 | - | - | 89.1 | 91 | 84.1 | - | 62 | | CMMLU | 81.7 | 75.1 | - | - | 88.3 | 90.1 | 83.5 | - | 63 | | GSM8K | **89.5** | 72.6 | 89 | - | 85.4 | 89.5 | 79.5 | 83.7 | 64 | | MATH | 53.3 | 20.8 | 53.8 | - | 49.6 | 51.1 | 34.1 | 41.4 | 65 | | HumanEval | 51.8 | 37.8 | 61 | 57.3 | 54.3 | 64.6 | 46.3 | 58.5 | 66 | | MBPP | 59.8 | 40.6 | 73.4 | - | 70.9 | 76.9 | 66.9 | 66.2 | 67 | | PIQA | 84.8 | 79.4 | 85.6 | - | | - | - | 83.8 | 68 | | RACE-M | 88.4 | 90.7 | - | - | | - | - | - | 69 | 70 | **对比闭源 Chat 模型** 71 | | | XVERSE-MoE-A36B | GPT-4o | abab-6.5-20240415 | Step-2 | Baichuan3 | GLM-4 (0520) | 72 | | :----------: | :-------------: | :----: | :---------------: | :----: | :-------: | :----------: | 73 | | Total Params | 255B | - | 万亿 | 万亿 | 千亿 | - | 74 | | MMLU | 80.8 | 88.7 | 78.7 | | 81.7 | 83.3 | 75 | | C-Eval | 79.5 | - | - | - | - | - | 76 | | CMMLU | 81.7 | - | - | - | 78.1 | - | 77 | | GSM8K | 89.5 | - | 91.7 | 94 | 88.2 | 93.3 | 78 | | MATH | 53.3 | 76.6 | 51.3 | 68.4 | 49.2 | 61.3 | 79 | | HumanEval | 51.8 | 90.2 | 78 | 84.1 | 70.1 | 78.5 | 80 | | MBPP | 59.8 | - | - | - | 68.2 | - | 81 | | PIQA | 84.8 | - | - | - | - | - | 82 | | RACE-M | 88.4 | - | - | - | - | - | 83 | 84 | 对于上述所有比较模型,我们汇报其官方结果与自测结果之间的最大值。 85 | 86 | ## 使用方法 87 | 88 | ### 环境安装 89 | 90 | 1. 下载本仓库: 91 | 92 | ```shell 93 | git clone https://github.com/xverse-ai/XVERSE-MoE-A36B 94 | cd XVERSE-MoE-A36B 95 | ``` 96 | 97 | 2. 使用 pip 安装依赖: 98 | 99 | ```shell 100 | pip install -r requirements.txt 101 | ``` 102 | ### Transformers 加载方式 103 | 104 | 可通过以下代码加载 XVERSE-MoE-A36B 模型来进行推理: 105 | 106 | ```python 107 | import torch 108 | from transformers import AutoTokenizer, AutoModelForCausalLM 109 | tokenizer = AutoTokenizer.from_pretrained("xverse/XVERSE-MoE-A36B") 110 | model = AutoModelForCausalLM.from_pretrained("xverse/XVERSE-MoE-A36B", trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto') 111 | model = model.eval() 112 | inputs = tokenizer('北京的景点:故宫、天坛、万里长城等。\n深圳的景点:', return_tensors='pt').input_ids 113 | inputs = inputs.cuda() 114 | generated_ids = model.generate(inputs, max_new_tokens=70, eos_token_id=tokenizer.eos_token_id, repetition_penalty=1.1) 115 | print(tokenizer.batch_decode(generated_ids, skip_special_tokens=True)) 116 | ``` 117 | 118 | ### 网页 Demo 119 | 120 | 可通过以下代码启动一个web server,在浏览器输入访问地址后,可使用 XVERSE-MoE-A36B 模型进行推理: 121 | 122 | ```shell 123 | python text_generation_demo.py --port='port' --model_path='/path/to/model/' --tokenizer_path='/path/to/tokenizer/' 124 | ``` 125 | 126 | ## 局限性与免责申明 127 | 128 | XVERSE-MoE-A36B 与其他所有 LLM 一样,在某些情况下可能会产生不准确、有偏见或其他令人反感的内容。因此,请谨慎使用模型生成的内容,请勿将生成的有害内容进行传播,在部署任何 XVERSE-MoE-A36B 的应用之前,开发人员应根据其具体应用对模型进行安全测试和调优。 129 | 130 | 我们强烈警告不要将 XVERSE-MoE-A36B 模型用于制造或传播有害信息,或进行任何可能损害公众、国家、社会安全或违反法规的活动。如果使用 XVERSE-MoE-A36B 模型产生任何问题,无论是数据安全问题、公共舆论风险,还是模型被误解、滥用、传播或不合规使用所引发的任何风险和问题,我们将不承担任何责任。 131 | 132 | ## 模型开源协议 133 | 134 | 使用本仓库的源码需要遵循 [Apache-2.0](LICENSE) 开源协议,使用 XVERSE-MoE-A36B 的模型权重则需要遵循[模型许可协议](MODEL_LICENSE.pdf)。 135 | 136 | XVERSE-MoE-A36B 模型权重对学术研究**完全开放**,并且支持**免费商用**。如需申请商业许可证,请填写【[申请表](https://chat.xverse.cn/home/business.html)】,如有其他问题或合作,请联系 。 137 | 138 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 |
2 |

3 | XVERSE-MoE-A36B 4 |

5 |
6 | 7 |

8 | 🤗 Hugging Face | 9 | ModelScope | 10 | 💬 WeChat 11 |

12 | 13 |

14 |

15 | 中文 | 16 | English 17 |

18 |

19 | 20 | ## Update Information 21 | - **[2024/09/13]** Released **XVERSE-MoE-A36B** MoE base model, the Chat version model will be released later. 22 | 23 | ## Model Introduction 24 | 25 | **XVERSE-MoE-A36B** is a multilingual large language model, independently developed by Shenzhen Yuanxiang Technology which is using Mixture-of-experts (MoE) architecture. The total parameter scale of the model is 255 billion, with an actual number of activated parameters being 36 billion. The models released this time is the base model **XVERSE-MoE-A36B**. Its key features are as follows: 26 | 27 | - **Model Structure**: XVERSE-MoE-A36B uses the mainstream Decoder-only Transformer network structure that extends the FFN layer of dense models to expert layers. Unlike traditional MoE model where each expert has the same size as standard FFN (such as Mixtral 8x7B), it uses more fine-grained experts, with each expert being 1/4 the size of a standard FFN. It includes shared experts and non-shared experts, where shared experts are always activated during computation, and non-shared experts are selectively activated through a Router. 28 | - **Training Data**: The model has been thoroughly trained on a large-scale high-quality dataset, 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; The model is trained using training samples of length 8k; During the model training process, several data switches were made to dynamically introduce continuously processed high-quality data, along with adjustments to the data sampling ratio. 29 | - **Training Strategy**: While switching data, corresponding adjustments were also made to the learning rate scheduler to ensure the model could quickly and thoroughly learn from the newly introduced data. 30 | - **Training Framework**: We conducted in-depth customized optimization for the unique expert routing and weight calculation logic in the MoE model, developed an efficient fusion operator to improve computational efficiency. At the same time, to address the challenges of high memory consumption and communication volume in the MoE model, we designed a processing method for overlapping computation, communication, and CPU-Offload to increase overall throughput. 31 | 32 | The models sizes, architectures and learning rate of **XVERSE-MoE-A36B** are showed as follows: 33 | 34 | | total params | activated params | n_layers | d_model | n_heads | d_ff | n_non_shared_experts | n_shared_experts | top_k | lr | 35 | | :----------: | :--------------: | :------: | :-----: | :-----: | :--: | :------------------: | :--------------: | :---: | :----: | 36 | | 255.4B | 36.5B | 50 | 6144 | 48 | 4096 | 64 | 2 | 6 | 2.5e−4 | 37 | 38 | ## Model Evaluation 39 | 40 | To comprehensively assess the performance of the model, we conducted extensive testing across a range of standard datasets, including MMLU, C-Eval, CMMLU, RACE-M, PIQA, GSM8K, Math, MBPP and HumanEval. And compared it with open-weight MoE and Dense models (Base) of similar parameter scales, as well as closed-source Chat models. The results are as follows: 41 | 42 | **Comparison of Open-Weight Base Models - MoE** 43 | | | XVERSE-MoE-A36B | Grok-1-A85B | DeepSeek-V2-A21B | Skywork-MoE-A22B | Mixtral-8x22B-A39B | DBRX-A36B | 44 | | :----------: | :-------------: | :---------: | :--------------: | :--------------: | :----------------: | :-------: | 45 | | Total Params | 255B | 314B | 236B | 146B | 141B | 132B | 46 | | MMLU | **80.8** | 73 | 78.5 | 77.4 | 77.8 | 73.7 | 47 | | C-Eval | 79.5 | - | 81.7 | 82.2 | 56.8 | 44.9 | 48 | | CMMLU | 81.7 | - | 84 | 79.5 | 59.9 | 61.3 | 49 | | GSM8K | **89.5** | 62.9 | 79.2 | 76.1 | 82.3 | 70.7 | 50 | | MATH | **53.3** | 23.9 | 43.6 | 31.9 | 34.1 | 25.6 | 51 | | HumanEval | 51.8 | 63.2 | 48.8 | 43.9 | 45.1 | 46.3 | 52 | | MBPP | 59.8 | - | 66.6 | - | 71.2 | 58 | 53 | | PIQA | **84.8** | - | 83.7 | - | 84.1 | 84.5 | 54 | | RACE-M | **88.4** | - | 73.1 | - | 85.7 | 55.9 | 55 | 56 | **Comparison of Open-Weight Base Models - Dense** 57 | | | XVERSE-MoE-A36B | XVERSE-65B-2 | Llama3.1-405B | Nemotron-4-340B | Qwen1.5-110B | Qwen2-72B | Qwen1.5-72B | Llama3.1-70B | 58 | | :----------: | :-------------: | :----------: | :-----------: | :-------------: | :----------: | :-------: | :---------: | :----------: | 59 | | Total Params | 255B | 65B | 405B | 340B | 110B | 72B | 72B | 70B | 60 | | MMLU | 80.8 | 74.4 | 85.2 | 81.1 | 80.4 | 84.2 | 77.5 | 79.3 | 61 | | C-Eval | 79.5 | 72.4 | - | - | 89.1 | 91 | 84.1 | - | 62 | | CMMLU | 81.7 | 75.1 | - | - | 88.3 | 90.1 | 83.5 | - | 63 | | GSM8K | **89.5** | 72.6 | 89 | - | 85.4 | 89.5 | 79.5 | 83.7 | 64 | | MATH | 53.3 | 20.8 | 53.8 | - | 49.6 | 51.1 | 34.1 | 41.4 | 65 | | HumanEval | 51.8 | 37.8 | 61 | 57.3 | 54.3 | 64.6 | 46.3 | 58.5 | 66 | | MBPP | 59.8 | 40.6 | 73.4 | - | 70.9 | 76.9 | 66.9 | 66.2 | 67 | | PIQA | 84.8 | 79.4 | 85.6 | - | | - | - | 83.8 | 68 | | RACE-M | 88.4 | 90.7 | - | - | | - | - | - | 69 | 70 | **Comparison of Closed-Source Chat Models** 71 | | | XVERSE-MoE-A36B | GPT-4o | abab-6.5-20240415 | Step-2 | Baichuan3 | GLM-4 (0520) | 72 | | :----------: | :-------------: | :----: | :---------------: | :------------: | :-------------------: | :----------: | 73 | | Total Params | 255B | - | Trillion scale | Trillion scale | Hundred billion scale | - | 74 | | MMLU | 80.8 | 88.7 | 78.7 | | 81.7 | 83.3 | 75 | | C-Eval | 79.5 | - | - | - | - | - | 76 | | CMMLU | 81.7 | - | - | - | 78.1 | - | 77 | | GSM8K | 89.5 | - | 91.7 | 94 | 88.2 | 93.3 | 78 | | MATH | 53.3 | 76.6 | 51.3 | 68.4 | 49.2 | 61.3 | 79 | | HumanEval | 51.8 | 90.2 | 78 | 84.1 | 70.1 | 78.5 | 80 | | MBPP | 59.8 | - | - | - | 68.2 | - | 81 | | PIQA | 84.8 | - | - | - | - | - | 82 | | RACE-M | 88.4 | - | - | - | - | - | 83 | 84 | For all the comparison models mentioned above, we report the maximum value between their official results and our self-evaluation results. 85 | 86 | ## Usage 87 | 88 | ### Environment Setup 89 | 90 | 1. Clone this repository: 91 | 92 | ```shell 93 | git clone https://github.com/xverse-ai/XVERSE-MoE-A36B 94 | cd XVERSE-MoE-A36B 95 | ``` 96 | 97 | 2. Install the dependencies using pip: 98 | 99 | ```shell 100 | pip install -r requirements.txt 101 | ``` 102 | 103 | ### Loading with Transformers 104 | 105 | The XVERSE-MoE-A36B model can be loaded for inference using the following code: 106 | 107 | ```python 108 | import torch 109 | from transformers import AutoTokenizer, AutoModelForCausalLM 110 | tokenizer = AutoTokenizer.from_pretrained("xverse/XVERSE-MoE-A36B") 111 | model = AutoModelForCausalLM.from_pretrained("xverse/XVERSE-MoE-A36B", trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto') 112 | model = model.eval() 113 | inputs = tokenizer('北京的景点:故宫、天坛、万里长城等。\n深圳的景点:', return_tensors='pt').input_ids 114 | inputs = inputs.cuda() 115 | generated_ids = model.generate(inputs, max_new_tokens=70, eos_token_id=tokenizer.eos_token_id, repetition_penalty=1.1) 116 | print(tokenizer.batch_decode(generated_ids, skip_special_tokens=True)) 117 | ``` 118 | 119 | ### Web Demo 120 | 121 | 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-MoE-A36B model: 122 | 123 | ```shell 124 | python chat_demo.py --port='port' --model_path='/path/to/model/' --tokenizer_path='/path/to/tokenizer/' 125 | ``` 126 | 127 | ## Limitations and Disclaimer 128 | 129 | Like all other Large Language Models (LLMs), XVERSE-MoE-A36B 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-MoE-A36B, developers should conduct safety tests and optimization of the model according to its specific application. 130 | 131 | We strongly warn against the use of the XVERSE-MoE-A36B 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-MoE-A36B 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. 132 | 133 | ## Open Source License 134 | 135 | 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-MoE-A36B needs to adhere to the [Model License Agreement](MODEL_LICENSE.pdf). 136 | 137 | The XVERSE-MoE-A36B 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 . 138 | 139 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | transformers>=4.41.0 2 | torch>=2.0.1 3 | gradio>=3.39.0 4 | accelerate>=0.27.2 5 | -------------------------------------------------------------------------------- /resources/modelscope.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xverse-ai/XVERSE-MoE-A36B/d720fb007ba87aba3f2bf73dcb26bd32d7119032/resources/modelscope.png -------------------------------------------------------------------------------- /resources/wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xverse-ai/XVERSE-MoE-A36B/d720fb007ba87aba3f2bf73dcb26bd32d7119032/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-MoE-25B 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 | --------------------------------------------------------------------------------