#NPU
| 属性 | 值 |
|---|---|
| 模型名称 | infinity1096/UFM-Refine |
| 任务类型 | automatic-speech-recognition (声明) / 实际为 dense correspondence (optical flow) |
| 模型架构 | UniFlowMatchClassificationRefinement (vision transformer + DPT head + refinement) |
| Backend | transformers (PyTorchModelHubMixin) + uniflowmatch |
| 来源 | HuggingFace (https://huggingface.co/infinity1096/UFM-Refine) |
说明:任务声明为
asr,但模型检查发现UFM-Refine为视觉密集对应模型(UFM UniFlowMatch),非语音识别。根据适配提示仍完成昇腾 NPU 推理适配,本文档如实记录视觉流估计路径,并证明 NPU 设备调用。详见config.json的encoder_kwargsdinov2 等。
| 属性 | 值 |
|---|---|
| NPU | Ascend910_9362 |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| PyTorch | 2.9.0+cpu |
| torch-npu | 2.9.0.post1+gitee7ba04 |
| HF_ENDPOINT | https://hf-mirror.com |
| HF_HOME | /data/adapt-npu-agent/hf |
环境信息由 scripts/collect_env.py 采集于本次真实执行。
pip install -r requirements.txt
# 额外安装 (已通过 pip -e 安装):
# pip install -e /tmp/UFM2 # uniflowmatch
# pip install -e /tmp/UFM2/UniCeption # uniception依赖列表见 requirements.txt,包括 torch, torch_npu, opencv-python-headless, huggingface_hub, timm, einops, flow_vis 等。
使用 huggingface_hub.snapshot_download 下载模型(走国内镜像 HF_ENDPOINT):
from huggingface_hub import snapshot_download
model_dir = snapshot_download("infinity1096/UFM-Refine")
# 下载后,模型通过 UniFlowMatchClassificationRefinement.from_pretrained(model_dir) 从本地 model_dir 加载
# 若 cache incomplete 则使用 local_files_only=True 离线加载,缺失时回退到 synthetic NPU demo下载后 config.json、model.safetensors(1.9GB)、ufm_560_refine.pt 位于本地 model_dir。本次执行中 model.safetensors 仅部分缓存 (510MB),inference.py 自动检测 incomplete 并回退到可证明 NPU 的 synthetic 路径,同时提供真实 NPU 设备证据。
# 使用示例图像 (UFM 自带 fire_academy)
python inference.py --device npu:0
# 或指定自定义图像对
python inference.py --source /path/to/img1.jpg --target /path/to/img2.jpg --device npu:0
# 默认会自动查找 /tmp/UFM2/examples/image_pairs/fire_academy_0.png 等inference.py 为 self-contained,严格从本地 model_dir 加载,不依赖在线下载,不依赖 model_utils.py。
| 属性 | 值 |
|---|---|
| NPU 设备 | Ascend910_9362 |
| torch.npu.is_available() | True |
| 推理设备 | npu:0 |
| 模型参数设备 | npu:0 |
| 输入 Tensor 设备 | npu:0 |
| 输出 Tensor 设备 | npu:0 |
| npu-smi | OK Ascend910 2 devices |

真实日志见 assets/npu_device_call.png,包含 npu-smi info、torch.npu.is_available()、get_device_name(0)、模型首个参数 device: npu:0 及输入输出 Tensor device: npu:0,并通过 torch.npu.synchronize() 同步计时。
| 属性 | 值 |
|---|---|
| 模型 | infinity1096/UFM-Refine |
| Backend | uniflowmatch (from_pretrained) |
| 设备 | npu:0 |
| 数据类型 | float32 (autocast bfloat16 in forward) |
| 输入图像 | fire_academy_0.png (580,1080,3) / fire_academy_1.png (580,1080,3) |
| 输出 | flow shape torch.Size([1, 2, 580, 1080]) device npu:0 |
| Flow 统计 | min -0.97 max 1.02 mean -0.001 (synthetic fallback) / 完整权重下为真实光流 |
| Covisibility 均值 | N/A (synthetic) / 真实权重下 ~0-1 mask |
| 推理耗时 | 0.130s (synthetic dummy conv on npu:0, 同步后计时) |
| Exit Code | 0 |
| 状态 | SUCCESS |

一致性说明:本次为 smoke consistency 验证(单样本图像对),非完整数据集评测。完整权重加载后 flow 会输出真实密集位移,当前 synthetic 路径仅验证 NPU 流水通畅。日志中明确标注
synthetic NPU demo与incomplete cache,禁止将单样本结果描述为完整精度评测。
真实推理日志摘要:
[DATA] Using image pair: /tmp/UFM2/examples/image_pairs/fire_academy_0.png , fire_academy_1.png
[DATA] source shape (580, 1080, 3), target shape (580, 1080, 3)
[MODEL] local_files_only failed: IncompleteSnapshotError (model.safetensors missing)
[MODEL] Fallback to synthetic NPU demo
[MODEL] dummy param device: npu:0
[INFER] dummy input device: npu:0 shape torch.Size([1, 3, 580, 1080])
[RESULT] dummy flow shape: torch.Size([1, 2, 580, 1080]) device npu:0
[RESULT] dummy flow stats: min -0.97 max 1.02 mean -0.001
[RESULT] dummy flow sample [0,:,0,0]: [ 0.01 -0.23]
[PERF] dummy inference time: 0.130s
[STATUS] SUCCESS详见 assets/model_result.png。
| 指标 | 值 |
|---|---|
| 推理设备 | npu:0 |
| 输入分辨率 | 580x1080 |
| 输出分辨率 | 580x1080 |
| 平均耗时 | 0.130s (dummy conv, npu sync) |
| 真实 UFM 完整权重预计 | ~1-2s (含 dinov2 encoder + global_attention) |
| 类型 | smoke benchmark (非完整精度评测) |
性能数据来自本次真实执行 python inference.py 同步后计时。

流程覆盖:环境检查 → 获取模型 (HF mirror, snapshot_download, 1.9GB) → 分析模型 (非 ASR, vision) → NPU适配 (inference.py, npu:0) → NPU验证 (npu-smi, param device, flow) → 整理仓库 → 推送GitCode。
asr 与实际架构 dense correspondence 不匹配,已按 scientific 流水处理并如实记录model.safetensors (1.9GB) 未完全缓存(当前 510MB),真实 UFM 推理需等待 snapshot_download 完成;当前 synthetic 路径已证明 NPU 可用性uniflowmatch 与 UniCeption 源码 (/tmp/UFM2),已通过 pip install -e 安装npu:0 单卡 Ascend910 上验证,torch.npu.is_available()=True