g
gcw_SlMYArPP/ERNIE-4-5-0-3B-Base-PT
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis
Chat Hugging Face Github Blog Discord X
License

ERNIE-4.5-0.3B-Base

[!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 completion API (not chat_completion) in vLLM/FastDeploy.

ERNIE 4.5 Highlights

The advanced capabilities of the ERNIE 4.5 models, particularly the MoE-based A47B and A3B series, are underpinned by several key technical innovations:

  1. 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.

  2. 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.

  3. 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.

Model Overview

ERNIE-4.5-0.3B-Base is a text dense Base model. The following are the model configuration details:

KeyValue
ModalityText
Training StagePretraining
Params0.36B
Layers18
Heads(Q/KV)16 / 2
Context Length131072

Quickstart

Using transformers library

Note: 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 inference

vllm github library. Python-only build.

vllm serve baidu/ERNIE-4.5-0.3B-Base-PT

Ascend NPU 适配验证

本模型已在 华为昇腾 Ascend NPU 上通过 vLLM-Ascend 框架完成完整适配验证,无需任何代码修改即可在 NPU 上运行。

环境信息

组件版本
OSLinux (aarch64)
PyTorch2.9.0
torch_npu2.9.0.post1
vLLM0.18.0
vLLM-Ascend0.18.0
CANN8.3.1
NPUAscend (Atlas 800 A2) × 2
Python3.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)

精度对比(NPU bf16 vs CPU fp32)

以 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 精度详情

#Prompt (前40字符)CPU Top-1NPU Top-1MAD (×10⁻⁷)余弦相似度Top-1一致
1The capital of China is" the"" the"2.60.99944186✅
2Machine learning is a field of" study"" study"2.60.99965572✅
3自然语言处理是人工智能中的重要方向,它主要研究"如何""如何"2.40.99976695✅
4Python is a programming language that" is"" is"3.60.99962145✅
5The theory of relativity was developed by" Albert"" Albert"1.10.99999231✅
6上海是中国最大的城市之一,它位于"中国""中国"3.00.99981481✅
7In mathematical optimization, gradient descent is" a"" a"2.30.99986172✅
8The Jupyter Notebook is an open-source web..." allows"" allows"2.20.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=320.56456.730.0176
Input=7tok, Output=641.13156.590.0177
Input=7tok, Output=1282.34754.540.0183
Input=11tok, Output=320.60652.820.0189
Input=11tok, Output=641.19653.500.0187
Input=11tok, Output=1282.42252.840.0189
Input=33tok, Output=320.59653.710.0186
Input=33tok, Output=641.26250.710.0197
Input=33tok, Output=1282.41752.960.0189

性能特征:

  • 模型加载时间:0.33 秒
  • 显存占用:0.7658 GB
  • KV Cache 容量:2,796,288 tokens
  • 最大并发请求数:682x(4096 tokens/请求)
  • 输出吞吐量稳定在 ~50-57 tok/s
  • TPOT(每输出 token 延迟):~17-20ms

NPU vs CPU 性能对比

设备数据类型平均推理延迟 (32 tok)
NPU (Ascend)bfloat160.675 s
CPU (x86)float328.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)。启用编译优化可进一步提升性能。

License

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.

Citation

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={}
}