d
dingdang666/roberta-base-go_emotions-NPU
模型介绍文件和版本Pull Requests讨论分析

roberta-base-go_emotions on Ascend NPU

1. 简介

本文档记录 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

2. 验证环境

组件版本
python3.11.x
torch2.10.0+cpu
torch_npu2.10.0
transformers5.8.1
CANN8.5.1
  • NPU:Ascend 910B3(8卡)
  • 模型路径:/path/to/model
  • 框架:PyTorch + transformers

3. 模型信息

项目值
模型架构RoBERTa-base (RobertaForSequenceClassification)
参数量~124.7M
分类类别28 (GoEmotions)
权重格式safetensors

4. Conda 环境安装

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/

5. 推理执行

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

6. 参数说明

脚本参数说明默认值
inference.py--model_path / --text / --device模型/文本/设备必需 / I love this! / npu:0
benchmark.py--model_path / --npu_device / --num_warmup模型/NPU/预热必需 / npu:0 / 3

7. 精度评测

使用同一输入文本在 CPU(FP32)和 NPU(FP32)上推理,对比分类 logits。

指标数值
向量级相对误差0.039385%
余弦相似度0.9999998808
评价指标实测值阈值状态
向量级相对误差0.04%< 1%PASS

8. 性能数据

操作耗时
CPU 推理时间(FP32)0.44 s
NPU 推理时间(FP32,3轮预热后)0.02 s
加速比 (CPU / NPU)24.62 x

9. 注意事项

  1. 如果 HuggingFace 无法访问,设置 export HF_ENDPOINT=https://hf-mirror.com/。
  2. NPU 首次推理包含编译优化,脚本默认 3 轮预热。
  3. 权重文件不包含在适配仓库中,需单独下载。
下载使用量0