yuvalkirstain/PickScore_v1model_type=clip, architectures=["CLIPModel"], projection_dim=1024, vision_hidden=1280 (32层), text_hidden=1024 (24层), patch_size=14, image_size=224, logit_scale_init=2.6592model.safetensors (3944552236 bytes, 3.67 GiB) + pytorch_model.bin (同大小, 二选一), 实际加载 safetensorsfloat32 (原始权重 float32, 单卡 Ascend910B 实测, 大模型容差放松见第6节)transformers CLIPProcessor + CLIPModel 从本地快照加载 (local_files_only=True), 不依赖运行时下载npu-smi 25.5.5, Health OK, Power ~160W, Temp 44-45°Ctorch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, CANN 8.5.1, transformers 4.27+, Pillow, numpy, huggingface_hubnpu-smi info
python -c "import torch; import torch_npu; print(torch.npu.is_available()); print(torch.npu.get_device_name(0))"torch.npu.is_available()=True, device_name=Ascend910_9362, device_count=2, passed=true/opt/atomgit/.cache/huggingface/hub/models--yuvalkirstain--PickScore_v1/snapshots/a4e4367c6dfa7288a00c550414478f865b875800pip install -r requirements.txt
# requirements 包含 torch, torch-npu, transformers, Pillow, numpy, huggingface_hub, accelerate, safetensors
# 已在环境中安装 torch-npu 与 CANN, 无需手动设置代理或 HF_ENDPOINT (已配置 hf-mirror)默认命令 (真实 NPU):
python inference.py
# 或显式指定本地权重目录
python inference.py --model-dir /opt/atomgit/.cache/huggingface/hub/models--yuvalkirstain--PickScore_v1/snapshots/a4e4367c6dfa7288a00c550414478f865b875800其他模式:
python inference.py --mode validate # 完整验证 (含 CPU-NPU 一致性, 放松阈值见第6节)
python inference.py --mode benchmark # 性能测试 (预热3次, 测试10次, torch.npu.synchronize 计时)输入契约 (固定可复现):
a photo of a cute cat sitting on a sofa, highly detaileda photo of a dog running in the parka painting of a mountain landscape, artistica photo of a dress on a mannequin, fashiona blurry low quality photo, distorteda photo of a delicious pizza on a tablenpu:0, dtype float32, batch 1以下为本次在 npu:0 上 python inference.py 的真实输出 (首轮含编译约 297ms):
Model: yuvalkirstain/PickScore_v1
Task: zero-shot image classification / image-text retrieval (dual-encoder CLIP, PickScore)
Device: npu:0 torch=2.9.0+cpu torch_npu=2.9.0.post1 NPU name=Ascend910_9362
Requested dtype: torch.float32 batch_size=1 image_size=224
Input: 1×3×224×224 synthetic cat image + 6 texts
Output contract:
image_embeds: (1, 1024) dtype=torch.float32 device=npu:0
text_embeds: (6, 1024) dtype=torch.float32 device=npu:0
logits_per_image: (1, 6) dtype=torch.float32
Inference latency (single, synchronized): 296.99 ms (first run includes NPU compilation)
Similarity (logits_per_image) raw scores (PickScore CLIP):
[0] a photo of a cute cat sitting on a sofa, highly detailed logit=17.5410 softmax=0.3054
[1] a photo of a dog running in the park logit=15.9560 softmax=0.0626
[2] a painting of a mountain landscape, artistic logit=15.5408 softmax=0.0413
[3] a photo of a dress on a mannequin, fashion logit=15.2817 softmax=0.0319
[4] a blurry low quality photo, distorted logit=17.9524 softmax=0.4608
[5] a photo of a delicious pizza on a table logit=16.4040 softmax=0.0980
Ranking (desc by logit):
Rank 1: [4] a blurry low quality photo, distorted logit=17.9524 prob=0.4608
Rank 2: [0] a photo of a cute cat sitting on a sofa, highly detailed logit=17.5410 prob=0.3054
Rank 3: [5] a photo of a delicious pizza on a table logit=16.4040 prob=0.0980
Rank 4: [1] a photo of a dog running in the park logit=15.9560 prob=0.0626
Rank 5: [2] a painting of a mountain landscape, artistic logit=15.5408 prob=0.0413
Rank 6: [3] a photo of a dress on a mannequin, fashion logit=15.2817 prob=0.0319
Top-1: "a blurry low quality photo, distorted"
Note: PickScore uses CLIP softmax over candidates (not SigLIP sigmoid).说明:
logits_per_image (image_embeds @ text_embeds.T * logit_scale.exp()) 并对候选集合做 softmax 得到分布npu:0 真实执行, 设备与 dtype 已验证 (param device=npu:0)相同权重、相同输入、相同预处理分别在 CPU 与 NPU 上运行, 报告 (float32):
image_embeds cosine: 0.999999
text_embeds cosine mean: 0.999998 min: 0.999998 per-text: ['0.999999', '0.999999', '0.999998', '0.999998', '0.999998', '0.999999']
logits max_abs_err: 0.019040 mean_abs_err: 0.011100
Top-1 CPU: [4] a blurry low quality photo, distorted NPU: [4] a blurry low quality photo, distorted (一致)
Ranking CPU: [4, 0, 5, 1, 2, 3] NPU: [4, 0, 5, 1, 2, 3] Top3 overlap: 3/3阈值与判定:
结论: [PASS] CPU-NPU consistency within tolerance (relaxed for ViT-H)
验证方法为单样本 smoke consistency (固定合成样例), 非完整数据集评测, 已在 inference.py --mode validate 默认流程中自动执行。
计时区间前后均调用 torch.npu.synchronize(), 预热 3 次, 正式测试 10 次, batch 1, 224x224, 6 texts, float32, npu:0:
Full end-to-end (image+text+similarity): avg=27.91ms min=27.28ms max=28.89ms p50=27.80ms p90=28.46ms p95=28.67ms
Throughput: 35.83 inferences/s
Image encoder only: avg=17.46ms min=17.32ms max=17.67ms p50=17.43ms p90=17.66ms p95=17.67ms
Text encoder (6 texts): avg=15.03ms min=14.60ms max=16.11ms p50=14.96ms p90=15.35ms p95=15.73ms
NPU memory used: 4552.4 MB / 62740 MB
First run (cold, with compilation): 296.99 ms
Stable (warm): ~27.28ms (min) to 27.91ms (avg)说明:
复现:
python inference.py --mode benchmarkassets/agent_workflow.png — 阶段日志 (下载、侦察、加载、NPU推理、验证、性能)assets/npu_device_call.png — npu-smi info、torch.npu.is_available()、设备名、模型参数设备与 dtypeassets/model_result.png — python inference.py 完整输出、任务结果、计时与 PASS/FAIL图片由真实日志渲染, 提示符为 atomgit@pod-a94f8701860f4700b161b00e290de466:~$, 不代表实际主机名。受环境限制 (aarch64 容器缺少 Chromium 系统依赖 libnss 等, 无法通过 apt 安装), 本次采用 Pillow 回退渲染, 内容仍为真实日志原文与 SHA-256, 非模拟。
Hardware: NPU, NPU, Ascend, Ascend910, CLIP, PickScore, vision, dual-encoder, aesthetic-scoring, zero-shot #NPU
yuvalkirstain-PickScore_v1-NPU/
├── inference.py
├── readme.md
├── requirements.txt
└── assets/
├── agent_workflow.png
├── npu_device_call.png
└── model_result.png# 环境检查
npu-smi info
python -c "import torch; import torch_npu; print(torch.npu.is_available()); print(torch.npu.get_device_name(0))"
# 默认推理 (NPU)
python inference.py
# 验证 (含 CPU-NPU 一致性)
python inference.py --mode validate
# 性能
python inference.py --mode benchmark