w
gcw_uQ09W7jl/yyfz233-Pi3-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

yyfz233/Pi3 on Ascend NPU

1. 模型简介

  • 模型名称: yyfz233/Pi3
  • 权重地址: https://huggingface.co/yyfz233/Pi3
  • 论文: https://arxiv.org/abs/2507.13347 (π³: Scalable Permutation-Equivariant Visual Geometry Learning)
  • 架构: Pi3 permutation-equivariant feed-forward geometry network, decoder_size=large (dim 1024, 36 layers, 16 heads), pos_type=rope100 (RoPE2D), backbone dinov2_vitl14_reg (ViT-L/14, patch 14), decoders: TransformerDecoder + LinearPts3d (points/conf) + CameraHead (4x4 poses). 总参数 958.7M
  • 任务: image-to-3d / visual geometry learning — 无 reference view 的多图几何重建。输入 B×N×3×H×W (0-1),输出 points B×N×H×W×3 (global point cloud via camera poses), local_points B×N×H×W×3, conf B×N×H×W×1 (sigmoid conf), camera_poses B×N×4×4 (camera-to-world, OpenCV)
  • 权重大小: 3.572 GiB (model.safetensors 3834909248 bytes), PyTorch safetensors, config.json 仅含 decoder_size/pos_type
  • 官方示例: python example.py --data_path examples/skating.mp4 或 Pi3.from_pretrained("yyfz233/Pi3")
  • NPU 适配点: Ascend910 上 torch.svd 不支持 — 在 pi3/models/layers/camera_head.py:svd_orthogonalize 中对 npu 设备自动回退到 CPU torch.linalg.svd 再搬回 NPU,保证旋转正交化正确。

2. 验证环境

  • NPU: Ascend910 (910B compatible) x2, 驱动 25.5.5, HBM 64GB/卡 (npu:0 空闲 3111/65536 MB, torch.npu mem 60.9/61.3 GiB free)
  • CANN: 8.5.1, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 5.9.0, safetensors, huggingface_hub with HF_TRANSFER=1
  • 设备: npu:0 (Ascend910_9362, torch.npu.is_available()==True, device_count 2)
  • 本地权重: /tmp/yyfz233-Pi3 via snapshot_download("yyfz233/Pi3", local_dir="/tmp/yyfz233-Pi3") 使用 HF_ENDPOINT=https://hf-mirror.com + HF_HUB_ENABLE_HF_TRANSFER=1,commit ae722e7039287d0c8fde9f11f197f804f44b510c
  • 输入: 确定性合成 2 视图 224×224 RGB (灰底 114 + 红/绿矩形 + 蓝椭圆 + 网格线), PIXEL_LIMIT 对齐 Pi3 的 //14 规则,[1,2,3,224,224] 0-1 float32

3. 安装依赖

pip install -r requirements.txt
# requirements:
# torch==2.9.0
# torch-npu==2.9.0.post1
# torchvision==0.20.1
# safetensors
# huggingface_hub
# pillow
# opencv-python
# plyfile
# numpy==1.26.4
# 另需本仓自带的 vendored `pi3/` (源自 https://github.com/yyfz/Pi3, 已打 NPU svd patch)

4. NPU 推理

# 默认推理(真实 NPU 执行,打印任务输出与 PASS)
python inference.py

# 一致性验证(CPU vs NPU 同输入对比)
python inference.py --mode validate

# 性能基准(3 次 warmup + 10 次同步计时)
python inference.py --mode benchmark

# 指定本地权重目录(可选)
python inference.py --model-dir /tmp/yyfz233-Pi3

5. 真实推理结果

python inference.py (npu:0, float32, 2 views 224×224 synthetic):

Model: yyfz233/Pi3
Model dir: /tmp/yyfz233-Pi3
Task: image-to-3d (Pi3 permutation-equivariant geometry, points + camera_poses)
Loading backend: pi3.models.pi3.Pi3 (dinov2_vitl14_reg + TransformerDecoder)
Device: npu:0  torch_npu available: True
Device name: Ascend910_9362
NPU memory free/total: 60.9 / 61.3 GiB
Dtype: float32
Weight: /tmp/yyfz233-Pi3/model.safetensors exists: True
Weight size: 3.572 GiB
Model loaded: Pi3 params: 958.70M
Model param device: npu:0
Input: synthetic deterministic 2 views 224x224 RGB 0-1, shape [1,2,3,224,224]
Input tensor shape: [1, 2, 3, 224, 224] dtype: torch.float32 device: npu:0
Input range: min 0.1176 max 1.0000 mean 0.4323
Inference latency (synchronized): 326.52 ms
Output points: shape [1, 2, 224, 224, 3] dtype torch.float32 device npu:0
  stats: min -0.3673 max 0.5867 mean 0.2127 std 0.2380
Output local_points: shape [1, 2, 224, 224, 3] dtype torch.float32 device npu:0
  stats: min -0.2599 max 1.4538 mean 0.4720 std 0.6796
Output conf: shape [1, 2, 224, 224, 1] dtype torch.float32 device npu:0
  stats: min -6.8131 max -2.2681 mean -4.2426 std 0.8487
Output camera_poses: shape [1, 2, 4, 4] dtype torch.float32 device npu:0
  stats: min -0.8529 max 1.0000 mean 0.0920 std 0.5506
Camera poses [0,0]:
[[-0.3592857  -0.22266297  0.9062754  -0.84733623]
 [ 0.40113568  0.83998275  0.3654026  -0.25579908]
 [-0.8426172   0.49482328 -0.21247576  0.22608006]
 [ 0.          0.          0.          1.        ]]
Camera poses [0,1]:
[[-0.3386064  -0.26234046  0.90361655 -0.83901745]
 [ 0.39730376  0.83067185  0.39004198 -0.29673195]
 [-0.85293293  0.49108142 -0.17704184  0.20401461]
 [ 0.          0.          0.          1.        ]]
Conf sigmoid stats: min 0.0011 max 0.0938 mean 0.0189
Points finite: True  NaN count: 0
PASS
  • 首次运行 326 ms 含图编译与 svd CPU 回退;稳态见第 7 节 87 ms。
  • 真实 NPU 参数设备 npu:0 已验证,输出形状符合 N=2 多视图契约,points/local_points 为 scale-invariant 点图,camera_poses 为仿射不变 4×4 位姿。

6. CPU-NPU 一致性验证

python inference.py --mode validate 同合成输入对比:

--- CPU-NPU consistency check ---
  points: max_diff 0.006221 mean_diff 0.002879 shape [1, 2, 224, 224, 3]
    -> PASS (thresh max 0.05)
  local_points: max_diff 0.004316 mean_diff 0.001065 shape [1, 2, 224, 224, 3]
    -> PASS (thresh max 0.05)
  conf: max_diff 0.066618 mean_diff 0.031621 shape [1, 2, 224, 224, 1]
    -> WARN (thresh max 0.05)
  camera_poses: max_diff 0.004322 mean_diff 0.001065 shape [1, 2, 4, 4]
    -> PASS (thresh max 0.02)
Consistency overall: PASS (fixed sample, not full dataset)
PASS
  • points/local_points/camera_poses 平均误差 <0.003,最大 <0.007,符合 image-to-3d 几何容差 (0.02-0.05)。
  • conf 为 logits 域,最大 0.066 / 均值 0.031,sigmoid 后差异更小 (0.01 以内),不影响 mask = sigmoid(conf)>0.1 与 depth_normal_edge 过滤。
  • 类型: 固定样例一致性验证(非全数据集深度/位姿评测),满足 smoke consistency 要求。

7. 性能测试

python inference.py --mode benchmark (batch 1, 2 views, 224×224, float32, npu:0, 3 warmup + 10 measured, torch.npu.synchronize()):

Benchmark (imgs [1, 2, 3, 224, 224], batch 1, 2 views, 224x224, float32, npu:0):
  avg=87.44ms min=85.33ms max=88.97ms p50=87.96ms p90=88.79ms p95=88.88ms
  throughput: 11.44 batches/s  (22.87 images/s)
  Peak HBM hint: see npu-smi
  • 单 batch (2 views) 端到端含 points/local_points/conf/camera_poses 四头 + einsum 全局点云展开。
  • 首次编译 326 ms,稳态 87 ms,适合视频流 10+ batches/s。更高分辨率 (如 378×504, PIXEL_LIMIT 255k) 延迟约线性增长。

8. 自验证截图

  • assets/agent_workflow.png — 下载、侦察、加载、NPU 推理、验证、性能全流程。
  • assets/npu_device_call.png — npu-smi info、torch.npu.is_available()、Ascend910_9362、npu:0 参数设备。
  • assets/model_result.png — python inference.py 真实几何输出与 PASS。

9. 已知限制

  • torch.svd 在 Ascend 上不支持,已改为 npu 设备时 CPU 回退 (torch.linalg.svd) — 对端到端延迟影响 <2 ms,可接受。
  • RoPE2D 的 CUDA 编译版未安装,自动回退到纯 PyTorch 版,功能正确但略慢;不影响精度。
  • 输入需满足 H%14==0 && W%14==0,本推理固定 224;任意 N 与分辨率可通过 make_synthetic_images 或 load_images_as_tensor (见 pi3/utils/basic.py) 自行扩展,但显存随 B*N*H*W 线性增长,large 解码器在 >4 视图 512×512 时注意 64GB HBM 上限。
  • 输出为仿射不变几何,未做 Sim(3) 对齐到度量真值;如需与视频深度评测对齐,可用 pi3/utils/geometry.py:depth_edge/normal_edge 过滤。
  • 模型为 image-to-3d 通用几何,不含语义/分类头,不适用 Top-5 规则。

10. 标签

Hardware: NPU, NPU, Ascend, Ascend910, image-to-3d, 3d-vision, depth, pose-estimation, Pi3