OpenAI CLIP ViT-B/16 image encoder adapted for Ascend NPU (910B4).
| Component | Version |
|---|---|
| torch | 2.9.0 |
| torch-npu | 2.9.0.post1 |
| timm | 1.0.27 |
| transformers | 4.57.6 |
| NPU | Ascend910B4 |
| File | Description |
|---|---|
inference.py | Inference wrapper (CPU/NPU) |
vit_clip_npu_adapt.py | Precision validation + performance benchmark |
eval_vit_clip.py | Structured evaluation script |
config.json | Model configuration |
eval_output/ | Verification reports |
from inference import ViTCIPInference
import torch
# NPU inference
model = ViTCIPInference(device="npu:0", dtype=torch.float32)
embedding = model.embed(image) # returns numpy array [1, 512]Precision (CPU FP32 vs NPU):
| Metric | FP32 | FP16 |
|---|---|---|
| Cosine Similarity | 0.999987 | 0.999988 |
| Mean Abs Diff | 0.001790 | 0.001732 |
| Max Abs Diff | 0.027754 | 0.025086 |
| PASSED | ✅ | ✅ |
Performance (Ascend910B4):
| Batch Size | FP32 (ms) | FP16 (ms) |
|---|---|---|
| 1 | 17.20 | 21.03 |
| 4 | 14.72 | 19.95 |
| 8 | 18.58 | 14.71 |
Model weights from GitCode: https://gitcode.com/hf_mirrors/timm/vit_base_patch16_clip_224.openai
open_clip_model.safetensors) from ModelScope/GitCodevisual.* keys from OpenCLIP format to timm VisionTransformer formatvisual.proj → head.weight (transposed), head.bias = zerosnpu:0 deviceNo operator-level modification needed — model runs out of the box on Ascend NPU via torch_npu.