飞桨PaddlePaddle/ERNIE-4.5-21B-A3B-Thinking
模型介绍文件和版本Pull Requests讨论分析
下载使用量0
Chat Hugging Face Github Blog Discord X
License

ERNIE-4.5-21B-A3B-Thinking

模型亮点

在过去的三个月中,我们持续提升ERNIE-4.5-21B-A3B的思维能力,改进推理的质量与深度,从而增强ERNIE轻量级模型在复杂推理任务中的竞争力。我们荣幸地推出ERNIE-4.5-21B-A3B-Thinking,其主要增强点如下:

  • 在推理任务上的性能显著提升,包括逻辑推理、数学、科学、代码编写、文本生成以及通常需要人类专业知识的学术基准测试。
  • 高效的工具使用能力。
  • 增强的128K长上下文理解能力。

[!NOTE] 注意:此版本的思维长度有所增加。我们强烈推荐将其用于高度复杂的推理任务。

benchmark

模型概述

ERNIE-4.5-21B-A3B-Thinking 是一款文本 MoE 后训练模型,总参数为 210 亿,每个 token 的激活参数为 30 亿。以下是模型配置详情:

关键项数值
模态文本
训练阶段后训练
参数(总计/激活)21B / 3B
层数28
注意力头数(Q/KV)20 / 4
文本专家数(总计/激活)64 / 6
视觉专家数(总计/激活)64 / 6
共享专家数2
上下文长度131072

快速入门

[!NOTE] 为与更广泛的社区保持一致,本模型发布 Transformer 风格权重。PyTorch 和 PaddlePaddle 生态工具(如 vLLM、transformers 和 FastDeploy)预计能够加载并运行此模型。

FastDeploy 推理

如下所示,使用 FastDeploy 快速部署服务。有关更详细的用法,请参阅 FastDeploy GitHub 仓库。

注意:需要 80GB x 1 GPU 资源。部署此模型需要 FastDeploy 2.2 版本。

python -m fastdeploy.entrypoints.openai.api_server \
       --model baidu/ERNIE-4.5-21B-A3B-Thinking \
       --port 8180 \
       --metrics-port 8181 \
       --engine-worker-queue-port 8182 \
       --load_choices "default_v1" \
       --tensor-parallel-size 1 \
       --max-model-len 131072 \
       --reasoning-parser ernie_x1 \
       --tool-call-parser ernie_x1 \
       --max-num-seqs 32

ERNIE-4.5-21B-A3B-Thinking模型支持函数调用。

curl -X POST "http://0.0.0.0:8180/v1/chat/completions" \
-H "Content-Type: application/json" \
-d $'{
  "messages": [
    {
      "role": "user",
      "content": "How \'s the weather in Beijing today?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Determine weather in my location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state e.g. San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "enum": [
                "c",
                "f"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "location",
            "unit"
          ]
        },
        "strict": true
      }
    }]
}'

vLLM 推理

vllm serve baidu/ERNIE-4.5-21B-A3B-Thinking

vLLM Ernie 的 reasoning-parser 和 tool-call-parser 目前正在开发中。

使用 transformers 库

注意:使用此模型需要安装 transformers 库(4.54.0 或更高版本)。

以下代码片段展示了如何使用模型根据给定输入生成内容。

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "baidu/ERNIE-4.5-21B-A3B-Thinking"

# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    device_map="auto",
    torch_dtype=torch.bfloat16,
)

# prepare the model input
prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], add_special_tokens=False, return_tensors="pt").to(model.device)

# conduct text completion
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=1024
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()

# decode the generated ids
generate_text = tokenizer.decode(output_ids, skip_special_tokens=True)
print("generate_text:", generate_text)

许可协议

ERNIE 4.5 模型基于 Apache License 2.0 协议提供。本协议允许商业使用,但需遵守其条款和条件。版权所有 (c) 2025 百度公司。保留所有权利。

引用说明

如果您认为 ERNIE 4.5 模型对您的工作有帮助,或希望在您的项目中使用该模型,请引用我们的技术报告:

@misc{ernie2025technicalreport,
      title={ERNIE 4.5 Technical Report},
      author={Baidu-ERNIE-Team},
      year={2025},
      primaryClass={cs.CL},
      howpublished={\url{https://ernie.baidu.com/blog/publication/ERNIE_Technical_Report.pdf}}
}