AtomGit 侧模型名 multi-modal_clip-vit-huge-patch14_zh,其真实权重标识为 ModelScope
AI-ModelScope/chinese-clip-vit-huge-patch14(revision Revision:master,CreatedAt:1728551124)。
Chinese-CLIP 中英双语图文双塔(ViT-H/14),参数量 957.6M,fp32 权重目录 7.14 GB。
实测结构(读自本地 config.json):vision clip_vision_model(layers=32, hidden=1280,
patch=14, image=224)、text chinese_clip_text_model(layers=24, hidden=1024)、
projection_dim=1024;模型目录内自定义 Python 文件数 = 0,无需 trust_remote_code。
任务类型为零样本图文匹配(双塔):输出 image/text embedding、相似度与候选文本排序, 不使用图像分类 Top-5 口径。
| 项 | 值 |
|---|---|
| 环境 | 昇腾算力容器(pod-ecc17223f3234edbbc5ccd936d8cc2f3),非 root |
| NPU | Ascend910_9362,单卡 npu:0(ASCEND_RT_VISIBLE_DEVICES=0),HBM 64 GB |
| npu-smi | 25.5.5;空载时约 3.1/2.9 GB HBM 为他方容器占用,已记入基线,不计入本模型开销 |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| torch / torch_npu | 2.9.0+cpu / 2.9.0.post1+gitee7ba04 |
| transformers | 4.57.6 |
| 权重加载 | 本地目录加载(CLIP_MODEL_DIR 指向已下载权重,正式推理不依赖运行时下载) |
pip install -r requirements.txt
# 权重(约 7.1 GB,含 .pt 与 .bin 两份)
python -c "from modelscope import snapshot_download; print(snapshot_download('AI-ModelScope/chinese-clip-vit-huge-patch14'))"export CLIP_MODEL_DIR=<本地权重目录>
# 例:/opt/atomgit/clip/models/models/AI-ModelScope/chinese-clip-vit-huge-patch14
export CLIP_TEST_IMAGE=/opt/atomgit/test_data/test1.jpg # 可选,默认即此图
python inference.py # 验证模式(默认):真实 npu:0 推理 + 一致性判定
python inference.py --mode benchmark # 性能模式:预热 3 + 正式 10inference.py 默认执行即完成一次真实 NPU 推理,并打印模型、任务、后端、device、dtype、
输入摘要、完整候选排序、同步后的耗时与最终 RESULT;异常时返回非零退出码。
运行条件:dtype=torch.bfloat16,device=npu:0,param dev={'npu'},batch=1。
输入:/opt/atomgit/test_data/test1.jpg(JPEG 512×512,91814 B,sha256=7de7ed51a1594fff)。
候选文本(5 条)与实测相似度(cos = logits_per_image / 100):
| 排名 | 候选文本 | cos |
|---|---|---|
| 1 | 一位戴着帽子的女士的肖像 | 0.2837 |
| 2 | 一张年轻女性的照片 | 0.2262 |
| 3 | 一只猫的照片 | 0.1400 |
| 4 | 一盘食物的照片 | 0.1256 |
| 5 | 一片自然风景照片 | 0.1144 |
Top-1 = 一位戴着帽子的女士的肖像(与图像实际内容一致)。首次前向 247.6 ms(含图编译),
峰值 HBM 1.80 GB,RESULT: PASS。
口径说明:单样本 smoke consistency(1 张图 × 5 条候选文本),不是完整数据集精度评测。
CPU 侧 fp32 锚点由同一权重、同一输入、同一 processor 生成并落盘为 logs/cpu_baseline.npz。
| 对比 | image_embeds cosine | text_embeds cosine | 候选排序 | 判定 |
|---|---|---|---|---|
| NPU fp32 vs CPU fp32(阈值 ≥0.9999) | 0.99999988 | 0.99999917 | 5/5 完全一致 | PASS |
| NPU bf16 vs CPU fp32(阈值 ≥0.999) | 0.999859 | 0.999972 | 5/5 完全一致 | PASS |
排除静默回退 CPU 的证据:参数所在设备 {'npu'},NPU 已分配显存 fp32 3.63 GB / bf16 1.80 GB。
其他实测发现(供复现者参考):
model.get_text_features() / model.get_image_features() 返回 None
(pooled_output 为 None,触发 linear(): argument 'input' must be Tensor, not NoneType),
本工程统一使用整体 forward:model(**image_inputs, **text_inputs)。argmax(最高 token id)落在最后一个汉字(位置 3),而 [SEP] 在位置 4;
与整体 forward 的结果无冲突(两种 dtype 下排序均与 CPU 完全一致)。preprocessor_config.json:resize 至 224×224(do_center_crop=false,
resample=3 BICUBIC),使用 CLIP 标准 mean/std。条件:dtype=bf16、batch=1、输入图 512×512、候选文本 5 条、预热 3 次、正式 10 次;
每个计时区间前后均调用 torch.npu.synchronize()。单位 ms。
| 阶段 | avg | min | max | p50 | p90 | p95 |
|---|---|---|---|---|---|---|
| 图像塔 forward | 19.2 | 19.0 | 19.4 | 19.2 | 19.4 | 19.4 |
| 文本塔 forward(5 条) | 15.7 | 15.4 | 16.3 | 15.6 | 16.2 | 16.3 |
| 相似度计算(1×5) | 1.3 | 0.9 | 4.8 | 0.9 | 1.3 | 3.1 |
| 端到端 forward | 34.7 | 34.6 | 34.9 | 34.8 | 34.8 | 34.9 |



三张图由本次真实日志渲染(每图对应一次真实命令,源日志与 SHA-256 见证据 manifest)。
get_image_features / get_text_features 在当前 transformers 版本不可用,必须走整体 forwardHardware: NPU / NPU / Ascend / Ascend910