g
gcw_coj3XaOd/businesslion_scaffdiff
模型介绍
文件和版本
Pull Requests
讨论
分析

ScaffDiff - 昇腾 NPU 推理部署

1. 模型简介

模型名称: businesslion/scaffdiff

模型链接: HuggingFace | AtomGit 镜像

模型描述: ScaffDiff 是一款面向 3D 场景补全的单步、支架引导的扩散模型。基于 SemanticKITTI 数据集,它通过局部点云输入完成完整 3D 场景重建。

模型架构:

  • VAE (7.1M 参数):多 token 高斯 VAE,采用残差 PointNet 编码器 + 32 个 query 的交叉注意力池化器 + 5 层 Transformer 解码器
  • Denoiser (6.4M 参数):支架引导的单步扩散去噪器,采用余弦调度(1,000 个时间步),推理时取 t=200
  • Encoder (Sonata/PTv3, 108M 参数):冻结的自监督预训练点云编码器(推理时以简化版本替代)

参数规模: 约 124M(VAE:7.1M + Denoiser:6.4M + Encoder:108M,冻结)

输入规格:

  • 类型:3D 点云 (B, 3, N)
  • 点数:可变(典型为 2,000–20,000 点/帧)

输出规格:

  • 类型:3D 点云 (B, 3, 8000)
  • 点数:8,000 点/帧(由 VAE 解码生成)

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
numpy>= 1.20数值计算
open3d>= 0.13点云处理(可选)
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu==2.9.0.post1
pip install numpy open3d

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

方式一:AtomGit 镜像(推荐,HuggingFace 下载较慢时使用)

# 权重文件已包含在 HuggingFace 镜像中
# 使用 hf-mirror 下载:
export HF_ENDPOINT=https://ai.gitcode.com/hf_mirrors
huggingface-cli download businesslion/scaffdiff --local-dir ./scaffdiff_ckpt

方式二:HuggingFace

huggingface-cli download businesslion/scaffdiff --local-dir ./scaffdiff_ckpt

3.3 运行推理

# VAE 推理 (点云编码-解码)
python inference.py \
  --checkpoint-type vae \
  --model-path checkpoints/best_point_vae.pth \
  --device npu \
  --num-frames 3

# Teacher Denoiser 推理 (单步去噪)
python inference.py \
  --checkpoint-type teacher-ft \
  --model-path checkpoints/teacher_v2gt_ft/best_model.pth \
  --device npu \
  --num-frames 1

3.4 推理参数说明

参数类型默认值说明
--checkpoint-typestr必填模型类型: vae 或 teacher-ft
--model-pathstr必填模型 checkpoint 路径
--devicestrcpu推理设备: cpu 或 npu
--num-framesint1推理帧数

3.4 启动服务

# 启动 VAE 推理服务
python inference.py \
  --checkpoint-type vae \
  --model-path checkpoints/best_point_vae.pth \
  --device npu \
  --num-frames 1

3.5 推理调用

单条推理:

python inference.py \
  --checkpoint-type vae \
  --model-path checkpoints/best_point_vae.pth \
  --device npu \
  --num-frames 1

批量推理:

python inference.py \
  --checkpoint-type vae \
  --model-path checkpoints/best_point_vae.pth \
  --device npu \
  --num-frames 8

教师去噪器推理:

python inference.py \
  --checkpoint-type teacher-ft \
  --model-path checkpoints/teacher_v2gt_ft/best_model.pth \
  --device npu \
  --num-frames 1

4. 推理成功日志

4.1 VAE 单条推理日志

[VAE] Loading checkpoint from checkpoints/best_point_vae.pth ...
  [WARN] Missing keys (2): ['centering_mean', 'centering_std']...
[VAE] Config: num_latent_tokens=32, num_decoded_points=8000, internal_dim=256
[VAE] Parameters: 7,107,523 (7.11M)

  Frame 0: MSE=0.055769, MeanDist=0.3776, Time=118.2ms, OutputShape=(1, 3, 8000)

[RESULT] VAE inference completed: 1 frame(s)
[SUCCESS] ScaffDiff inference completed on Ascend910_9362

4.2 教师去噪器推理日志

[Teacher] Loading checkpoint from checkpoints/teacher_v2gt_ft.pth ...
[Teacher] Denoiser loaded: missing=50, unexpected=212
[Teacher] Parameters: 6,407,043 (6.41M)

  Frame 0: DeltaMean=0.0564, DeltaStd=0.5046, Time=1244.4ms, OutputShape=(1, 20000, 3)

[RESULT] Teacher denoiser inference completed: 1 frame(s)

4.3 批量推理日志 (3帧 VAE)

[基准测试] 3帧 VAE 推理统计:
  Frame 0: MSE=0.064385, MeanDist=0.4055, Time=65.7ms
  Frame 1: MSE=0.055322, MeanDist=0.3772, Time=4.5ms
  Frame 2: MSE=0.062160, MeanDist=0.3990, Time=4.7ms
  平均MSE: 0.0606
  平均耗时: 25.0ms/frame (首帧后 4.6ms)

5. 测试示例与输出结果

示例 1:VAE 单帧推理

运行命令:

python inference.py --checkpoint-type vae --model-path checkpoints/best_point_vae.pth --device npu --num-frames 1

输出:

[INFO] Device: Ascend910_9362 (npu)
[INFO] Checkpoint: checkpoints/best_point_vae.pth (81.5 MB)
[VAE] Loading checkpoint from checkpoints/best_point_vae.pth ...
[VAE] Config: num_latent_tokens=32, num_decoded_points=8000, internal_dim=256, num_dec_blocks=5
[VAE] Parameters: 7,107,523 (7.11M)
  Frame 0: MSE=0.061752, MeanDist=0.3977, Time=146.5ms, OutputShape=(1, 3, 8000)
[RESULT] VAE inference completed: 1 frame(s)
[SUCCESS] ScaffDiff inference completed on Ascend910_9362

样例 2:Teacher Denoiser 推理

运行命令:

python inference.py --checkpoint-type teacher-ft --model-path checkpoints/teacher_v2gt_ft.pth --device npu --num-frames 1

输出:

[INFO] Device: Ascend910_9362 (npu)
[INFO] Checkpoint: checkpoints/teacher_v2gt_ft.pth (448.2 MB)
[Teacher] Denoiser loaded: missing=50, unexpected=212
[Teacher] Parameters: 6,407,043 (6.41M)
  Frame 0: DeltaMean=0.0564, DeltaStd=0.5046, Time=1244.4ms, OutputShape=(1, 20000, 3)
[RESULT] Teacher denoiser inference completed: 1 frame(s)
[SUCCESS] ScaffDiff inference completed on Ascend910_9362

6. Agent 适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: 随机生成点云(SemanticKITTI 格式)

评测指标:

指标结果说明
VAE 重建 MSE0.0606(平均)3 帧平均
VAE 平均点距离0.391(平均)3 帧平均
VAE 推理速度约 25.0 ms/帧Ascend 910(首帧 118 ms)
教师去噪器 ΔMean0.0564单步 t=200
教师去噪器速度约 1244 ms/帧Ascend 910

评测命令:

python inference.py --checkpoint-type vae --model-path checkpoints/best_point_vae.pth --device npu --num-frames 3

8. NPU 配置说明

  • NPU 型号: Ascend910_9362(2 卡)
  • 设备: npu:0
  • CANN 版本: 8.5.1
  • torch_npu 版本: 2.9.0.post1+gitee7ba04
  • VAE 显存占用: 约 0MB(预处理采用 CPU offload)
  • Denoiser 显存占用: 约 0MB

9. 已知问题

  1. NPU torch.randn_like 格式警告: 使用 base format 替代 internal format(非关键问题)
  2. Sonata/PTv3 编码器不可用: 原始模型使用 108M 参数的 Sonata 预训练编码器,需要 sonata 包。当前推理使用简化版 PointNet 编码器替代
  3. Teacher checkpoint 部分 key 不匹配: 仅加载 denoiser head 权重(完整模型中有 50 个缺失 key、212 个未预期 key)
  4. BatchNorm 替换为 LayerNorm: 原始 VAE 编码器使用 BatchNorm1d,已替换为 LayerNorm,以兼容 NPU 的 (B, N, C) 矩阵乘法格式