本仓库为 MiniMax/VTP-Small-f16d64 模型提供在华为昇腾 NPU 上的适配推理、性能测试与精度验证脚本。
原始权重来源:https://gitcode.com/MiniMax-AI/VTP-Small-f16d64
| 属性 | 数值 |
|---|---|
| 架构 | VTP (Visual Tokenizer Pre-training) |
| 参数量 | 167.2M |
| 输入尺寸 | [3, 256, 256] |
| Vision Embed Dim | 384 |
| Vision Depth | 12 |
| Vision Patch Size | 16 |
| Text Embed Dim | 768 |
| Text Depth | 12 |
pip install torch torchvision transformers timm omegaconf pillow说明:
torch_npu需根据您的 CANN 版本安装,请参考昇腾官方文档。
modelscope download --model MiniMax/VTP-Small-f16d64 --local_dir ./weight/VTP-Small-f16d64在 NPU 上执行单图特征提取推理:
python3 inference.py --device npu --image assets/dog.pngLoading model on NPU...
Model parameters: 167.2M
Loading image from assets/dog.png...
Input tensor shape: torch.Size([1, 3, 256, 256])
CLS token shape: torch.Size([1, 384])
Patch tokens shape: torch.Size([1, 256, 384])
CLS token top-5 values: [3.506739 3.3904345 3.267725 3.1618907 2.7488108]
Inference completed successfully!本模型通过
model.to("npu")直接加载到 NPU 运行,无需对第三方库代码进行 monkey-patch。
测试不同 batch size 下的推理延迟与吞吐量:
python3 benchmark.py --device npu| Batch Size | 平均延迟 (ms) | 吞吐量 (samples/s) |
|---|---|---|
| 1 | 14.390 | 69.49 |
| 2 | 14.378 | 139.10 |
| 4 | 14.043 | 284.84 |
| 8 | 14.156 | 565.12 |
| 16 | 14.309 | 1118.20 |
对比 NPU 与 CPU 基线的输出一致性:
python3 accuracy.py --batch_size 1| 指标 | 数值 |
|---|---|
| MSE | 0.000003 |
| MAE | 0.001299 |
| 范围归一化相对误差 (%) | 0.029979 |
| 余弦相似度 | 0.999999 |
| 最大绝对差 | 0.005011 |
验证结论:通过 — 范围归一化相对误差 = 0.0300% < 1%,余弦相似度 = 0.999999
| 文件 | 说明 |
|---|---|
inference.py | NPU 单图特征提取推理脚本 |
benchmark.py | 多 batch 延迟与吞吐量测试 |
accuracy.py | NPU 与 CPU 精度对比 |
vtp/ | VTP 模型源代码(来自原始仓库) |
assets/dog.png | 测试用示例图片 |
output/ | 运行日志 |
@article{vtp,
title={Towards Scalable Pre-training of Visual Tokenizers for Generation},
author={Yao, Jingfeng and Song, Yuda and Zhou, Yucong and Wang, Xinggang},
journal={arXiv preprint arXiv:2512.13687},
year={2025}
}