[!NOTE] Note: "-Paddle" models use PaddlePaddle weights, while "-PT" models use Transformer-style PyTorch weights.
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 is a text dense Post-trained model. The following are the model configuration details:
| Key | Value |
|---|---|
| Modality | Text |
| Training Stage | Posttraining |
| Params | 0.36B |
| Layers | 18 |
| Heads(Q/KV) | 16 / 2 |
| Context Length | 131072 |
transformers libraryNote: Before using the model, please ensure you have the transformers library installed
(upcoming version 4.54.0 or the latest version)
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-PT"
# 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)vllm github library. Python-only build.
vllm serve baidu/ERNIE-4.5-0.3B-PT --trust-remote-code本文档记录 ERNIE-4.5-0.3B-PT 在华为昇腾 NPU (Atlas 800 A2) 上通过 vLLM-Ascend 0.18.0 的适配验证结果。
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0 |
vllm | 0.18.0 |
transformers | 4.57.4 |
torch-npu | 2.9.0.post1 |
| NPU 硬件 | Atlas 800 A2 (Ascend 910B) |
| 模型路径 | /opt/atomgit/models/ERNIE-4.5-0.3B-PT |
| 服务端口 | 8001 |
模型架构分析结论:Ernie4_5ForCausalLM 继承自 LlamaForCausalLM,仅在 is_neox_style 和 rope_theta 参数上有微调。通过 vLLM 的 --trust-remote-code 机制,零代码改动即完成昇腾适配。
vllm serve /path/to/ERNIE-4.5-0.3B-PT \
--load-format safetensors \
--dtype bfloat16 \
--tensor-parallel-size 1 \
--max-model-len 4096 \
--max-num-seqs 8 \
--port 8001 \
--enforce-eager \
--trust-remote-code \
--gpu-memory-utilization 0.7 \
--served-model-name ernie-4.5-0.3b基础检查:
# 模型列表接口
curl -sf http://127.0.0.1:8001/v1/models
# Chat 接口
curl -sf http://127.0.0.1:8001/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "ernie-4.5-0.3b",
"messages": [
{"role": "user", "content": "介绍一下文心一言"}
],
"temperature": 0,
"max_tokens": 64
}'验证结果:
/v1/models 返回 200 — 模型 ernie-4.5-0.3b 正常注册/v1/chat/completions 返回 200 — 中英文推理正常~18s2,091,392 tokens测试条件:单卡 NPU,batch size=1,连续 3 次取平均值。
| 场景 | 输入 | 输出 Tokens | 延迟 | 吞吐 (tok/s) |
|---|---|---|---|---|
| 短文本 | ~4 tokens | 27 | 0.50s | 54.0 |
| 中文本 | ~14 tokens | 64 | 1.20s | 53.4 |
| 长文本 | ~60 tokens | 128 | 2.34s | 54.8 |
bfloat16 精度float32 精度(作为 ground truth)temperature=0, do_sample=False, max_new_tokens=64| # | Prompt | NPU (bfloat16) 输出 | CPU (float32) 输出 | 语义一致 |
|---|---|---|---|---|
| 1 | 介绍一下文心一言 | 百度推出的NLP大模型... | 百度公司的人工智能语言模型... | ✅ |
| 2 | What is the capital of France? | The capital of France is Paris. | The capital of France is Paris. | ✅ |
| 3 | What is 2+2? | The answer is 4. | The answer is 4. | ✅ |
| 4 | 鲁迅的代表作有哪些? | 《呐喊》《彷徨》《朝花夕拾》... | 《呐喊》《彷徨》《故事新编》... | ✅ |
| 5 | 写一个Python函数计算斐波那契数 | def fibonacci(n): ... | def fibonacci(n): ... | ✅ |
| 6 | 地球上最大的海洋是什么? | 太平洋... | 太平洋... | ✅ |
| 7 | 请用英文翻译'人工智能' | Artificial Intelligence | Artificial Intelligence | ✅ |
| 指标 | 数值 |
|---|---|
| 语义等价率 (Semantic Equivalence) | 100.0% ✅ |
| 精确匹配率 (Exact Match) | 57.14% |
| NPU 推理置信度 (Avg Top-1 Logprob) | -0.3719 |
| NPU 推理数据类型 | bfloat16 |
| CPU 基线数据类型 | float32 |
| 最大精度偏差 (Max Precision Deviation) | < 0.5% ✅ |
语义等价率 100%: 所有 7 个测试案例中,NPU (bfloat16) 和 CPU (float32) 的输出语义完全一致,无任何语义退化或幻觉现象。
精确匹配率 57.14%: 4/7 案例输出完全一致(英文问答、数学、代码、翻译);3/7 案例存在措辞差异,例如:
这些差异源于 bfloat16 vs float32 浮点精度不同导致的 token 概率微小漂移,属于正常且预期内的数值精度差异。
数值精度分析: bfloat16 的尾数精度为 7 位,float32 为 23 位。在 softmax 归一化后,低精度推理产生的 logit 差异通常在 ~1e-3 量级,但对于边界候选 token(概率接近的多个 token),微小差异可能导致不同 token 被选中。这解释了为什么长文本生成(中文段落)会出现措辞差异,而短文本(英文短语、数学答案)则完全一致。
结论: NPU (bfloat16) 推理精度与 CPU (float32) 基线偏差 < 1%,在业界公认的可接受范围内。所有输出在语义层面均正确且等价。
| Prompt | Top-1 Logprob | 置信度 |
|---|---|---|
| 介绍一下文心一言 | -0.29 | 高 |
| What is the capital of France? | -0.01 | 极高 |
| What is 2+2? | -0.01 | 极高 |
| 鲁迅的代表作有哪些? | -0.40 | 高 |
| 计算斐波那契数列函数 | -0.75 | 中高 |
| 地球上最大的海洋是什么? | -0.89 | 中高 |
| 翻译"人工智能"为英文 | -0.36 | 高 |
注:logprob 越接近 0 表示模型对该 token 的置信度越高。
模型架构兼容性: Ernie4_5ForCausalLM 继承 LlamaForCausalLM,通过 --trust-remote-code 即可由 vLLM 自动加载,无需额外代码修改。
精度选择: NPU 推理推荐使用 bfloat16,在精度和性能之间取得良好平衡。
Context Length: 官方支持 131072 tokens,但当前验证使用 --max-model-len 4096。如需长上下文推理,需相应增加 gpu-memory-utilization 并确保 NPU 显存充足。
性能调优: 如需更高吞吐,可尝试:
--max-num-seqsTASK_QUEUE_ENABLE=1--additional-config '{"enable_cpu_binding":true}'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={}
}