[!NOTE] 注意:“-Paddle”模型使用PaddlePaddle权重,而“-PT”模型使用Transformer风格的PyTorch权重。
[!NOTE] 注意:Base模型仅支持文本补全。评估时,请使用vLLM/FastDeploy中的
completionAPI(而非chat_completion)。
ERNIE 4.5 模型的卓越性能,尤其是基于 MoE 的 A47B 和 A3B 系列,依托于多项关键技术创新:
多模态异构 MoE 预训练:我们的模型在文本和视觉两种模态上进行联合训练,以更好地捕捉多模态信息的细微差别,并提升在文本理解与生成、图像理解以及跨模态推理等任务上的表现。为了实现这一目标,同时避免一种模态阻碍另一种模态的学习,我们设计了异构 MoE 结构,融入了模态隔离路由机制,并采用了路由正交损失函数和多模态 token 均衡损失函数。这些架构设计确保两种模态都能得到有效表征,从而在训练过程中实现相互强化。
高效扩展基础设施:我们提出了一种新颖的异构混合并行与分层负载均衡策略,用于 ERNIE 4.5 模型的高效训练。通过采用节点内专家并行、内存高效的流水线调度、FP8 混合精度训练以及细粒度重计算方法,我们实现了显著的预训练吞吐量。在推理方面,我们提出了多专家并行协作方法和卷积码量化算法,以实现 4 位/2 位无损量化。此外,我们引入了具有动态角色切换的 PD 解耦技术,以实现有效的资源利用,从而提升 ERNIE 4.5 MoE 模型的推理性能。ERNIE 4.5 构建于 PaddlePaddle 之上,能够在广泛的硬件平台上提供高性能推理。
特定模态后训练:为了满足实际应用的多样化需求,我们针对特定模态对预训练模型的变体进行了微调。我们的 LLM 针对通用语言理解和生成进行了优化。VLM 则专注于视觉语言理解,并支持思考模式和非思考模式。每个模型在后续训练中均采用了监督微调(SFT)、直接偏好优化(DPO) 或一种名为统一偏好优化(UPO) 的改进型强化学习方法的组合。
ERNIE-4.5-0.3B-Base 是一个文本密集型基础模型。以下是模型配置详情:
| 关键项 | 数值 |
|---|---|
| 模态 | 文本 |
| 训练阶段 | 预训练 |
| 参数规模 | 0.36B |
| 网络层数 | 18 |
| 注意力头数(Q/KV) | 16 / 2 |
| 上下文长度 | 131072 |
transformers 库注意:使用此模型需要安装 transformers 库(4.54.0 或更新版本)。
以下代码片段展示了如何使用模型根据给定输入生成内容。
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "baidu/ERNIE-4.5-0.3B-Base-PT"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
torch_dtype=torch.bfloat16,
)
prompt = "Large language model is"
model_inputs = tokenizer([prompt], add_special_tokens=False, return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=1024
)
result = tokenizer.decode(generated_ids[0].tolist(), skip_special_tokens=True)
print("result:", result)vllm GitHub 库。仅支持 Python 的 构建。
vllm serve baidu/ERNIE-4.5-0.3B-Base-PT本模型已在 华为昇腾 Ascend NPU 上通过 vLLM-Ascend 框架完成完整适配验证,无需任何代码修改即可在 NPU 上运行。
| 组件 | 版本 |
|---|---|
| 操作系统 | Linux (aarch64) |
| PyTorch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| vLLM | 0.18.0 |
| vLLM-Ascend | 0.18.0 |
| CANN | 8.3.1 |
| NPU | Ascend (Atlas 800 A2) × 2 |
| Python | 3.11.14 |
import os
os.environ['NPU_VISIBLE_DEVICES'] = '0'
from vllm import LLM, SamplingParams
model_path = "baidu/ERNIE-4.5-0.3B-Base-PT"
llm = LLM(
model=model_path,
dtype='bfloat16',
max_model_len=4096,
gpu_memory_utilization=0.8,
enforce_eager=True,
trust_remote_code=True,
)
prompts = ["Large language model is"]
sampling_params = SamplingParams(temperature=0, max_tokens=32)
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
print(output.outputs[0].text)以 CPU float32 输出为基线,对比 NPU bfloat16 推理输出精度。测试覆盖中英文 8 组不同 prompt,对比内容包括概率分布差异(平均绝对误差)、余弦相似度和 Top-1 词元一致性。
| 指标 | 数值 |
|---|---|
| 平均概率绝对误差 (MAD) | 2.5×10⁻⁷ (0.000025%) |
| 最大概率绝对误差 | 3.6×10⁻⁷ (0.000036%) |
| 平均余弦相似度 | 0.99975458 |
| 最小余弦相似度 | 0.99944186 |
| Top-1 词元一致性 | 100% (8/8) |
| 结论 | ✅ 精度误差远小于 1% |
| # | Prompt (前40字符) | CPU Top-1 | NPU Top-1 | MAD (×10⁻⁷) | 余弦相似度 | Top-1一致 |
|---|---|---|---|---|---|---|
| 1 | The capital of China is | " the" | " the" | 2.6 | 0.99944186 | ✅ |
| 2 | Machine learning is a field of | " study" | " study" | 2.6 | 0.99965572 | ✅ |
| 3 | 自然语言处理是人工智能中的重要方向,它主要研究 | "如何" | "如何" | 2.4 | 0.99976695 | ✅ |
| 4 | Python is a programming language that | " is" | " is" | 3.6 | 0.99962145 | ✅ |
| 5 | The theory of relativity was developed by | " Albert" | " Albert" | 1.1 | 0.99999231 | ✅ |
| 6 | 上海是中国最大的城市之一,它位于 | "中国" | "中国" | 3.0 | 0.99981481 | ✅ |
| 7 | In mathematical optimization, gradient descent is | " a" | " a" | 2.3 | 0.99986172 | ✅ |
| 8 | The Jupyter Notebook is an open-source web... | " allows" | " allows" | 2.2 | 0.99988180 | ✅ |
NPU bfloat16 精度与 CPU float32 基线的 平均概率偏差仅为 0.000025%,远低于 1% 的误差阈值。余弦相似度均大于 0.9994,表明概率分布几乎完全一致。所有测试 prompt 的 Top-1 预测词元 100% 一致,证明 NPU bfloat16 推理精度无损。
在 Ascend NPU 上使用 vLLM-Ascend(enforce_eager 模式)的推理性能:
| 测试条件 | 延迟 (s) | 吞吐量 (tok/s) | TPOT (s/tok) |
|---|---|---|---|
| Input=7tok, Output=32 | 0.564 | 56.73 | 0.0176 |
| Input=7tok, Output=64 | 1.131 | 56.59 | 0.0177 |
| Input=7tok, Output=128 | 2.347 | 54.54 | 0.0183 |
| Input=11tok, Output=32 | 0.606 | 52.82 | 0.0189 |
| Input=11tok, Output=64 | 1.196 | 53.50 | 0.0187 |
| Input=11tok, Output=128 | 2.422 | 52.84 | 0.0189 |
| Input=33tok, Output=32 | 0.596 | 53.71 | 0.0186 |
| Input=33tok, Output=64 | 1.262 | 50.71 | 0.0197 |
| Input=33tok, Output=128 | 2.417 | 52.96 | 0.0189 |
性能特征:
| 设备 | 数据类型 | 平均推理延迟 (32 tok) |
|---|---|---|
| NPU (Ascend) | bfloat16 | 0.675 s |
| CPU (x86) | float32 | 8.176 s |
| NPU 加速比 | — | 12.12× |
输入: Large language model is
NPU 输出:
a type of deep learning model that is trained to recognize and generate text based on a large corpus of text data. It is a powerful tool for language processing and
ERNIE-4.5-0.3B-Base-PT 因继承 LlamaForCausalLM 架构(Ernie4_5ForCausalLM),已在 vLLM 注册表中原生支持,无需任何代码修改即可在 Ascend NPU 上实现高效推理。
| 验证项 | 状态 |
|---|---|
| 模型架构自动识别 (Ernie4_5ForCausalLM) | ✅ |
| vLLM-Ascend 模型加载 | ✅ |
| NPU bf16 推理(enforce_eager) | ✅ |
| 精度误差 < 1% | ✅ (0.000025%) |
| Top-1 词元 100% 一致 | ✅ |
| 输出吞吐量 > 50 tok/s | ✅ |
说明: 当前测试基于
enforce_eager=True模式(关闭 torch.compile 和 CUDAGraphs)。启用编译优化可进一步提升性能。
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},
eprint={},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={}
}