本仓库作为昇腾 NPU 模型仓库发布。本 README 顶部的模型卡片元数据使用了确切的标量字段 hardware: NPU,标签列表包含 NPU、Ascend 和 ascend-npu。仓库描述或模型卡片在 AtomGit 或 GitCode 上还应包含 #+NPU 标签。
| 项目 | 数值 |
|---|---|
| 仓库 | https://gitcode.com/nanyizjm/vit-base-patch16-224-in21k |
| 竞赛任务 | Track 1 模型适配 |
| 硬件元数据 | hardware: NPU |
| 所需标签 | #+NPU |
| README 数据策略 | 推理、精度和性能数值以文本形式写入本 README;不使用图像替代数据。 |
| 项目 | 数值 |
|---|---|
| 模型仓库 | https://gitcode.com/nanyizjm/vit-base-patch16-224-in21k |
| 原始模型或权重来源 | https://gitcode.com/hf_mirrors/google/vit-base-patch16-224-in21k |
| 竞赛赛道 | Track 1:模型适配 |
| 目标硬件 | 昇腾 NPU |
| 必备功能 | NPU 推理成功运行或明确记录阻塞原因 |
| 必备精度 | NPU 结果与 CPU/GPU 参考值对比,误差小于 1% |
| 所需标签 | #+NPU |
| 交付物 | 状态 |
|---|---|
| inference.py | 已提供 |
| readme.md / README.md | 已提供 |
| eval/eval_accuracy.py | 已提供 |
| eval/eval_performance.py | 已提供 |
| logs 目录 | 已提供 |
| results 目录 | 已提供 |
| 资产或截图证明 | 已提供 |
README 必须包含明确的 CPU/GPU 与 NPU 数值对比数据。关键验收目标是误差小于 1%。相应的结构化证明在可用时应保存至 results/accuracy_eval.json 和 logs/accuracy_eval.log。
#+NPU
本部分直接写入 README 供平台审核使用。仅使用本仓库中已签入的日志和 JSON 结果文件,不依赖嵌入式图片。
| 审核项 | 直接结果 |
|---|---|
| 仓库 | vit-base-patch16-224-in21k |
| 硬件元数据 | 本 README 中存在 hardware: NPU 和 #+NPU |
| 正常 NPU 推理输出 | 通过 - 已签入的 NPU 推理输出如下所示。 |
| 精度要求 | 通过 - 已签入的精度证据报告显示通过;请使用下表查看精确记录值。 |
| 性能证据 | 可用 - 已签入的性能指标如下所示。 |
| 证据文件 | results/inference_result.json、logs/inference.log、results/accuracy_eval.json、results/performance_eval.json、logs/accuracy_eval.log、logs/performance_eval.log |
"device": "npu:0",
"input_shape": [
"pooler_output_shape": [
"throughput": 166.9441171787932,
Device: npu:0 | Dtype: float32 | NPU: True (2)
pooler_output: torch.Size([1, 768])
Throughput: 166.94 images/s| 来源 | 指标 | 数值 |
|---|---|---|
results/inference_result.json | device | npu:0 |
results/inference_result.json | input_shape | [1,3,224,224] |
results/inference_result.json | pooler_output_shape | [1,768] |
results/inference_result.json | throughput | 166.9441171787932 |
| 来源 | 指标 | 数值 |
|---|---|---|
results/accuracy_eval.json | cls_cosine_mean | 0.9999793579504667 |
results/accuracy_eval.json | hidden_cosine_mean | 0.9999348992625414 |
results/accuracy_eval.json | passed | true |
results/accuracy_eval.json | per_sample[0].cls_cosine | 0.9999824666965669 |
results/accuracy_eval.json | per_sample[0].hidden_cosine | 0.9999834719135302 |
results/accuracy_eval.json | per_sample[1].cls_cosine | 0.9999812497923902 |
results/accuracy_eval.json | per_sample[1].hidden_cosine | 0.9999345349108698 |
results/accuracy_eval.json | per_sample[2].cls_cosine | 0.9999641782560029 |
results/accuracy_eval.json | per_sample[2].hidden_cosine | 0.9998010291212842 |
results/accuracy_eval.json | per_sample[3].cls_cosine | 0.9999829797421976 |
精度结论:PASS - 已提交的精度验证报告显示通过;具体记录数值请参见下表。
| 来源 | 指标 | 数值 |
|---|---|---|
results/performance_eval.json | device | npu |
results/performance_eval.json | dtype | float32 |
results/performance_eval.json | batch_size | 1 |
results/performance_eval.json | warmup | 3 |
results/performance_eval.json | num_runs | 10 |
results/performance_eval.json | throughput | 176.34833208600668 |
results/performance_eval.json | peak_memory_mb | 330.22119140625 |
results/performance_eval.json | all_runs_ms | [5.690813064575195,5.635738372802734,5.659341812133789,5.638360977172852,5.722999572753906,5.654096603393555,5.666255950927734,5.713462829589844,5.6672096252441 |
本文档记录 ViT-Base-Patch16-224-IN21K 在华为昇腾 NPU 环境下的适配验证、推理部署与评测结果整理。
ViT-Base-Patch16-224-IN21K 的当前适配任务类型为:图像识别 / 视觉特征提取。仓库围绕 赛道一模型适配 交付要求,提供 NPU 推理脚本、精度评测、性能评测、运行日志、结果文件和文本化自验证证据。
相关获取地址:
仓库提供 inference.py 作为统一推理入口,运行时通过 --device npu 或脚本默认设备在昇腾 NPU 上执行推理。推理代码保留 model.eval()、无梯度推理、输入输出摘要、耗时统计和日志保存逻辑,便于复现与核验。
仓库保留精度评测与性能评测材料。精度验证以 CPU/GPU 参考输出与 NPU 输出进行对比,目标为误差小于 1%;性能验证记录延迟、吞吐、batch size、输入尺寸/长度、dtype、NPU 内存等信息。所有结果以 logs/ 与 results/ 中的真实运行文件为准。
自验证截图中的关键内容已转写为 README 文本证据,避免仅依赖图片展示。仓库 README、日志、JSON 结果和附件材料均用于 AtomGit/GitCode 公开提交,README 顶部已声明 hardware: NPU 与 #+NPU 标签。
| 组件 | 版本 / 说明 |
|---|---|
| 操作系统 | Linux-5.10.0-182.0.0.95.r2220_156.hce2.aarch64-aarch64-with-glibc2.35 |
| Python | 3.11.14 |
| NPU 数量 | 2 |
| PyTorch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| transformers | 4.57.6 |
| 依赖安装 | pip install -r requirements.txt |
results/env_info.json 或 logs/env_check.log 为准)torch_npu,请先完成昇腾基础环境配置后再运行真实验证。.
├── .gitignore
├── README.md
├── assets/README.md
├── assets/accuracy_eval_result.png
├── assets/env_check.png
├── assets/git_submit_result.png
├── assets/inference_result.png
├── assets/performance_eval_result.png
├── eval/eval_accuracy.py
├── eval/eval_performance.py
├── inference.py
├── logs/accuracy_eval.log
├── logs/env_check.log
├── logs/inference.log
├── logs/model_check.log
├── logs/performance_eval.log
├── requirements.txt
├── results/accuracy_eval.json
├── results/env_info.json
├── results/inference_result.json
└── results/performance_eval.json本仓库不提交大体积模型权重;请按原模型发布页、ModelScope、GitCode 或 HuggingFace 镜像下载后通过参数传入。
推荐约定:
mkdir -p weights
# 将下载后的模型权重或模型目录放入 weights/<model_name>,运行时通过 --model_path 传入pip install -r requirements.txt
python inference.py --model_path <model_path> --image_path <image.jpg> --device npupython eval/eval_accuracy.py --model_path <model_path> --device npu
python eval/eval_performance.py --model_path <model_path> --device npu| 指标 | 结果 |
|---|---|
| 模型名称 | vit-base-patch16-224-in21k |
| 任务类型 | 图像识别 / 视觉特征提取 |
| 推理设备 | Ascend NPU |
| 推理框架 | PyTorch / torch_npu 或仓库脚本声明的推理框架 |
| 仓库分支 | main |
| 当前提交 | 037e1be |
测试结果来源:results/performance_eval.json
| 指标 | 结果 |
|---|---|
device | npu |
dtype | float32 |
batch_size | 1 |
num_runs | 10 |
warmup | 3 |
avg_ms | 5.6706 |
throughput | 176.35 |
结果来源:results/accuracy_eval.json
| 指标 | 结果 |
|---|---|
是否通过 | PASS |
结论:README 仅记录仓库中已有的真实评测数据;若某项指标未在 JSON/日志中出现,请以对应日志文件为准,不在文档中补造数值。
python eval/eval_accuracy.py --model_path <model_path> --device npu
python eval/eval_performance.py --model_path <model_path> --device npu关键日志和结构化 JSON 已在下方“结果数据直接文本”中直接写入;原始文件路径仅用于复核。
inference.py 支持的参数以脚本自身 --help 输出为准。当前 README 从脚本中提取到的主要参数如下:
| 参数 | 默认值 | 说明 |
|---|---|---|
--model_path | 见脚本默认值 | 模型权重或模型目录路径 |
--image_path | 见脚本默认值 | 输入样例路径 |
--device | 见脚本默认值 | 推理设备,NPU 推理使用 npu |
--dtype | 见脚本默认值 | 推理精度类型 |
--trust_remote_code | 见脚本默认值 | 脚本参数,详见 python inference.py --help |
--output_log | 见脚本默认值 | 输出目录或日志路径 |
python inference.py --help
python inference.py --model_path <model_path> --image_path <image.jpg> --device npu以下内容来自仓库已有 README 证据段、运行日志或结果文件。图片文件如保留在 assets/ 中,仅作为附件材料;README 中直接写入可检索的文本证据。
以下 PNG 文件由之前的 assets/*.txt 证据文件渲染生成。渲染完成后,原始 TXT 文件已被移除。
| 证据 | PNG 文件 |
|---|---|
| 精度评估结果 | assets/accuracy_eval_result.png |
| 环境检查 | assets/env_check.png |
| Git 提交结果 | assets/git_submit_result.png |
| 推理结果 | assets/inference_result.png |
| 性能评估结果 | assets/performance_eval_result.png |
本节将仓库中已提交的评测 JSON、推理日志、环境日志和性能日志直接写入 README。原始文件路径仅用于标识数据来源,主要数值和输出内容已在下面以文本形式完整展开。
[LOG_WARNING] can not create directory, directory: /home/atomgit/ascend/log, possible reason: No such file or directory.path string is NULLpath string is NULL{
"os": "Linux-5.10.0-182.0.0.95.r2220_156.hce2.aarch64-aarch64-with-glibc2.35",
"python_version": "3.11.14",
"arch": "aarch64",
"torch_version": "2.9.0+cpu",
"torch_npu_version": "2.9.0.post1+gitee7ba04",
"transformers_version": "4.57.6",
"npu_available": true,
"npu_count": 2,
"npu_device_name": "Ascend910_9362",
"ascend_toolkit_home": "/usr/local/Ascend/cann-8.5.1",
"soc_version": "ascend910_9391",
"npu_smi": "+------------------------------------------------------------------------------------------------+\n| npu-smi 25.5.2 Version: 25.5.2 |\n+---------------------------+---------------+----------------------------------------------------+\n| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|\n| Chip Phy-ID | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |\n+===========================+===============+====================================================+\n| 5 Ascend910 | OK | 172.7 46 0 / 0 |\n| 0 10 | 0000:0B:00.0 | 0 0 / 0 3106 / 65536 |\n+------------------------------------------------------------------------------------------------+\n| 5 Ascend910 | OK | - 47 0 / 0 |\n| 1 11 | 0000:0A:00.0 | 0 0 / 0 2870 / 65536 |\n+===========================+===============+====================================================+\n+---------------------------+---------------+----------------------------------------------------+\n| NPU Chip | Process id | Process name | Process memory(MB) |\n+===========================+===============+====================================================+\n| No running processes found in NPU 5 |\n+===========================+===============+====================================================+\n"
}{
"os": "Linux-5.10.0-182.0.0.95.r2220_156.hce2.aarch64-aarch64-with-glibc2.35",
"python_version": "3.11.14",
"arch": "aarch64",
"torch_version": "2.9.0+cpu",
"torch_npu_version": "2.9.0.post1+gitee7ba04",
"transformers_version": "4.57.6",
"npu_available": true,
"npu_count": 2,
"npu_device_name": "Ascend910_9362",
"ascend_toolkit_home": "/usr/local/Ascend/cann-8.5.1",
"soc_version": "ascend910_9391",
"npu_smi": "+------------------------------------------------------------------------------------------------+\n| npu-smi 25.5.2 Version: 25.5.2 |\n+---------------------------+---------------+----------------------------------------------------+\n| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|\n| Chip Phy-ID | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |\n+===========================+===============+====================================================+\n| 5 Ascend910 | OK | 172.7 46 0 / 0 |\n| 0 10 | 0000:0B:00.0 | 0 0 / 0 3106 / 65536 |\n+------------------------------------------------------------------------------------------------+\n| 5 Ascend910 | OK | - 47 0 / 0 |\n| 1 11 | 0000:0A:00.0 | 0 0 / 0 2870 / 65536 |\n+===========================+===============+====================================================+\n+---------------------------+---------------+----------------------------------------------------+\n| NPU Chip | Process id | Process name | Process memory(MB) |\n+===========================+===============+====================================================+\n| No running processes found in NPU 5 |\n+===========================+===============+====================================================+\n"
}Model Check Log
================
Model: google/vit-base-patch16-224-in21k
Source: ModelScope
Path: /tmp/ms_cache/google/vit-base-patch16-224-in21k
Files:
- config.json: OK (ViTModel, hidden_size=768, 12 layers, 12 heads)
- model.safetensors: OK (~330MB)
- preprocessor_config.json: OK (224x224, mean=[0.5,0.5,0.5], std=[0.5,0.5,0.5])
Architecture: ViTModel
- hidden_size: 768
- num_attention_heads: 12
- num_hidden_layers: 12
- patch_size: 16
- image_size: 224
CPU inference: PASS - last_hidden_state [1,197,768], pooler_output [1,768]
NPU inference: PASS - same output shapes============================================================
ViT-Base-Patch16-224-In21k Inference - Ascend NPU
============================================================
Device: npu:0 | Dtype: float32 | NPU: True (2)
Model: /tmp/ms_cache/google/vit-base-patch16-224-in21k
Loading model...
Loaded in 1.32s
Image: random test (seed=42)
Input: torch.Size([1, 3, 224, 224])
============================================================
Results
============================================================
last_hidden_state: torch.Size([1, 197, 768])
pooler_output: torch.Size([1, 768])
CLS Embedding (first 10): [0.3490956127643585, -0.376524955034256, -0.4646841287612915, 0.2205367088317871, 0.2288619577884674, 0.6864526867866516, 0.22021925449371338, 0.540951669216156, -0.6418433785438538, 0.23362571001052856]
mean=0.011744 std=0.416306
min=-0.829715 max=0.857226
norm=11.541611
Patch Tokens: (196, 768)
mean=-0.017998 std=0.199733
Performance
Inference: 5.99 ms
Throughput: 166.94 images/s
Device: Ascend910_9362 (61.3 GB)
PyTorch 2.9.0+cpu
torch_npu 2.9.0.post1+gitee7ba04{
"model": "google/vit-base-patch16-224-in21k",
"device": "npu:0",
"dtype": "float32",
"input_shape": [
1,
3,
224,
224
],
"last_hidden_state_shape": [
1,
197,
768
],
"pooler_output_shape": [
1,
768
],
"cls_first10": [
0.3490956127643585,
-0.376524955034256,
-0.4646841287612915,
0.2205367088317871,
0.2288619577884674,
0.6864526867866516,
0.22021925449371338,
0.540951669216156,
-0.6418433785438538,
0.23362571001052856
],
"cls_mean": 0.011743989773094654,
"cls_std": 0.41630637645721436,
"inference_ms": 5.990028381347656,
"throughput": 166.9441171787932,
"npu_available": true
}============================================================
ViT-Base-Patch16-224-In21k Accuracy: CPU vs NPU
============================================================
Loading CPU model...
Loading NPU model...
Testing 5 images
Sample 1: CLS cos=0.999982 p99=0.3972% mae=0.1080% | Hid cos=0.999983 p99=0.1220% mae=0.0362%
Sample 2: CLS cos=0.999981 p99=0.4121% mae=0.1127% | Hid cos=0.999935 p99=0.1462% mae=0.0431%
Sample 3: CLS cos=0.999964 p99=0.5716% mae=0.1615% | Hid cos=0.999801 p99=0.2670% mae=0.0775%
Sample 4: CLS cos=0.999983 p99=0.3972% mae=0.1083% | Hid cos=0.999983 p99=0.1212% mae=0.0355%
Sample 5: CLS cos=0.999986 p99=0.3639% mae=0.0966% | Hid cos=0.999973 p99=0.1267% mae=0.0374%
============================================================
Summary
============================================================
CLS: Cosine=0.999979 P99Err=0.5716% MAE=0.1174% MaxErr=1.3420%
Hid: Cosine=0.999935 P99Err=0.2670% MAE=0.0459% MaxErr=9.9172%
Cos>0.9999: PASS
P99Err<1%: PASS
MAE<1%: PASS
Overall: PASS{
"model": "google/vit-base-patch16-224-in21k",
"device": "npu:0",
"dtype": "float32",
"num_samples": 5,
"cls_cosine_mean": 0.9999793579504667,
"hidden_cosine_mean": 0.9999348992625414,
"cls_p99_err_pct": 0.5715685947916698,
"hidden_p99_err_pct": 0.26697294251635384,
"cls_mae_pct": 0.11741497903130949,
"hidden_mae_pct": 0.04593578167259693,
"cls_max_err_pct": 1.342011895030737,
"hidden_max_err_pct": 9.917229413986206,
"passed": true,
"per_sample": [
{
"sample": 1,
"cls_cosine": 0.9999824666965669,
"hidden_cosine": 0.9999834719135302,
"cls": {
"max_pct": 1.342011895030737,
"p99_pct": 0.39721892043898777,
"mae_pct": 0.10797061258926988,
"mae_abs": 0.00182095926720649
},
"hidden": {
"max_pct": 0.24946846533566713,
"p99_pct": 0.12200637722494664,
"mae_pct": 0.03615466121118516,
"mae_abs": 0.0009077113936655223
}
},
{
"sample": 2,
"cls_cosine": 0.9999812497923902,
"hidden_cosine": 0.9999345349108698,
"cls": {
"max_pct": 0.7182231172919273,
"p99_pct": 0.41208565966639743,
"mae_pct": 0.1127194962464273,
"mae_abs": 0.001983115216717124
},
"hidden": {
"max_pct": 4.646378383040428,
"p99_pct": 0.14615263752093352,
"mae_pct": 0.04310031654313207,
"mae_abs": 0.0010910072596743703
}
},
{
"sample": 3,
"cls_cosine": 0.9999641782560029,
"hidden_cosine": 0.9998010291212842,
"cls": {
"max_pct": 0.9910869412124157,
"p99_pct": 0.5715685947916698,
"mae_pct": 0.16151850577443838,
"mae_abs": 0.002759933238849044
},
"hidden": {
"max_pct": 9.917229413986206,
"p99_pct": 0.26697294251635384,
"mae_pct": 0.07752051460556686,
"mae_abs": 0.002001263899728656
}
},
{
"sample": 4,
"cls_cosine": 0.9999829797421976,
"hidden_cosine": 0.9999827516874749,
"cls": {
"max_pct": 0.7778280880302191,
"p99_pct": 0.3972197900481425,
"mae_pct": 0.1082691247574985,
"mae_abs": 0.001853788155131042
},
"hidden": {
"max_pct": 0.2562459325417876,
"p99_pct": 0.12116758090958493,
"mae_pct": 0.03547864034771919,
"mae_abs": 0.0009030310320667922
}
},
{
"sample": 5,
"cls_cosine": 0.9999859152651751,
"hidden_cosine": 0.999972708679548,
"cls": {
"max_pct": 0.4423458594828844,
"p99_pct": 0.3639224424456612,
"mae_pct": 0.09659715578891337,
"mae_abs": 0.0017064885469153523
},
"hidden": {
"max_pct": 1.7812589183449745,
"p99_pct": 0.12670005776673085,
"mae_pct": 0.03742477565538138,
"mae_abs": 0.000944148690905422
}
}
]
}============================================================
ViT-Base-Patch16-224-In21k Performance
============================================================
Batch: 1 | Input: torch.Size([1, 3, 224, 224]) | Device: npu
Memory before warmup: 330.2 MB
Warmup: 3
Timed runs: 10
Run 1: 5.69 ms
Run 2: 5.64 ms
Run 3: 5.66 ms
Run 4: 5.64 ms
Run 5: 5.72 ms
Run 6: 5.65 ms
Run 7: 5.67 ms
Run 8: 5.71 ms
Run 9: 5.67 ms
Run 10: 5.66 ms
Device: Ascend910_9362 (61.3 GB)
Peak memory: 330.2 MB
============================================================
Results
============================================================
Avg: 5.67 ms Std: 0.03 ms
Min: 5.64 ms Max: 5.72 ms Median: 5.66 ms
Throughput: 176.35 images/s{
"model": "google/vit-base-patch16-224-in21k",
"device": "npu",
"dtype": "float32",
"batch_size": 1,
"input_shape": [
1,
3,
224,
224
],
"warmup": 3,
"num_runs": 10,
"avg_ms": 5.670595169067383,
"std_ms": 0.0280049592924108,
"min_ms": 5.635738372802734,
"max_ms": 5.722999572753906,
"median_ms": 5.662798881530762,
"throughput": 176.34833208600668,
"peak_memory_mb": 330.22119140625,
"all_runs_ms": [
5.690813064575195,
5.635738372802734,
5.659341812133789,
5.638360977172852,
5.722999572753906,
5.654096603393555,
5.666255950927734,
5.713462829589844,
5.667209625244141,
5.657672882080078
]
}license 元数据或 LICENSE 文件为准。