本文档记录 CoROM 中文句嵌入模型在昇腾 NPU (Ascend 910B3) 上的迁移适配与精度验证结果。
该模型基于 BERT-tiny 架构(4 层 Transformer,256 维隐层),通过对比学习训练实现中文句子级别的语义向量表示,可用于语义搜索、文本聚类等任务。
相关获取地址:
| 组件 | 版本 |
|---|---|
CANN | 8.5.1 |
torch | 2.8.0 |
torch_npu | 2.8.0.post4 |
transformers | latest |
modelscope | 1.37.0 |
Ascend 910B3,单卡推理[1, seq_len, 256] 隐层表示conda create -n nlp_corom_sentence-embedding_chinese-tiny python=3.10 -y
conda activate nlp_corom_sentence-embedding_chinese-tiny
pip install torch==2.8.0 torch_npu==2.8.0.post4 \
-i https://mirrors.huaweicloud.com/repository/pypi/simple
pip install transformers modelscope numpymodelscope download --model damo/nlp_corom_sentence-embedding_chinese-tiny \
--local_dir ./nlp_corom_sentence-embedding_chinese-tinypython inference.py --text "这是一段测试文本" --device npufrom inference import run_inference
result = run_inference("测试文本", device="npu")
print(f"向量维度: {result['embedding'].shape}, 耗时: {result['time_ms']:.1f}ms")python evaluate.py验证结果:
[1, seq_len, 256]测试条件:输入 4 个 token 的中文短句。
| 指标 | CPU | NPU (Ascend 910B3) |
|---|---|---|
| 推理耗时 | 266 ms | 8 ms |
| 加速比 | — | 35x |
| 指标 | 数值 |
|---|---|
| 输出形状 | [1, 6, 256] |
| 鲁棒平均相对误差 | 0.318% |
| 精度要求 | 平均相对误差 < 1% |
| 精度评测 | 通过 |
transformers.AutoModel.from_pretrained 加载,为 HuggingFace 兼容格式AutoTokenizer 分词,中文按字分词nlp_structbert_sentence-similarity_chinese-tiny 为同一架构的相似度版本,适配方式一致