我们对 ERNIE-4.5-21B-A3B 和 ERNIE-4.5-300B-A47B 模型进行了一次重磅更新,大幅提升了长文本推理的速度。通过集成一种全新的稀疏注意力技术,你现在可以更快地处理长篇文档和对话,而且对效果的影响微乎其微。
目前,这一更新已经在 ERNIE-4.5-21B-A3B 和 ERNIE-4.5-300B-A47B 的 “-Paddle” 版本中上线,并且需要配合 FastDeploy 部署使用。
你将体验到什么?性能大幅提升 🚀
这次更新将为你带来显著的速度和效率提升。这两款更新后的模型都有了大幅的性能提升。
ERNIE-4.5-21B-A3B 性能提升
Metric | Before (Full Attention) | After (Sparse Attention) | Improvement |
---|---|---|---|
Queries Per Second (QPS) | 0.101 | 0.150 | +48% |
Decode Speed (token/s) | 13.32 | 18.12 | +36% |
Time to First Token (s) | 8.082 | 5.466 | -48% |
End-to-End Latency (s) | 61.400 | 42.157 | -46% |
ERNIE-4.5-300B-A47B 性能提升
Metric | Before (Full Attention) | After (Sparse Attention) | Improvement |
---|---|---|---|
Queries Per Second (QPS) | 0.066 | 0.081 | +23% |
Decode Speed (token/s) | 5.07 | 6.75 | +33% |
Time to First Token (s) | 13.812 | 10.584 | -30% |
End-to-End Latency (s) | 164.704 | 132.745 | -24% |
以上性能数据是在 InfiniteBench 的 longbook_sum_eng 子集上评估得出的,平均输入长度约为 113K token。
背后的技术:PLAS
之所以能实现如此快的速度,是因为我们引入了一种名为 PLAS(Pluggable Lightweight Attention for Sparsity,可插拔轻量级稀疏注意力) 的新型稀疏注意力机制。
传统的注意力机制需要将长文本中的每个 token 都与其他所有 token 进行比较,而 PLAS 的工作方式更智能。它将文本分成若干块,并使用一个小型且可学习的模块,智能地仅选择最相关的文本块进行计算。
它的“可插拔”特性意味着我们可以在一个已完全训练好的模型上添加 PLAS,而无需更改原始权重,从而确保模型的核心知识保持不变。
对效果的影响
我们深知性能不能以牺牲效果为代价。PLAS 机制的设计初衷就是尽可能地实现无损。我们在长文本基准测试中的评估结果显示,这两款模型的精度差异都可以忽略不计。
Model | Benchmark | Full Attention | Sparse Attention (PLAS) |
---|---|---|---|
ERNIE-4.5-21B-A3B | LongBenchV2 | 31.48 | 31.45 |
Ruler (128K) | 25.48 | 25.05 | |
ERNIE-4.5-300B-A47B | LongBenchV2 | 41.02 | 41.05 |
Ruler (128K) | 58.18 | 57.85 |
评估结果显示精度变化极小,确保了可靠的模型输出。
快速开始
如果你正在使用 -Paddle 版本的 ERNIE-4.5-21B-A3B 或 ERNIE-4.5-300B-A47B 模型,并且通过 FastDeploy 进行部署,那么启用稀疏注意力非常简单。
你只需设置环境变量,并在启动命令中添加 PLAS 配置即可。
# Set the environment variable to enable the PLAS attention backend
export FD_ATTENTION_BACKEND="PLAS_ATTN"
# Launch the API server with your model (e.g., ERNIE-4.5-300B-A47B-Paddle) and PLAS configuration
python -m fastdeploy.entrypoints.openai.api_server \
--model baidu/ERNIE-4.5-300B-A47B-Paddle \
--port 8180 \
--metrics-port 8181 \
--quantization wint4 \
--tensor-parallel-size 4 \
--engine-worker-queue-port 8182 \
--max-model-len 131072 \
--max-num-seqs 32 \
--max-num-batched-tokens 8192 \
--enable-chunked-prefill \
--plas-attention-config '{"plas_encoder_top_k_left": 50, "plas_encoder_top_k_right": 60,"plas_decoder_top_k_left": 100, "plas_decoder_top_k_right": 120}'
此命令示例来自 ERNIE-4.5-300B-A47B-Paddle 模型卡片。
想要了解更多技术细节,可以参考 PLAS Attention 官方文档。