we166488/webssl-mae700m-full2b-224
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

webssl-mae700m-full2b-224 昇腾 NPU 部署文档

模型: facebook/webssl-mae700m-full2b-224
任务: 视觉特征提取 (Vision Transformer)
硬件: 昇腾 Ascend 910
适配组织: Ascend-SACT
报告日期: 2026-05-20


1. 模型简介

属性值
模型架构ViT-Huge (Vision Transformer)
参数量700M
输入分辨率224×224
隐藏层大小1280
层数32
图像块大小(Patch Size)14
预训练方法Web-MAE(掩码自编码器)
适用任务图像特征提取、视觉表征学习

2. 环境配置

2.1 硬件要求

项目配置
NPU 型号Ascend 910 / 910B
NPU 数量≥ 1 卡
内存≥ 16 GB
存储≥ 10 GB(模型文件约 2.5 GB)

2.2 软件环境

项目版本
操作系统EulerOS 2.10 / CentOS 7.6 / Ubuntu 22.04
CANN≥ 8.0
Python3.9 / 3.10 / 3.11
PyTorch2.9.0+cpu
torch_npu2.9.0.post1
transformers4.57.6

2.3 依赖安装

# 激活 CANN 环境
source /usr/local/Ascend/ascend-toolkit/set_env.sh

# 安装 PyTorch
pip install torch==2.9.0 --index-url https://download.pytorch.org/whl/cpu

# 安装 torch_npu
pip install torch_npu==2.9.0.post1

# 安装 transformers 及其他依赖
pip install transformers==4.57.6 Pillow numpy scipy

2.4 NPU 状态检查

npu-smi info

确认 NPU 状态为 OK 且温度正常。


3. 快速开始

3.1 模型文件准备

将模型权重与配置文件放置于 model_files/ 目录下:

model_files/
├── config.json
├── preprocessor_config.json
└── model.safetensors

3.2 单图推理

# NPU FP32 推理
python inference.py \
  --model_path ./model_files \
  --device npu \
  --precision fp32 \
  --image path/to/your/image.jpg \
  --save_features \
  --output_dir ./outputs

# NPU FP16 推理
python inference.py \
  --model_path ./model_files \
  --device npu \
  --precision fp16 \
  --image path/to/your/image.jpg \
  --save_features \
  --output_dir ./outputs

3.3 一键精度验证

python accuracy_run.py --precision fp32 --output_dir ./logs
python accuracy_run.py --precision fp16 --output_dir ./logs

3.4 性能基准测试

python accuracy_run_perf.py --device npu --precision fp32 --output_dir ./logs
python accuracy_run_perf.py --device npu --precision fp16 --output_dir ./logs

3.5 验收检查

python check_accuracy_run_perf.py --precision both --output_dir ./logs

4. 评测结果摘要

4.1 精度结果

精度模式余弦相似度最大差值平均差值判定
FP321.000003222.90e-021.76e-03通过
FP160.999999344.59e-021.82e-03通过

4.2 性能结果

精度模式平均延迟吞吐量延迟标准差
FP3215.13 ms66.09 img/s0.33 ms
FP1614.91 ms67.05 img/s0.48 ms

4.3 耗时拆解

阶段耗时占比
预处理(CPU)1.52 ms9.2%
H2D 数据拷贝0.10 ms0.6%
纯推理(NPU)14.97 ms90.2%

5. 运行证据

以下为本仓库脚本在 Ascend910_9362 上的真实终端输出(复制自实际运行日志)。

5.1 NPU 推理脚本输出

============================================================
Web-SSL MAE ViT-H Inference on Ascend NPU
============================================================
Device selected: npu
NPU Device: Ascend910_9362
torch version: 2.9.0+cpu
torch_npu version: 2.9.0.post1+gitee7ba04

[1/4] Loading model and processor...
  Model loaded in 2.37s

[2/4] Preparing input data...
  Input shape: torch.Size([1, 3, 224, 224])

[3/4] Warm-up inference...

[4/4] Running benchmark inference...
  Output shape: torch.Size([1, 257, 1280])
  Output dtype: torch.float32
  Output mean: 0.010152
  Output std: 0.479154
  Output max: 6.903232
  Output min: -14.741646
  Average inference time (5 runs): 0.0146s
  NPU Memory: allocated=2478.5MB, reserved=2584.0MB
  Model load time: 2.37s
  Avg inference time: 0.0146s

Web-SSL MAE ViT-H NPU inference completed successfully!

5.2 标准推理脚本 (inference.py) 输出

[INFO] Using device: npu:0
[INFO] Using precision: fp32 (torch.float32)
[INFO] Loading model from ./model_files ...
[INFO] Model loaded. Parameters: ~700M
[INFO] No image provided, using random 224x224 image
[INFO] Input shape: torch.Size([1, 3, 224, 224])
[INFO] Warmup 3 rounds ...
[INFO] Running inference ...

===== Inference Result =====
Feature shape:        torch.Size([1, 257, 1280])
Feature dtype:        torch.float32
Feature mean:         0.009344
Feature std:          0.479671
Feature min:          -13.164553
Feature max:          7.015934
Inference latency:    15.00 ms
Throughput:           66.67 images/sec

[INFO] Features saved to ./outputs/features_npu_fp32.pt
[INFO] Metadata saved to ./outputs/meta_npu_fp32.json

[INFO] Inference completed successfully.

5.3 CPU 与 NPU 精度验证输出

============================================================
Web-SSL MAE ViT-H CPU vs NPU Precision Verification
============================================================
NPU Device: Ascend910_9362
torch version: 2.9.0+cpu
torch_npu version: 2.9.0.post1+gitee7ba04

[1/5] Loading model and processor...
  Model loaded

[2/5] Preparing fixed input...
  Input shape: torch.Size([1, 3, 224, 224])

[3/5] Running CPU inference (baseline)...
  CPU output shape: (1, 257, 1280)
  CPU output mean: 0.010283, std: 0.479693

[4/5] Running NPU inference...
  NPU output shape: (1, 257, 1280)
  NPU output mean: 0.010280, std: 0.479144

[5/5] Comparing precision...
  Max absolute diff: 7.184887e-02
  Mean absolute diff: 1.831753e-03
  MSE: 6.355060e-06
  Relative L2 error: 5.254095e-03 (0.5254%)
  Cosine similarity: 0.99998784
  Max relative error (|cpu| > 1e-4): 4.881472e+01

  Primary metric: Relative L2 error = 0.5254% (threshold < 1%)
  Secondary metric: Cosine similarity = 0.99998784 (threshold > 0.999)

  ✅ Precision verification PASSED

Precision verification completed!

5.4 截图证据

推理成功截图 推理成功

精度通过截图 精度通过

性能基准截图 性能基准

6. 项目结构

.
├── inference.py                 # 标准推理脚本
├── accuracy_run.py              # 精度评测脚本
├── accuracy_run_perf.py         # 性能评测脚本
├── check_accuracy_run_perf.py   # 验收检查脚本
├── webssl_npu_infer.py          # NPU推理与性能基准脚本
├── webssl_npu_verify.py         # CPU vs NPU精度验证脚本
├── webssl_npu_adaptation_report.md  # 完整适配报告
├── logs/                        # 评测日志与报告
│   ├── accuracy_report_fp32.json
│   ├── accuracy_report_fp16.json
│   ├── perf_report_npu:0_fp32.json
│   ├── perf_report_npu:0_fp16.json
│   └── run_*.log
├── screenshots/                 # 自验证截图
│   ├── inference_success.png
│   ├── accuracy_passed.png
│   └── perf_benchmark.png
├── model_files/                 # 模型权重(用户自备)
└── readme.md                    # 本部署文档

7. 常见问题 (FAQ)

Q1: NPU 推理时出现 LOG_WARNING
A: 检查 CANN 环境是否激活。LOG_WARNING 不影响推理功能。

Q2: FP16 为什么没有明显加速?
A: 当前 torch_npu 2.9.0 版本中部分 ViT 算子的 FP16 融合优化有限。建议后续升级 torch_npu/CANN。

Q3: 如何验证模型是否正确加载?
A: 运行 python inference.py --device npu --precision fp32,检查输出特征形状是否为 [1, 257, 1280]。


8. 引用

@article{fan2025scaling,
  title={Scaling Language-Free Visual Representation Learning},
  author={David Fan and Shengbang Tong and Jiachen Zhu and Koustuv Sinha and Zhuang Liu and Xinlei Chen and Michael Rabbat and Nicolas Ballas and Yann LeCun and Amir Bar and Saining Xie},
  year={2025},
  eprint={2504.01017},
  archivePrefix={arXiv},
  primaryClass={cs.CV}
}

本文档由 Model Agent 自动生成,用于昇腾 NPU 模型适配交付。