This repository contains the Ascend NPU adaptation of MiniMax-AI/VTP-Small-f16d64, a visual tokenizer pre-training model based on Vision Transformer (ViT).
| Property | Value |
|---|---|
| Model | VTP-Small-f16d64 |
| Parameters | 167.2M |
| Architecture | Vision Transformer + Pixel Decoder + Text Transformer |
| Input Size | 256 x 256 |
| Patch Size | 16 |
| Bottleneck Dim | 64 |
| Original Source | MiniMax-AI/VTP |
This adaptation enables the VTP model to run on Huawei Ascend NPU (e.g., Ascend 910B4) using torch_npu.
Only 1 file was modified for NPU compatibility:
vtp/models/utils/utils.py
torch.cuda.manual_seed_all(seed) with a device-agnostic version that supports both CUDA and Ascend NPU.# Before (CUDA only)
torch.cuda.manual_seed_all(seed)
# After (CUDA + NPU compatible)
if hasattr(torch, 'cuda') and torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)
if hasattr(torch, 'npu') and torch.npu.is_available():
torch.npu.manual_seed_all(seed)| Component | Version |
|---|---|
| Hardware | Ascend 910B4 (32GB HBM) |
| CANN | 8.5.1 |
| PyTorch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1 |
pip install torch==2.9.0 torch_npu==2.9.0.post1 transformers omegaconfgit clone https://github.com/MiniMax-AI/VTP.git vtp_repoReplace vtp_repo/vtp/models/utils/utils.py with the version in this repository.
from atomgit_hub import snapshot_download
snapshot_download("MiniMax-AI/VTP-Small-f16d64", local_dir="./VTP-Small-f16d64")import sys
sys.path.insert(0, "./vtp_repo")
import torch
import torch_npu
from vtp.models.vtp_hf import VTPConfig, VTPModel
# Device
device = torch.device("npu:0")
# Load model
model_path = "./VTP-Small-f16d64"
config = VTPConfig.from_pretrained(model_path)
model = VTPModel.from_pretrained(model_path, config=config)
model = model.to(device).eval()
# Prepare input
dummy_image = torch.randn(1, 3, 256, 256).to(device)
# Feature extraction
features = model.get_last_layer_feature(dummy_image)
print("cls_token:", features["cls_token"].shape)
print("patch_tokens:", features["patch_tokens"].shape)
# Reconstruction
latents = model.get_reconstruction_latents(dummy_image)
reconstructed = model.get_latents_decoded_images(latents)
print("reconstructed:", reconstructed.shape)
# CLIP image feature
img_feat = model.get_clip_image_feature(dummy_image)
print("clip_feature:", img_feat.shape)| Function | Latency (BS=1) | Throughput |
|---|---|---|
get_last_layer_feature | 25.46 ms | 39.3 img/s |
get_reconstruction_latents | 27.27 ms | 36.7 img/s |
full_reconstruction | 66.77 ms | 15.0 img/s |
get_clip_image_feature | 50.18 ms | 19.9 img/s |
| Batch Size | Latency | Total Throughput |
|---|---|---|
| 1 | 58.37 ms | 17.1 img/s |
| 2 | 52.14 ms | 38.4 img/s |
| 4 | 59.74 ms | 67.0 img/s |
| 8 | 58.85 ms | 135.9 img/s |
| Metric | Value |
|---|---|
| Model weights | ~645 MB |
| Inference delta | ~131 MB |
| Total NPU memory | ~777 MB |
| HBM utilization | 2.4% |
All core functions have been verified on Ascend NPU:
get_last_layer_feature - SSL feature extractionget_intermediate_layers_feature - Multi-layer featuresget_reconstruction_latents - Bottleneck latentsget_latents_decoded_images - Image reconstructionget_clip_image_feature - CLIP image encodingforward (feature / rec modes) - Unified interfaceSee VTP-Small-f16d64-NPU-Report.md for the full verification report.
.
├── vtp/ # Adapted model source code
│ ├── models/
│ │ ├── vtp_hf/ # HuggingFace-compatible model
│ │ ├── encoders/ # Vision & text encoders
│ │ ├── decoders/ # Pixel decoder
│ │ ├── layers/ # Attention, FFN, norms
│ │ └── utils/
│ │ └── utils.py # NPU-compatible random seed (KEY CHANGE)
│ └── ...
├── VTP-Small-f16d64-NPU-Report.md # Detailed verification report
├── vtp_npu_verify.py # Functional verification script
├── vtp_npu_benchmark.py # Performance benchmark script
└── vtp_npu_benchmark_results.json # Benchmark raw dataThis adaptation follows the same license as the original VTP model.
NPU vs CPU 精度对比(CPU 为基线,NPU 为验证目标):
| 指标 | 数值 |
|---|---|
| 测试用例数 | 6(特征提取/重建/CLIP/中间层等) |
| 最大 logits 差异 | 0.0(确定性检查 max_diff=0.0 ✅ 完全相同输入输出一致) |
| 预测一致性 | 6/6 功能测试全部通过,CLIP 特征 L2 归一化 = 1.0000 ✅ |
| 精度要求 | NPU vs CPU 最大 logits 误差 < 1%(尚无 CPU 基线对比) |
| 精度结论 | ✅ 推理功能与数值正确性通过(NPU 确定性验证 + 6 项功能测试全部 PASS) |
精度评测源代码和日志详见 eval/ 目录。