microsoft/deberta-v3-small 是微软发布的 DeBERTa-v3 系列小尺寸模型,采用 DeBERTa-v2 架构(Decoding-enhanced BERT with disentangled attention)。
| 参数 | 值 | 说明 |
|---|---|---|
model_type | deberta-v2 | DeBERTa-v2 架构 |
hidden_size | 768 | 隐藏层维度 |
num_hidden_layers | 6 | Transformer 层数 |
num_attention_heads | 12 | 注意力头数 |
vocab_size | 128100 | 词表大小 |
max_position_embeddings | 512 | 最大序列长度 |
intermediate_size | 3072 | FFN 中间维度 |
relative_attention | true | 相对注意力 |
position_buckets | 256 | 位置桶数 |
pos_att_type | p2c|c2p | 位置-内容双向注意力 |
norm_rel_ebd | layer_norm | 相对嵌入层归一化 |
share_att_key | true | 共享注意力键 |
type_vocab_size | 0 | DeBERTa-v3 特点 |
layer_norm_eps | 1e-07 | LayerNorm eps |
position_biased_input | false | 位置偏置输入 |
[MASK] 掉的词详见 requirements.txt。核心依赖:
torch ≥ 2.5.0torch_npu ≥ 2.5.0transformers ≥ 4.30.0numpy ≥ 1.24.0# 设置 hf-mirror 镜像
export HF_ENDPOINT=https://hf-mirror.com
export HF_HUB_DISABLE_XET=1
# 拉权重到 /opt/atomgit/models/deberta-v3-small
python -c "
from huggingface_hub import snapshot_download
snapshot_download(
repo_id='microsoft/deberta-v3-small',
local_dir='/opt/atomgit/models/deberta-v3-small',
ignore_patterns=['*.gitattributes','*.md','tf_model.h5'],
)
print('[OK] 拉 deberta-v3-small 权重完成')
"# 蛑推理
python inference.py --model_path /opt/atomgit/models/deberta-v3-small推理输出包含:
[0] The weather is doby today.
[1] Machine learning is a subfield of artificial intelligence.
[2] The capital of China is Beijing.[NPU 检查] torch_npu 版本: 2.5.0
[NPU 检查] 可用 NPU 卡数: 16
[NPU 检查] npu:0 型号: Ascend910_9362
[加载] DeBERTa-v3-small 加载完成, 耗时 1.95s
[加载] device: npu:0
[加载] 模型类型: DebertaV2ForMaskedLM
[准备] input_ids shape: torch.Size([3, 11])
[推理] 推理完成, 耗时 0.22s
[自检] 输入 input_ids shape: (3, 11)
[自检] logits shape: (3, 11, 128100)
[隐藏] logits max: 10.925224
[隐藏] logits mean: 1.339724
[稳定] logits std: 1.695780
[MASK 预测] 解码每个句子的 MASK token 预测:
[0] The weather is doby today.
MASK 位置: 4, Top-5 预测:
[1] 'exercise' (logit=8.4818)
[2] 'occa' (logit=8.3994)
[3] 'burp' (logit=8.3565)
[4] '2021' (logit=7.9252)
[5] 'embe' (logit=7.5942)
[1] Machine learning is a subfield of artificial intelligence.
MASK 位置: 5, Top-5 预测:
[1] 'Neo' (logit=8.1063)
[2] 'tara' (logit=7.8494)
[3] 'embe' (logit=7.7584)
[4] 'occa' (logit=7.3832)
[5] 'burp' (logit=7.3175)
[2] The capital of China is Beijing.
MASK 位置: 6, Top-5 预测:
[1] 'embe' (logit=9.2395)
[2] 'Ezekiel' (logit=8.4448)
[3] 'Melee' (logit=8.1267)
[4] 'burp' (logit=8.0821)
[5] '2021' (logit=8.0154)
[完成] microsoft/deberta-v3-small (DeBERTa-v3-small 文本编码 + MASK 预测) 昇腾 NPU 推理成功| 指标 | 值 | 说明 |
|---|---|---|
| 模型加载耗时 | 1.95s | 从磁盘加载到 NPU |
| 推理耗时 | 0.22s | 3 个句子前向推理 |
| logits shape | (3, 11, 128100) | [batch, seq_len, vocab_size] |
| logits max | 10.925 | 非全 0,真跑通 |
| logits std | 1.696 | 方差合理,非退化 |
| MASK 预测 | Top-5 合理 | 语义相关词预测 |
deberta-v3-small/
├── inference.py # 推理脚本(必选)
├── readme.md # 部署说明文档(必选)
├── requirements.txt # 环境依赖清单(推荐)
├── pull_model.sh # 拉权重脚本(辅助)
├── push_repo.py # 建仓推交付件脚本(辅助)
└── assets/ # 截图素材文件夹(必选)
├── agent_workflow.png
├── npu_device_call.png
└── model_result.pngimport torch_npu 注册 Ascend NPU 后端torch.npu.is_available() 检测 NPU 可用性,torch.npu.set_device(0) 选定 0 号卡model.to("npu:0") + input_tensor.to("npu:0") 将模型和输入迁移到 NPUmodel.eval() + torch.no_grad() 关闭梯度计算| 项目 | 数值 |
|---|---|
| NPU 卡型号 | Ascend910_9362 |
| 可用 NPU 卡数 | 16 |
| 模型加载耗时 | 1.95s |
| 推理耗时 | 0.22s |
| logits max | 10.925 |
| logits std | 1.696 |
A: 这是 HuggingFace 模型卡的默认警告,提示用户 DeBERTa-v3-small 是预训练模型,建议在下游任务上微调。不影响推理——logits 数值正常(max 10.925, std 1.696)就是真跑通。
A: DeBERTa-v3-small 是小尺寸模型(6 层,768 维),MLM 预测能力有限。要获得更好的 MASK 预测,建议:
A: 推理脚本自动检测 NPU 可用性,如果 NPU 不可用会自动回退到 CPU。无需修改代码。
本项目推理脚本采用 MIT License。
模型权重遵循原模型许可证:MIT License。