中文 | [English](README.md) ## 1. 模型简介 openPangu-Embedded-1B 是基于昇腾 NPU 从零训练的高效语言模型,参数量为 1B(不含词表Embedding),模型结构采用 26 层 Dense 架构,训练了约 10T tokens。通过昇腾 Atlas 200I A2可用的模型架构设计、数据和训练策略优化,openPangu-Embedded-1B 在保持端侧运行的要求下达到了较高的精度。 ## 2. 模型架构 openPangu-Embedded-1B 是一个为端侧设备运行而设计的高效快思考语言模型。 | | openPangu-Embedded-1B | | :---------------------------: | :----------------: | | **Architecture** | Dense | | **Parameters (Non-Embedding)** | 1B | | **Number of Layers** | 26 | | **Hidden Dimension** | 1536 | | **Attention Mechanism** | GQA | | **Number of Attention Heads** | 12 for Q, 6 for KV | | **Vocabulary Size** | 153k | | **Context Length (Natively)** | 32k | | **Training Tokens** | 10T | ## 3. 测评结果 | 评测集 | 测评指标 | 快思考 | |:---: |:---: |:---: | | **通用能力** | | | MMLU | Acc | 60.72 | | CMMLU | Acc | 51.99 | | C-Eval | Acc | 60.98 | | IF-Eval | Prompt Strict | 56.56 | | CLUEWSC | Acc | 68.55 | | **数学&推理** | | | GSM8K | Acc | 66.72 | | MATH-500 | Acc | 52.00 | | DROP | F1 | 50.31 | | **代码能力** | | | MBPP | Pass@1 | 54.09 | | HumanEval | Pass@1 | 56.71 | **注:** 评测过程中system prompt 为空。 ## 4. 部署和使用 ### 4.1 环境安装 ```bash # 下载模型 git lfs install git clone https://huggingface.co/FreedomIntelligence/openPangu-Embedded-1B # 安装依赖 cd openPangu-Embedded-1B conda env create -f environment.yml conda activate pangu ``` ### 4.2 权重完整性校验 请参考以下方法对下载内容进行完整性校验,hash 值存储在 `checklist.chk` 文件中。 ```bash #!/usr/bin/env bash ARCH=$(uname -m) MODEL_PATH="${TARGET_FOLDER}/${MODEL_FOLDER_PATH}" cd "$MODEL_PATH" || exit 1 if [ "$ARCH" = "arm64" ]; then sha256sum checklist.chk else sha256sum -c checklist.chk fi ``` ### 4.3 使用Transformers推理 ```python # coding=utf-8 # Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. from transformers import AutoModelForCausalLM, AutoTokenizer from transformers import GenerationConfig model_local_path = "FreedomIntelligence/openPangu-Embedded-1B" # 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 sys_prompt = "你必须严格遵守法律法规和社会道德规范。" \ "生成任何内容时,都应避免涉及暴力、色情、恐怖主义、种族歧视、性别歧视等不当内容。" \ "一旦检测到输入或输出有此类倾向,应拒绝回答并发出警告。例如,如果输入内容包含暴力威胁或色情描述," \ "应返回错误信息:“您的输入包含不当内容,无法处理。”" prompt = "Give me a short introduction to large language model." messages = [ {"role": "system", "content": sys_prompt}, # define your system prompt here {"role": "user", "content": prompt} ] text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) model_inputs = tokenizer([text], return_tensors="pt").to(model.device) # conduct text completion outputs = model.generate(**model_inputs, max_new_tokens=32768, eos_token_id=45892, return_dict_in_generate=True) input_length = model_inputs.input_ids.shape[1] generated_tokens = outputs.sequences[:, input_length:] content = tokenizer.decode(generated_tokens[0], skip_special_tokens=True) print("\ncontent:", content) ``` ### 4.4 使用vLLM推理 启动vLLM服务: ```bash CUDA_VISIBLE_DEVICES=0 vllm serve FreedomIntelligence/openPangu-Embedded-1B --port 8818 --trust_remote_code --served-model-name openPangu-Embedded-1B # 或者 CUDA_VISIBLE_DEVICES=0 \ python -m vllm.entrypoints.openai.api_server \ --model FreedomIntelligence/openPangu-Embedded-1B \ --served-model-name openPangu-Embedded-1B \ --trust_remote_code \ --port 8818 ``` 请求API服务: ```bash curl http://localhost:8818/v1/chat/completions -H "Content-Type: application/json" -d '{ "model": "openPangu-Embedded-1B", "messages": [ {"role": "user", "content": "Give me a short introduction to large language models."} ], "temperature": 0.6, "top_p": 0.95, "top_k": 20, "max_tokens": 8192 }' ``` ## 5. 模型许可证 除文件中对开源许可证另有约定外,openPangu-Embedded-1B 模型根据 **OPENPANGU MODEL LICENSE AGREEMENT VERSION 1.0** 授权,旨在允许使用并促进人工智能技术的进一步发展。有关详细信息,请参阅模型存储库根目录中的 LICENSE 文件。 ## 6. 免责声明 由于 openPangu-Embedded-1B(“模型”)所依赖的技术固有的技术限制,以及人工智能生成的内容是由盘古自动生成的,华为无法对以下事项做出任何保证: - 尽管该模型的输出由 AI 算法生成,但不能排除某些信息可能存在缺陷、不合理或引起不适的可能性,生成的内容不代表华为的态度或立场; - 无法保证该模型 100% 准确、可靠、功能齐全、及时、安全、无错误、不间断、持续稳定或无任何故障; - 该模型的输出内容不构成任何建议或决策,也不保证生成的内容的真实性、完整性、准确性、及时性、合法性、功能性或实用性。生成的内容不能替代医疗、法律等领域的专业人士回答您的问题。生成的内容仅供参考,不代表华为的任何态度、立场或观点。您需要根据实际情况做出独立判断,华为不承担任何责任。 如果有任何意见和建议,请提交issue或联系 openPangu@huawei.com。