liucu/timm-convnext_tiny.in12k_ft_in1k-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

timm/convnext_tiny.in12k_ft_in1k on Ascend NPU

1. 模型简介

  • 模型名称: timm/convnext_tiny.in12k_ft_in1k
  • 模型权重URL: https://huggingface.co/timm/convnext_tiny.in12k_ft_in1k
  • 论文/项目: A ConvNet for the 2020s (ConvNeXt) — ConvNeXt-Tiny, ImageNet-12k 预训练 + ImageNet-1k 微调
  • 架构: ConvNeXt-Tiny
    • Depths: [3, 3, 9, 3], Dims: [96, 192, 384, 768]
    • Stem: Conv2d 4x4 stride 4 + LayerNorm2d, stages with downsample Conv2d 2x2
    • Blocks: depthwise Conv2d 7x7 groups=C + LayerNorm + MLP (expansion 4x) + GELU
    • Head: SelectAdaptivePool2d(avg) + LayerNorm2d + Linear 768→1000
    • 总参数: ~28.59M (model.safetensors 114.37MB + pytorch_model.bin 114.42MB, FP32)
    • Input: 224x224x3 RGB (pretrained_cfg test 288), Normalize mean [0.485,0.456,0.406] std [0.229,0.224,0.225], crop_pct 0.95 bicubic
    • Output: logits (1,1000) → softmax Top-5, ImageNet-1k 1000 classes
  • 适配路线: vision-encoder / unknown → 实际为图像分类 (image-classification), 使用 logits + Top-5 一致性验收
  • 加载后端: timm create_model("convnext_tiny") + safetensors.torch.load_file, 本地权重加载 (snapshot_download 缓存), trust_remote_code=False (无自定义代码)
  • Task: 计算机视觉 — ImageNet 图像分类
  • 权重大小: model.safetensors 114,374,272 bytes + pytorch_model.bin 114,420,885 bytes

2. 验证环境

项值
NPUAscend910_9362 (npu-smi 25.5.5, CANN 8.5.1)
设备npu:0 (PhyID 6, Bus 0000:0B:00.0), 64GB HBM, 2 devices
torch2.9.0+cpu
torch_npu2.9.0.post1+gitee7ba04
torch.npu.is_available()True
timm1.0.22
huggingface_hub0.36.2
safetensors0.6.2
Pillow11.x
Python3.11.14
验证日期2026-08-21 UTC
输入合成 PIL 256x256 灰底+红/绿矩形, timm resolve_data_config + create_transform (Resize 235 bicubic, CenterCrop 224, Normalize), 224x224x3, batch 1
dtypefloat32 (FP32)
batch1

环境检查命令:

npu-smi info
python -c "import torch; import torch_npu; print(torch.npu.is_available()); print(torch.npu.get_device_name(0))"
python .opencode/skills/npu-adapt-skills/scripts/check_npu.py --output env_check.json

3. 安装依赖

pip install -r requirements.txt

系统已配置 HF_ENDPOINT=https://hf-mirror.com 与代理,无需手动设置。

模型下载(首次):

python -c "from huggingface_hub import snapshot_download; print(snapshot_download(repo_id='timm/convnext_tiny.in12k_ft_in1k'))"

4. NPU 推理

默认命令(npu:0 真实推理,3 次 warmup + 10 次计时,含 CPU-NPU 一致性检查):

python inference.py

其他模式:

python inference.py --mode validate
python inference.py --device cpu

inference.py 默认打印: 模型名/任务/后端/device/dtype/输入摘要/真实 logits 与 Top-5(含概率)/分位延迟/吞吐/显存/一致性 diff 与最终 PASS/FAIL。

5. 真实推理结果

Model: timm/convnext_tiny.in12k_ft_in1k
Model weight URL: https://huggingface.co/timm/convnext_tiny.in12k_ft_in1k
Task: ImageNet 图像分类 (ConvNeXt-Tiny, 1000 classes)
Architecture: ConvNeXt-Tiny depths [3,3,9,3] dims [96,192,384,768] ~28.59M params
torch.npu.is_available(): True, device_name: Ascend910_9362, device_count: 2
Loaded .../model.safetensors (114.4 MB)
Model loaded in 1.42s, params: 28.59M
Model moved to npu:0, first param device: npu:0, dtype: torch.float32
Preprocessed pixel_values shape: (1, 3, 224, 224), dtype: torch.float32, range: [-2.118, 2.429]
  Iter 1: logits[:5]=[-0.778, 0.520, -0.731, 0.455, 0.874] Top-5 ids: [549, 530, 409, 892, 921] latency=6.8ms
Latency avg=6.8ms min=6.7ms max=7.0ms throughput 147.06 images/s
CPU logits[:5]: [-0.780, 0.526, -0.728, 0.453, 0.863] NPU logits[:5]: [-0.778, 0.520, -0.731, 0.455, 0.874]
Max abs diff: 0.035826, Top-1 match True, Top-5 set match True
[PASS] CPU-NPU consistency
FINAL: PASS - NPU inference successful

6. CPU-NPU 一致性验证

检查结果
CPU logits[:5][-0.780, 0.526, -0.728, 0.453, 0.863]
NPU logits[:5][-0.778, 0.520, -0.731, 0.455, 0.874]
Max abs diff0.035826
CPU Top-5[549,530,892,409,921]
NPU Top-5[549,530,409,892,921]
Top-1True
Top-5 setTrue
判定PASS

7. 性能测试

指标npu:0cpu
avg6.8 ms180.7 ms
throughput147 images/s5.5 images/s
加速比26.6x—

8. 自验证截图

  • assets/agent_workflow.png
  • assets/npu_device_call.png
  • assets/model_result.png

Agent workflow NPU device call Model result

9. 已知限制

  • 单张合成图 smoke consistency,非全量 ImageNet 评测
  • 存在 ~0.03 max diff,Top-5 顺序翻转属浮点误差
  • FP32,未启用 FP16

10. 标签

Hardware: NPU, NPU, Ascend, Ascend910, vision, image-classification, convnext