本仓库为 MiniMax/VTP-Base-f16d64 模型提供在华为昇腾 NPU 上的适配推理、性能测试与精度验证脚本。
原始权重来源:https://gitcode.com/MiniMax-AI/VTP-Base-f16d64
| 属性 | 数值 |
|---|---|
| 架构 | VTP (Visual Tokenizer Pre-training) |
| 参数量 | ~300M |
| 输入尺寸 | [3, 256, 256] |
| Vision Embed Dim | 768 |
| 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-Base-f16d64 --local_dir ./weight/VTP-Base-f16d64在 NPU 上执行单图特征提取推理:
python3 inference.py --device npu --image assets/dog.pngLoading model on NPU...
Model parameters: 295.6M
Loading image from assets/dog.png...
Input tensor shape: torch.Size([1, 3, 256, 256])
CLS token shape: torch.Size([1, 768])
Patch tokens shape: torch.Size([1, 256, 768])
CLS token top-5 values: [2.9994555 2.864135 2.853548 2.649261 2.6276755]
Inference completed successfully!本模型通过
model.to("npu")直接加载到 NPU 运行,无需对第三方库代码进行 monkey-patch。
测试不同 batch size 下的推理延迟与吞吐量:
python3 benchmark.py --device npu| Batch Size | 平均延迟 (ms) | 吞吐量 (samples/s) |
|---|---|---|
| 1 | 14.714 | 67.96 |
| 2 | 14.665 | 136.38 |
| 4 | 14.712 | 271.89 |
| 8 | 14.627 | 546.95 |
| 16 | 22.530 | 710.16 |
对比 NPU 与 CPU 基线的输出一致性:
python3 accuracy.py --batch_size 1| 指标 | 数值 |
|---|---|
| MSE | 0.000001 |
| MAE | 0.000690 |
| 范围归一化相对误差 (%) | 0.020103 |
| 余弦相似度 | 1.000000 |
| 最大绝对差 | 0.002983 |
验证结论:通过 — 范围归一化相对误差 = 0.0201% < 1%,余弦相似度 = 1.000000
| 文件 | 说明 |
|---|---|
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}
}