facebook/dino-vitb16last_hidden_state (197,768) 和 CLS embedding本仓已在 Ascend910B (npu:0) 上完成真实权重加载与推理验证,适用于图像特征提取、下游线性分类等任务的 backbone。
npu:0npu-smi info: OK, HBM 65536 MB, 单次推理后 used ~843 MBtorch.npu.is_available()=True, device_count=2snapshot_download 本地缓存 /opt/atomgit/.cache/huggingface/hub/models--facebook--dino-vitb16/snapshots/f205d5d8e640a89a2b8ef0369670dfc37cc07fc2pip install -r requirements.txt
# requirements.txt 已固定版本:
# torch==2.9.0
# torch_npu==2.9.0.post1
# transformers==4.48.0
# pillow
# numpy默认命令(FP32, npu:0, 自动判断 device):
python inference.py
python inference.py --mode validate # 含 CPU-NPU 一致性
python inference.py --mode benchmark # 10 次正式计时 + 统计224x224 RGB (seed 0 随机噪声, seed 1 半白半黑条纹) 经 ViTImageProcessor 归一化npu:0,可用 torch.npu.synchronize() 同步计时执行 python inference.py (torch.float32, npu:0) 真实 stdout (截取关键行):
Model: facebook/dino-vitb16
Task: vision-encoder (DINO ViT-B/16 feature extraction)
Loading backend: transformers.ViTModel
Device: npu:0 (NPU available: True)
Dtype: torch.float32
Snapshot: /opt/atomgit/.cache/huggingface/hub/models--facebook--dino-vitb16/snapshots/f205d5d8e640a89a2b8ef0369670dfc37cc07fc2
Processor: ViTImageProcessor size=SizeDict(height=224, width=224, ...) image_mean=(0.485, 0.456, 0.406)
Model param device: npu:0 dtype: torch.float32
Input: synthetic 224x224 RGB images (seed 0 and 1), batch=1
Output last_hidden_state shape: (1, 197, 768)
Output CLS embedding shape: (1, 768)
CLS embedding first 5 values: [0.9551856517791748, -3.153085708618164, 0.6187676191329956, -0.009724095463752747, -0.6044752597808838]
CLS embedding norm: 63.9630
Inference latency (single, synced): 6.21 ms
Cosine self-similarity (should be 1.0): 1.000000
Cosine cross-image similarity: 0.178936
CPU-NPU consistency:
max_abs_diff: 0.038536
mean_abs_diff: 0.006384
cosine_similarity: 0.999994
consistency PASS: True (threshold max_abs<0.05, cos>0.99)
Validation: shape_ok=True latency_ok=True self_sim_ok=True distinct_ok=True consistency_ok=True is_npu=True
PASS: DINO ViT-B/16 NPU inference successful, embeddings valid and consistentViTModel get last_hidden_state[:,0,:] (CLS)max_abs_diff: 0.038536mean_abs_diff: 0.006384cosine_similarity: 0.999994max_abs <0.05 && cosine >0.99 => PASSpython inference.py --mode benchmark 在 npu:0, FP32, batch=1, 224x224 下 (含 torch.npu.synchronize(),warmup 3 + 10 iters):
FP16 可将显存减半、延迟略降,本次提交默认 FP32 保证最大兼容。
assets/agent_workflow.png - 下载、侦察、加载、NPU 推理、验证与性能全流程日志assets/npu_device_call.png - npu-smi info、torch.npu.is_available()、device_name 与模型参数 deviceassets/model_result.png - python inference.py 完整真实输出与 PASSpooler.dense.weight/bias,第一次加载提示 MISSING 属正常,推理使用 last_hidden_state 不受影响--dtype fp16Hardware: NPU, NPU, Ascend, Ascend910, Vision, ViT, DINO, Transformer, Feature-Extraction