patrickjohncyh/fashion-clipmodel_type=clip, architectures=["CLIPModel"], projection_dim=512, vision_hidden=768 (12层), text_hidden=512 (12层), patch_size=32, image_size=224model.safetensors (605 MB) + pytorch_model.bin (605 MB), 1.13 GiB 合计, 实际加载 safetensorsfloat32 (原始权重 float32, 单卡 Ascend910B 实测)transformers CLIPProcessor + CLIPModel 从本地快照加载 (local_files_only=True), 不依赖运行时下载npu-smi 25.5.5, Health OK, Power ~160W, Temp 44°Ctorch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, CANN 8.5.1, transformers 4.44.0, Pillow, numpynpu-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--patrickjohncyh--fashion-clip/snapshots/7e3ba62ce16b379a1ab479346b66f192e76f51b7pip install -r requirements.txt
# requirements 包含 torch, torch-npu, transformers, Pillow, numpy, huggingface_hub
# 已在环境中安装 torch-npu 与 CANN, 无需手动设置代理或 HF_ENDPOINT (已配置 hf-mirror)默认命令 (真实 NPU):
python inference.py
# 或显式指定本地权重目录
python inference.py --model-dir /opt/atomgit/.cache/huggingface/hub/models--patrickjohncyh--fashion-clip/snapshots/7e3ba62ce16b379a1ab479346b66f192e76f51b7其他模式:
python inference.py --mode validate # 完整验证 (含 CPU-NPU 一致性)
python inference.py --mode benchmark # 性能测试 (预热3次, 测试10次, torch.npu.synchronize 计时)输入契约 (固定可复现):
a photo of a dressa photo of a t-shirta photo of jeansa photo of a sneakera photo of a handbaga photo of a jacketnpu:0, dtype float32, batch 1以下为本次在 npu:0 上 python inference.py 的真实输出 (首轮含编译):
Model: patrickjohncyh/fashion-clip
Task: zero-shot image classification / image-text retrieval (dual-encoder CLIP)
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 dress image + 6 texts
Output contract:
image_embeds: (1, 512) dtype="torch.float32" device="npu:0"
text_embeds: (6, 512) dtype="torch.float32" device="npu:0"
logits_per_image: (1, 6) dtype="torch.float32"
Inference latency (single, synchronized): 275.91 ms (first run includes NPU compilation)
Similarity (logits_per_image) raw scores (CLIP):
[0] a photo of a dress logit="24.9999" softmax="0.2563"
[1] a photo of a t-shirt logit="22.0199" softmax="0.0130"
[2] a photo of jeans logit="22.5441" softmax="0.0220"
[3] a photo of a sneaker logit="24.4217" softmax="0.1437"
[4] a photo of a handbag logit="25.7809" softmax="0.5596"
[5] a photo of a jacket logit="21.1410" softmax="0.0054"
Ranking (desc by logit):
Rank 1: [4] a photo of a handbag logit="25.7809" prob="0.5596"
Rank 2: [0] a photo of a dress logit="24.9999" prob="0.2563"
Rank 3: [3] a photo of a sneaker logit="24.4217" prob="0.1437"
Rank 4: [2] a photo of jeans logit="22.5441" prob="0.0220"
Rank 5: [1] a photo of a t-shirt logit="22.0199" prob="0.0130"
Rank 6: [5] a photo of a jacket logit="21.1410" prob="0.0054"
Top-1: "a photo of a handbag"
Note: Fashion-CLIP 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 上运行, 报告:
image_embeds cosine: 1.000000
text_embeds cosine mean: 1.000000 min: 1.000000 per-text: ['1.000000', '1.000000', '1.000000', '1.000000', '1.000000', '1.000000']
logits max_abs_err: 0.003529 mean_abs_err: 0.002101
Top-1 CPU: [4] a photo of a handbag NPU: [4] a photo of a handbag (一致)
Ranking CPU: [4, 0, 3, 2, 1, 5] NPU: [4, 0, 3, 2, 1, 5] Top3 overlap: 3/3阈值与判定 (float32):
结论: [PASS] CPU-NPU consistency within tolerance
验证方法为单样本 smoke consistency (固定合成样例), 非完整数据集评测, 已在 inference.py 默认流程中自动执行。
计时区间前后均调用 torch.npu.synchronize(), 预热 3 次, 正式测试 10 次, batch 1, 224x224, 6 texts, float32, npu:0:
Full end-to-end (image+text+similarity): avg=13.90ms min=13.44ms max=14.38ms p50=13.89ms p90=14.36ms p95=14.37ms
Throughput: 71.93 inferences/s
Image encoder only: avg=6.18ms min=6.12ms max=6.49ms
Text encoder (6 texts): avg=7.21ms min=7.11ms max=7.29ms
NPU memory used: 1204.6 MB / 62740 MB
First run (cold, with compilation): 275.91 ms
Stable (warm): ~13.44ms (min) to 13.90ms (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图片由 scripts/render_xterm_evidence.mjs 从本次真实日志渲染 (--style raw), 提示符为 atomgit@pod-a94f8701860f4700b161b00e290de466:~$, 不代表实际主机名。
Hardware: NPU, NPU, Ascend, Ascend910, CLIP, vision, fashion, dual-encoder, zero-shot
patrickjohncyh-fashion-clip-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