|
中文 | [English](README.md) |
|
|
|
## 1. 模型简介 |
|
|
|
openPangu-Embedded-7B 是基于昇腾 NPU 从零训练的高效大语言模型,参数量为 7B(不含词表Embedding)。openPangu-Embedded-7B 训练了约 19T tokens,具备快慢思考融合能力。 |
|
|
|
## 2. 模型架构 |
|
|
|
| | openPangu-Embedded-7B | |
|
| :---------------------------: | :----------------: | |
|
| **Architecture** | Dense | |
|
| **Parameters (Non-Embedding)** | 7B | |
|
| **Number of Layers** | 34 | |
|
| **Hidden Dimension** | 12800 | |
|
| **Attention Mechanism** | GQA | |
|
| **Number of Attention Heads** | 32 for Q,8 for KV | |
|
| **Vocabulary Size** | 153k | |
|
| **Context Length (Natively)** | 32k | |
|
| **Pretraining Tokens** | 19T | |
|
|
|
## 3. 测评结果 |
|
|
|
| 测评集 | 测评指标 | 慢思考 | |
|
| :---: | :---: | :---: | |
|
| **通用能力** | | | |
|
| MMLU-Pro | Exact Match | 76.32 | |
|
| CMMLU | Acc | 75.59 | |
|
| ArenaHard_v0.1 | w/o style control | 85.80 | |
|
| C-Eval | Acc | 83.05 | |
|
| GPQA-Diamond | Avg@4 | 70.54 | |
|
| **数学能力** | | | |
|
| MATH-500 | Avg@1 | 95.00 | |
|
| AIME24 | Avg@16 | 71.57 | |
|
| AIME25 | Avg@16 | 58.24 | |
|
| **代码能力** | | | |
|
| LiveCodeBench | Avg@2 (08/24~01/25) | 54.04 | |
|
| MBPP+ | Avg@2 | 76.06 | |
|
|
|
**注:** 评测过程中system prompt 为空,且不添加任何额外的思维链(CoT)提示。评测采用 128k 的序列长度进行。 |
|
|
|
## 4. 部署和使用 |
|
|
|
### 4.1 环境安装 |
|
|
|
```bash |
|
# 下载模型 |
|
git lfs install |
|
git clone https://huggingface.co/FreedomIntelligence/openPangu-Embedded-7B |
|
|
|
# 安装依赖 |
|
cd openPangu-Embedded-7B |
|
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 |
|
|
|
model_local_path = "FreedomIntelligence/openPangu-Embedded-7B" |
|
|
|
# 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." |
|
no_thinking_prompt = prompt+" /no_think" |
|
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:] |
|
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) |
|
``` |
|
|
|
openPangu-Embedded-7B 模型默认为慢思考模式,可以通过以下手段切换至快思考模式: |
|
- 在代码中,`no_thinking_prompt`变量的定义展示了切换至快思考模式的具体实现:通过在用户输入末尾添加`/no_think`标记,可将当前轮次切换至快思考模式。处于该模式时,`thinking_content`将为空值。 |
|
|
|
### 4.4 使用vLLM推理 |
|
|
|
启动vLLM服务: |
|
```bash |
|
CUDA_VISIBLE_DEVICES=0 vllm serve FreedomIntelligence/openPangu-Embedded-7B --port 8818 --trust_remote_code --served-model-name openPangu-Embedded-7B |
|
|
|
# 或者 |
|
CUDA_VISIBLE_DEVICES=0 \ |
|
python -m vllm.entrypoints.openai.api_server \ |
|
--model FreedomIntelligence/openPangu-Embedded-7B \ |
|
--served-model-name openPangu-Embedded-7B \ |
|
--trust_remote_code \ |
|
--port 8818 |
|
``` |
|
|
|
请求API服务: |
|
```bash |
|
curl http://localhost:8818/v1/chat/completions -H "Content-Type: application/json" -d '{ |
|
"model": "openPangu-Embedded-7B", |
|
"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-7B 模型根据 **OPENPANGU MODEL LICENSE AGREEMENT VERSION 1.0** 授权,旨在允许使用并促进人工智能技术的进一步发展。有关详细信息,请参阅模型存储库根目录中的 LICENSE 文件。 |
|
|
|
|
|
## 6. 免责声明 |
|
|
|
由于 openPangu-Embedded-7B(“模型”)所依赖的技术固有的技术限制,以及人工智能生成的内容是由盘古自动生成的,华为无法对以下事项做出任何保证: |
|
- 尽管该模型的输出由 AI 算法生成,但不能排除某些信息可能存在缺陷、不合理或引起不适的可能性,生成的内容不代表华为的态度或立场; |
|
- 无法保证该模型 100% 准确、可靠、功能齐全、及时、安全、无错误、不间断、持续稳定或无任何故障; |
|
- 该模型的输出内容不构成任何建议或决策,也不保证生成的内容的真实性、完整性、准确性、及时性、合法性、功能性或实用性。生成的内容不能替代医疗、法律等领域的专业人士回答您的问题。生成的内容仅供参考,不代表华为的任何态度、立场或观点。您需要根据实际情况做出独立判断,华为不承担任何责任。 |
|
|
|
如果有任何意见和建议,请提交issue或联系 [email protected]。 |
|
|