laion/CLIP-convnext_base_w-laion2B-s13B-b82K-augregconvnext_base_w (ConvNeXt-B visual backbone + 12-layer Transformer text encoder, embed_dim=640)open_clip_pytorch_model.bin 717,620,007 bytes, 配置 open_clip_config.json (image_size 256, vision_cfg timm_convnext_base, text_cfg width 640 / heads 10 / layers 12)/data/.cache/models/laion/CLIP-convnext_base_w-laion2B-s13B-b82K-augreg)logits = logit_scale * image_embeds @ text_embeds.T 并 softmax 排序open_clip (create_model_and_transforms convnext_base_w + local checkpoint)npu:0 (torch.npu.is_available()=True, device_name=Ascend910_9362)pip install -r requirements.txtrequirements.txt:
torch
torch_npu
open_clip_torch
Pillow
numpy
timm
transformers默认命令(必须在 npu:0 上执行):
python inference.py其他模式:
python inference.py --mode validate # CPU-NPU 一致性
python inference.py --mode benchmark # 性能测试 (synchronize 前后计时)固定输入(可复现):
np.random.seed(0) 随机噪声 + 中心 128x128 纯色块 [200,100,50] (PIL Image, 256x256)命令: python inference.py (npu:0, 同步计时)
Model: laion/CLIP-convnext_base_w-laion2B-s13B-b82K-augreg
Task: zero-shot image classification (dual-encoder)
Architecture: convnext_base_w (ConvNeXt-B visual + Transformer text)
Loading backend: open_clip
Requested dtype: torch.float32
Checkpoint: /data/.cache/models/laion/CLIP-convnext_base_w-laion2B-s13B-b82K-augreg/open_clip_pytorch_model.bin (717620007 bytes)
Device requested: npu:0
torch.npu.is_available(): True
torch.npu.get_device_name(0): Ascend910_9362
Model param device: npu:0
--- Inference Results ---
image_embeds: [1, 640] dtype=torch.float32 device=npu:0
text_embeds: [5, 640] dtype=torch.float32 device=npu:0
similarity/logits: [1, 5]
logit_scale: 100.0000
logits: [27.057865142822266, 27.008134841918945, 26.301151275634766, 24.648456573486328, 27.016845703125]
probs (softmax): [0.28815367817878723, 0.27417418360710144, 0.13520336151123047, 0.025895915925502777, 0.27657291293144226]
Ranking (sorted indices): [0, 4, 1, 2, 3]
Rank 1: "a photo of a cat" logit=27.0579 prob=0.2882
Rank 2: "a photo of a bird" logit=27.0168 prob=0.2766
Rank 3: "a photo of a dog" logit=27.0081 prob=0.2742
Rank 4: "a photo of a car" logit=26.3012 prob=0.1352
Rank 5: "a photo of a beach" logit=24.6485 prob=0.0259
Inference latency: 231.31 ms (synchronized, 首次含编译) / 稳定 22.84 ms
Image embed norm: 1.0000
Text embed norms: ['1.0000', '1.0000', '1.0000', '1.0000', '1.0000']
Device check: image tensor npu:0, text tokens npu:0, params npu:0
Status: PASS输出契约验证:
image_embeds [1,640] ✓text_embeds [5,640] ✓logits [1,5] ✓ranking 完整排序及真实分数已展示 ✓logit_scale ✓命令: python inference.py --mode validate
=== CPU-NPU Consistency Validation ===
CPU model device: cpu
NPU model param device: npu:0
NPU image tensor device: npu:0
NPU text tokens device: npu:0
--- Consistency Results (dtype=torch.float32, candidates=5) ---
image_embeds cosine: 0.999987
text_embeds mean cosine: 0.999997
logits max abs error: 0.024223
logits mean abs error: 0.012963
CPU ranking: [0, 1, 4, 2, 3] -> ['a photo of a cat', 'a photo of a dog', 'a photo of a bird', 'a photo of a car', 'a photo of a beach']
NPU ranking: [0, 4, 1, 2, 3] -> ['a photo of a cat', 'a photo of a bird', 'a photo of a dog', 'a photo of a car', 'a photo of a beach']
CPU logits: [27.046491622924805, 26.99458122253418, 26.294153213500977, 24.639789581298828, 26.99262237548828]
NPU logits: [27.057865142822266, 27.008134841918945, 26.301151275634766, 24.648456573486328, 27.016845703125]
CPU probs: [0.28915563225746155, 0.2745283842086792, 0.13626842200756073, 0.026056388393044472, 0.2739911675453186]
NPU probs: [0.28815367817878723, 0.27417418360710144, 0.13520336151123047, 0.025895915925502777, 0.27657291293144226]
Top-1 match: True
Top-K overlap: 100.0%
Thresholds: cosine >= 0.9999, Top-1 must match, overlap >=90%
Consistency: PASS命令: python inference.py --mode benchmark (torch.npu.synchronize 前后计时, 预热 3 次, 正式 10 次)
=== Performance Benchmark ===
Model param device: npu:0
Batch size: 1, Image size: 256, Texts: 5, dtype: torch.float32
Image encode avg latency: 15.68 ms
Text encode avg latency (5 texts): 6.90 ms
Similarity compute included in e2e
End-to-end avg latency: 23.07 ms
E2E stats over 10 runs: avg=22.84 ms min=22.66 ms max=23.03 ms p50=22.83 ms p90=23.03 ms p95=23.03 ms
NPU memory allocated: 688.7 MB
NPU max memory allocated: 713.1 MB
First iteration latency (incl. compile): 70.32 ms
Stable latency (avg): 22.84 ms
Benchmark: PASS三张 PNG 由 xterm.js 根据本次真实日志渲染 (npm --prefix scripts install && node scripts/render_xterm_evidence.mjs --style raw),深灰背景白色等宽字体,提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$:
assets/agent_workflow.png - 阶段日志 (下载、侦察、加载、NPU 推理、验证、性能)assets/npu_device_call.png - npu-smi、torch.npu 可用性、设备名、模型参数 device/dtype、输入输出 Tensor deviceassets/model_result.png - python inference.py 真实完整输出、精度与性能、PASS/FAIL

npu:0 FP32;FP16/BF16 未测试,Large/Huge 模型需自行预判显存#NPU #Ascend #Ascend910 #Hardware: NPU #CLIP #ConvNeXt #zero-shot #vision