本文档记录 roberta-base-go_emotions(RoBERTa 情感分类模型)在昇腾 NPU(Ascend 910B3)环境的适配部署与精度验证结果。
RoBERTa-base-go-emotions 基于 RoBERTa-base 架构(约 124.7M 参数),在 GoEmotions 数据集上微调,可对文本进行 28 类细粒度情感分类。本项目完成该模型在昇腾 NPU 上的推理适配,验证 NPU 与 CPU 推理结果的精度误差 < 1%。
相关获取地址:
权重下载地址(HuggingFace):https://huggingface.co/roberta-base
适配代码仓库:https://gitcode.com/dingdang666/roberta-base-go_emotions-NPU
| 组件 | 版本 |
|---|---|
python | 3.11.x |
torch | 2.10.0+cpu |
torch_npu | 2.10.0 |
transformers | 5.8.1 |
CANN | 8.5.1 |
Ascend 910B3(8卡)/path/to/modelPyTorch + transformers| 项目 | 值 |
|---|---|
| 模型架构 | RoBERTa-base (RobertaForSequenceClassification) |
| 参数量 | ~124.7M |
| 分类类别 | 28 (GoEmotions) |
| 权重格式 | safetensors |
conda create -n roberta-emo python=3.11 -y
conda activate roberta-emo
pip install torch==2.10.0 --index-url https://repo.huaweicloud.com/repository/pypi/simple/
pip install torch_npu==2.10.0 --index-url https://repo.huaweicloud.com/repository/pypi/simple/
pip install transformers safetensors --index-url https://repo.huaweicloud.com/repository/pypi/simple/python3 inference.py --model_path /path/to/model --text "I love this!"
python3 inference.py ... --device cpu
python3 benchmark.py --model_path /path/to/model| 脚本 | 参数 | 说明 | 默认值 |
|---|---|---|---|
| inference.py | --model_path / --text / --device | 模型/文本/设备 | 必需 / I love this! / npu:0 |
| benchmark.py | --model_path / --npu_device / --num_warmup | 模型/NPU/预热 | 必需 / npu:0 / 3 |
使用同一输入文本在 CPU(FP32)和 NPU(FP32)上推理,对比分类 logits。
| 指标 | 数值 |
|---|---|
| 向量级相对误差 | 0.039385% |
| 余弦相似度 | 0.9999998808 |
| 评价指标 | 实测值 | 阈值 | 状态 |
|---|---|---|---|
| 向量级相对误差 | 0.04% | < 1% | PASS |
| 操作 | 耗时 |
|---|---|
| CPU 推理时间(FP32) | 0.44 s |
| NPU 推理时间(FP32,3轮预热后) | 0.02 s |
| 加速比 (CPU / NPU) | 24.62 x |
export HF_ENDPOINT=https://hf-mirror.com/。