laion/CLIP-convnext_base_w-laion2B-s13B-b82K-augregconvnext_base, w variant with LayerNorm), 文本塔 Transformer (12 layers, 640 width, 10 heads, context 77)open_clip_pytorch_model.bin / open_clip_model.safetensors (717 MB 单文件, 共 1.34 GiB), 预处理 mean [0.4814,0.4578,0.4082] std [0.2686,0.2613,0.2757]open_clip.create_model_and_transforms('convnext_base_w', pretrained=local_bin) 加载到 npu:0,使用 open_clip.get_tokenizer 分词,固定 256x256 合成图 + 6 候选文本验证 embedding 与 similarity,切实走 NPU 编译与推理torch.npu.is_available()=True, device_count=2, device_name Ascend910_9362python inference.py 默认即 NPU float32 单样本推理;已通过 check_npu.py (passed=true)pip install -r requirements.txt
# requirements.txt 包含: torch, torch-npu, open-clip-torch, timm, torchvision, Pillow, safetensors, huggingface-hub# 默认 NPU 推理 (包含 CPU 对比 + benchmark)
python inference.py
# 仅验证一致性
python inference.py --mode validate
# 仅性能测试
python inference.py --mode benchmark
# 指定设备 / 精度
python inference.py --device npu:0 --dtype float32
python inference.py --device cpu --dtype float32open_clip.create_model_and_transforms('convnext_base_w', pretrained="/opt/atomgit/.cache/huggingface/hub/.../open_clip_pytorch_model.bin") -> model.to('npu:0')Compose(Resize 256, CenterCrop 256, ToTensor, Normalize) 来自 open_clipcreate_fixed_image(256)1. a photo of a cat
2. a photo of a dog
3. a photo of a car
4. a photo of a mountain
5. a photo of food
6. a photo of a beachimage_features shape [1,640] image_embeds[0][:5] [0.01503, 0.02018, 0.00094, 0.00963, 0.04081]
text_features shape [6,640] text_embeds[0][:5] [0.01828, 0.00331, 0.01754, -0.02476, 0.02040]
logits_per_image [[30.76327, 28.65554, 29.22905, 28.62244, 27.47962, 27.50110]]
probs [[0.65338385, 0.07939548, 0.14088594, 0.07681035, 0.02449627, 0.02502811]]
ranking:
1. a photo of a cat logit=30.7633 prob=0.6534
2. a photo of a car logit=29.2291 prob=0.1409
3. a photo of a dog logit=28.6555 prob=0.0794
4. a photo of a mountain logit=28.6224 prob=0.0768
5. a photo of a beach logit=27.5011 prob=0.0250
6. a photo of food logit=27.4796 prob=0.0245param device npu:0 dtype torch.float32, image_features device npu:0, logits device npu:0, 单次同步后耗时 224.00 ms (含首次编译), 稳定端到端 19.92 msmodel.logit_scale.exp() 正确计算image_embeds cosine 0.999988
text_embeds cosine per text [0.999999, 0.999999, 0.999996, 0.999997, 0.999997, 0.999996] mean 0.999997
logits max_AE 0.024584 mean_AE 0.012600
Top-1 NPU=a photo of a cat CPU=a photo of a cat match=True
ranking NPU [cat, car, dog, mountain, beach, food]
ranking CPU [cat, car, dog, mountain, beach, food] full_match=True top3_overlap 1.00torch.npu.synchronize(), 预热 3 次, 正式 10 次 (取 avg/min/max/p50/p90/p95), batch=1, image 256x256, texts=6, dtype float32, device npu:0e2e (image+text+similarity+softmax) avg 19.92 ms min 19.89 max 19.96 p50 19.92 p90 19.95 p95 19.95
image_enc (encode_image only) avg 14.92 ms min 14.91 max 14.94 p50 14.92 p90 14.93
text_enc (6 texts, encode_text) avg 6.86 ms min 6.80 max 7.01 p50 6.84
similarity = logit_scale * image@text.T + softmax (包含在 e2e 内)assets/agent_workflow.png - 完整工作流日志 (下载、侦察、加载、NPU 推理、验证、性能)assets/npu_device_call.png - NPU 设备调用证据 (npu-smi, torch_npu 可用性, 设备名, 参数所在设备与 dtype)assets/model_result.png - 模型推理结果 (默认 python inference.py 的真实输出、排序、验证 PASS/FAIL 与性能)--dtype float16 测试但需重测一致性阈值 (>=0.999)Hardware: NPU, NPU, Ascend, Ascend910, Ascend910B, CLIP, OpenCLIP, ConvNeXt, dual-encoder, vision-language, zero-shot