[!NOTE] Note: "-Paddle" models use PaddlePaddle weights, while "-PT" models use Transformer-style PyTorch weights.
[!NOTE] Note: The Base model only supports text completion. For evaluation, use the
completionAPI (notchat_completion) in vLLM/FastDeploy.
The advanced capabilities of the ERNIE 4.5 models, particularly the MoE-based A47B and A3B series, are underpinned by several key technical innovations:
Multimodal Heterogeneous MoE Pre-Training: Our models are jointly trained on both textual and visual modalities to better capture the nuances of multimodal information and improve performance on tasks involving text understanding and generation, image understanding, and cross-modal reasoning. To achieve this without one modality hindering the learning of another, we designed a heterogeneous MoE structure, incorporated modality-isolated routing, and employed router orthogonal loss and multimodal token-balanced loss. These architectural choices ensure that both modalities are effectively represented, allowing for mutual reinforcement during training.
Scaling-Efficient Infrastructure: We propose a novel heterogeneous hybrid parallelism and hierarchical load balancing strategy for efficient training of ERNIE 4.5 models. By using intra-node expert parallelism, memory-efficient pipeline scheduling, FP8 mixed-precision training and finegrained recomputation methods, we achieve remarkable pre-training throughput. For inference, we propose multi-expert parallel collaboration method and convolutional code quantization algorithm to achieve 4-bit/2-bit lossless quantization. Furthermore, we introduce PD disaggregation with dynamic role switching for effective resource utilization to enhance inference performance for ERNIE 4.5 MoE models. Built on PaddlePaddle, ERNIE 4.5 delivers high-performance inference across a wide range of hardware platforms.
Modality-Specific Post-Training: To meet the diverse requirements of real-world applications, we fine-tuned variants of the pre-trained model for specific modalities. Our LLMs are optimized for general-purpose language understanding and generation. The VLMs focuses on visuallanguage understanding and supports both thinking and non-thinking modes. Each model employed a combination of Supervised Fine-tuning (SFT), Direct Preference Optimization (DPO) or a modified reinforcement learning method named Unified Preference Optimization (UPO) for post-training.
ERNIE-4.5-0.3B-Base is a text dense Base model. The following are the model configuration details:
| Key | Value |
|---|---|
| Modality | Text |
| Training Stage | Pretraining |
| Params | 0.36B |
| Layers | 18 |
| Heads(Q/KV) | 16 / 2 |
| Context Length | 131072 |
transformers libraryNote: You'll need the transformers library (version 4.54.0 or newer) installed to use this model.
The following contains a code snippet illustrating how to use the model generate content based on given inputs.
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 library. Python-only build.
vllm serve baidu/ERNIE-4.5-0.3B-Base-PT本模型已在 华为昇腾 Ascend NPU 上通过 vLLM-Ascend 框架完成完整适配验证,无需任何代码修改即可在 NPU 上运行。
| 组件 | 版本 |
|---|---|
| OS | 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,对比内容包括概率分布差异(Mean Absolute Difference)、余弦相似度(Cosine Similarity)和 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× |
Input: Large language model is
NPU Output:
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)。启用编译优化可进一步提升性能。
The ERNIE 4.5 models are provided under the Apache License 2.0. This license permits commercial use, subject to its terms and conditions. Copyright (c) 2025 Baidu, Inc. All Rights Reserved.
If you find ERNIE 4.5 useful or wish to use it in your projects, please kindly cite our technical report:
@misc{ernie2025technicalreport,
title={ERNIE 4.5 Technical Report},
author={Baidu ERNIE Team},
year={2025},
eprint={},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={}
}