weixin_72661020/VTP-Small-f16d64-Ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MiniMax VTP-Small-f16d64 Ascend NPU Adaptation

This repository contains the Ascend NPU adaptation of MiniMax-AI/VTP-Small-f16d64, a visual tokenizer pre-training model based on Vision Transformer (ViT).

Model Overview

PropertyValue
ModelVTP-Small-f16d64
Parameters167.2M
ArchitectureVision Transformer + Pixel Decoder + Text Transformer
Input Size256 x 256
Patch Size16
Bottleneck Dim64
Original SourceMiniMax-AI/VTP

Ascend NPU Compatibility

This adaptation enables the VTP model to run on Huawei Ascend NPU (e.g., Ascend 910B4) using torch_npu.

Code Changes

Only 1 file was modified for NPU compatibility:

  • vtp/models/utils/utils.py
    • Replaced 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)

Verified Environment

ComponentVersion
HardwareAscend 910B4 (32GB HBM)
CANN8.5.1
PyTorch2.9.0+cpu
torch_npu2.9.0.post1

Quick Start

1. Install Dependencies

pip install torch==2.9.0 torch_npu==2.9.0.post1 transformers omegaconf

2. Clone Original Model Code

git clone https://github.com/MiniMax-AI/VTP.git vtp_repo

3. Apply NPU Patch

Replace vtp_repo/vtp/models/utils/utils.py with the version in this repository.

4. Download Model Weights

from atomgit_hub import snapshot_download
snapshot_download("MiniMax-AI/VTP-Small-f16d64", local_dir="./VTP-Small-f16d64")

5. Run Inference on NPU

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)

Performance Benchmark (Ascend 910B4)

FunctionLatency (BS=1)Throughput
get_last_layer_feature25.46 ms39.3 img/s
get_reconstruction_latents27.27 ms36.7 img/s
full_reconstruction66.77 ms15.0 img/s
get_clip_image_feature50.18 ms19.9 img/s

Batch Size Scaling

Batch SizeLatencyTotal Throughput
158.37 ms17.1 img/s
252.14 ms38.4 img/s
459.74 ms67.0 img/s
858.85 ms135.9 img/s

Memory Usage

MetricValue
Model weights~645 MB
Inference delta~131 MB
Total NPU memory~777 MB
HBM utilization2.4%

Verification

All core functions have been verified on Ascend NPU:

  • get_last_layer_feature - SSL feature extraction
  • get_intermediate_layers_feature - Multi-layer features
  • get_reconstruction_latents - Bottleneck latents
  • get_latents_decoded_images - Image reconstruction
  • get_clip_image_feature - CLIP image encoding
  • forward (feature / rec modes) - Unified interface

See VTP-Small-f16d64-NPU-Report.md for the full verification report.

Repository Structure

.
├── 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 data

References

  • VTP GitHub Repository
  • VTP Paper (arXiv:2512.13687)
  • Original Model on HuggingFace
  • Ascend PyTorch Documentation

License

This adaptation follows the same license as the original VTP model.

Ascend NPU 精度评测

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/ 目录。