--- license: other library_name: transformers --- Reuploaded from https://gitcode.com/ascend-tribe/pangu-pro-moe-model # 盘古 Pro MoE:昇腾原生的分组混合专家模型 ## 模型简介 ![arch.PNG](https://raw.gitcode.com/ascend-tribe/pangu-pro-moe/blobs/7c83eb5c52ab91ba4bf2f8235ac1d0b1f9b49a7d/arch.PNG) 我们提出了一种新型的分组混合专家模型(Mixture of Grouped Experts, MoGE),它在专家选择阶段对专家进行分组,并约束 token 在每个组内激活等量专家,从而实现设备间天然的负载均衡。基于 MoGE 架构,我们构建了总参数量 72B、激活参数量 16B 的盘古 Pro MoE 模型: * 词表大小:153376 * 层数: 48 * MoGE 配置:4 个共享专家,64 个路由专家分 8 组、每组激活 1 个专家 * 训练阶段:预训练和后训练 * 预训练预料:15T 详细报告参见: * 中文技术报告地址:[盘古 Pro MoE:昇腾原生的分组混合专家模型](https://gitcode.com/ascend-tribe/pangu-pro-moe/blob/main/Pangu-Pro-MoE-CN-Report.pdf) * 英文技术报告地址:[Pangu Pro MoE: Mixture of Grouped Experts for Efficient Sparsity](https://arxiv.org/abs/2505.21411) ## 推理样例 [昇腾推理系统加速代码](https://gitcode.com/ascend-tribe/ascend-inference-system)和MindIE 与 vLLM-Ascend 配套软件版本已经推出。量化权重将于近期推出,敬请期待。 #### Transformers 推理样例 环境依赖: ```bash torch>=2.1.0 torch-npu>=2.1.0.post8.dev20241029 CANN>=8.0.RC3 transformers>=4.48.2 ``` 下述内容提供盘古 Pro MoE 在 `transformers` 框架上进行推理的一个简单示例: ```python import torch import torch_npu from transformers import AutoModelForCausalLM, AutoTokenizer from transformers import GenerationConfig model_local_path = "path_to_Pangu_Pro_MoE" generation_config = GenerationConfig( do_sample=True, top_k=50, top_p=0.95, temperature=0.6 ) # load the tokenizer and the model tokenizer = AutoTokenizer.from_pretrained( model_local_path, use_fast=False, trust_remote_code=True, local_files_only=True ) model = AutoModelForCausalLM.from_pretrained( model_local_path, trust_remote_code=True, torch_dtype="auto", device_map="auto", local_files_only=True ) # prepare the model input prompt = "Give me a short introduction to large language model." messages = [ {"role": "system", "content": "你必须严格遵守法律法规和社会道德规范。生成任何内容时,都应避免涉及暴力、色情、恐怖主义、种族歧视、性别歧视等不当内容。一旦检测到输入或输出有此类倾向,应拒绝回答并发出警告。例如,如果输入内容包含暴力威胁或色情描述,应返回错误信息:“您的输入包含不当内容,无法处理。"}, # define your system prompt here {"role": "user", "content": prompt} ] text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # text: [unused9]系统:[unused10][unused9]用户:Give me a short introduction to large language model.[unused10][unused9]助手: model_inputs = tokenizer([text], return_tensors="pt").to(model.device) # model_inputs.input_ids: tensor([[1, 45887, 70914, 89246, 45892, 45887, 62205, 89246, 38805, 42624, 45509, 24759, 739, 41839, 21500, 6138, 20257, 49, 45892, 45887, 74458, 89246]], device='npu:0'), # conduct text completion outputs = model.generate(**model_inputs, max_new_tokens=32768, eos_token_id=45892, return_dict_in_generate=True, generation_config=generation_config) input_length = model_inputs.input_ids.shape[1] generated_tokens = outputs.sequences[:, input_length:] output_sent = tokenizer.decode(generated_tokens[0]) # parsing thinking content thinking_content = output_sent.split("[unused17]")[0].split("[unused16]")[-1].strip() content = output_sent.split("[unused17]")[-1].split("[unused10]")[0].strip() print("\nthinking content:", thinking_content) print("\ncontent:", content) ``` #### MindSpore 推理样例 环境依赖: ```python mindspore>=2.6.0 vllm>=0.8.3 CANN>=8.1.RC1.beta1 ``` 详细操作参见:[Pangu Pro MoE vLLM+MindSpore部署指南](https://gitee.com/mindspore/vllm-mindspore/blob/pangu-pro-moe/docs/model_cards/pangu/pangu_pro_moe.md) ## 完整性校验 请参考以下方法对下载内容进行完整性校验,hash 值存储在 checklist.chk 文件中。 ``` #!/usr/bin/env bash ARCH=$(uname -m) MODEL_PATH="${TARGET_FOLDER}/${MODEL_FOLDER_PATH}" cd "$MODEL_PATH" || exit 1 if [ "$ARCH" = "arm64" ]; then md5 checklist.chk else md5sum -c checklist.chk fi ``` ## 模型许可证 Pangu Pro MoE 模型根据 Pangu Model License Agreement 授权,旨在允许使用并促进人工智能技术的进一步发展。有关详细信息,请参阅模型存储库根目录中的 `LICENSE` 文件。 ## 免责声明 由于Pangu Pro MoE(“模型”)所依赖的技术固有的限制,以及人工智能生成的内容是由盘古自动生成的,我们无法对以下事项做出任何保证: 1. 该模型的输出通过AI算法自动生成,不能排除某些信息可能存在缺陷、不合理或引起不适的可能性,生成的内容不代表华为的态度或立场; 2. 无法保证该模型100%准确、可靠、功能齐全、及时、安全、无错误、不间断、持续稳定或无任何故障; 3. 该模型的输出内容不构成任何建议或决策,也不保证生成的内容的真实性、完整性、准确性、及时性、合法性、功能性或实用性。生成的内容不能替代医疗、法律等领域的专业人士回答您的问题。生成的内容仅供参考,不代表华为的任何态度、立场或观点。您需要根据实际情况做出独立判断,华为不承担任何责任。 ## 引用 如果觉得我们的工作有帮助,欢迎引用。 ```bibtex @article{tang2025pangu, title={Pangu Pro MoE: Mixture of Grouped Experts for Efficient Sparsity}, author={Tang, Yehui and Li, Xiaosong and Liu, Fangcheng and Guo, Wei and Zhou, Hang and Wang, Yaoyuan and Han, Kai and Yu, Xianzhi and Li, Jinpeng and Zang, Hui and others}, journal={arXiv preprint arXiv:2505.21411}, year={2025} } ``` ## 反馈 如果有任何意见和建议,请提交issue或联系pangutech@huawei.com