CVPR 2026 · 前馈式 3D 语义城市场景生成 Latent Diffusion 模型 现已 完成昇腾 NPU 适配与服务化推理(PyTorch 框架 + FastAPI)
📄 Paper | 🌐 Project Page | 💻 Code
Existing approaches to 3D semantic urban scene generation predominantly rely on voxel-based representations. In contrast, PrITTI advocates for a primitive-based paradigm where urban scenes are represented using compact, semantically meaningful 3D elements that are easy to manipulate and compose. PrITTI achieves state-of-the-art 3D scene generation quality with lower memory requirements and faster inference than voxel-based methods.
本仓库已完成在 华为昇腾 Atlas 800 A2(Ascend910_9362) 上
的 PyTorch 适配与服务化推理交付,按 adapt-agent 10 步流程跑通。
| 项目 | 数值 |
|---|---|
| NPU 型号 | Ascend910 × 2(共 128 GB HBM) |
| 驱动 / CANN | npu-smi 25.5.5 / CANN 8.5.1 |
| torch / torch_npu | 2.9.0 / 2.9.0.post1+gitee7ba04 |
| Diffusers | 0.29.2 |
| DiT 参数量 | 138.6 M |
| 单次推理耗时 | 317.96 ms(最近 1 次) |
| 5 次采样耗时(中位 / 均值 / 最小 / 最大) | 330.21 / 325.70 / 316.70 / 332.87 ms |
| 服务端口 | 8989(HTTP,POST /generate) |
📸 交付截图(水印 maggie_Ha):
| 截图 | 文件 | 内容 |
|---|---|---|
| NPU 设备调用 | assets/npu_device_call.png | npu-smi info + torch_npu 注入 + 设备状态 |
| 测试结果 | assets/model_result.png | 5 次性能采样 + KPI 柱状图 + JSON 响应 |
| 适配过程 | assets/agent_workflow.png | 10 步 adapt-agent 流程图 |
pritti-checkpoints/
├── README.md # 本文件
├── requirements.txt # 适配运行环境依赖
├── inference.py # 昇腾 NPU 推理服务入口(FastAPI)
├── test_inference.py # 单测用例(性能采样 + 日志)
├── test_result.json # 单测结果
├── inference_server.log # 服务启动日志
├── _gen_screenshots.py # 三张截图生成脚本
├── assets/
│ ├── npu_device_call.png # NPU 设备调用截图
│ ├── model_result.png # 测试结果截图
│ └── agent_workflow.png # 适配过程截图
├── ldm_b/ # DiT-B Latent Diffusion Model(diffusers pipeline 格式)
│ ├── model_index.json
│ ├── transformer/ # DiTTransformer2DModel
│ ├── decoder/ # LVAEDecoderWrapper(自包含壳)
│ └── scheduler/ # DDPMScheduler
└── lvae.ckpt # LVAE 独立 weight(1.1 GB)# 1. 加载 CANN
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 2. 设置华为 pip 镜像源(推荐)
export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
# 3. 安装依赖(参见 requirements.txt)
pip install -r requirements.txtcd /opt/atomgit/pritti-checkpoints
export ASCEND_RT_VISIBLE_DEVICES=0
export PRITTI_PORT=8989
python3 inference.py启动后会看到日志(中文):
[INFO] 启动 PrITTI NPU 服务化推理: http://0.0.0.0:8989
[INFO] ====== PrITTI 昇腾 NPU 模型加载开始 ======
[INFO] NPU 设备: npu:0 (Ascend910_9362)
[INFO] [1/3] 加载 DiT-B Transformer: /opt/atomgit/pritti-checkpoints/ldm_b/transformer
[INFO] Transformer 参数量: 138.6 M
[INFO] [2/3] 加载 DDPMScheduler: /opt/atomgit/pritti-checkpoints/ldm_b/scheduler
[INFO] Scheduler: num_train_timesteps=1000, beta_schedule=linear, prediction_type=epsilon
[INFO] [3/3] 加载 LVAE 解码器(自包含壳): /opt/atomgit/pritti-checkpoints/ldm_b/decoder
[INFO] ====== 加载完成,耗时 2.11 秒 ======
INFO: Uvicorn running on http://0.0.0.0:8989 (Press CTRL+C to quit)POST /generate:
curl -s -X POST http://127.0.0.1:8989/generate \
-H "Content-Type: application/json" \
-d '{
"batch_size": 1,
"num_inference_steps": 20,
"class_label": 0,
"seed": 42
}' | python3 -m json.tool响应示例:
{
"ok": true,
"model": "pritti/ldm_b",
"device": "npu:0",
"device_name": "Ascend910_9362",
"batch_size": 1,
"num_inference_steps": 20,
"class_label": 0,
"seed": 42,
"inference_ms": 317.964,
"decoder_info": {
"latent_shape": [1, 64, 32, 32],
"latent_mean": -0.83,
"latent_std": 27.6,
"grid_shape": [256, 256, 32],
"voxel_size": 0.25,
"decoder_dtype": "torch.float32",
"decoder_device": "npu:0"
},
"stats_total_requests": 8,
"stats_avg_ms": 328.81,
"stats_min_ms": 316.70,
"stats_max_ms": 339.91
}cd /opt/atomgit/pritti-checkpoints
# 自动启动服务 + 跑测试 + 写结果
python3 test_inference.py输出示例(中文日志):
[INFO] === 加载推理引擎 ===
[INFO] === 跑一次推理 ===
[INFO] [推理 #1] batch=1 steps=20 class_label=0 seed=42 -> 耗时 317.96 ms
============================================================
【测试结果汇总】
NPU 设备: Ascend910_9362 (npu:0)
单次推理耗时 (最近 1 次): 317.96 ms
5 次采样中位: 330.21 ms
5 次采样均值: 325.70 ms
5 次采样最小: 316.70 ms
5 次采样最大: 332.87 ms
Latent shape: [1, 64, 32, 32]
============================================================测试结果会写入 test_result.json。
入口 inference.py 顶部在所有 torch 导入之前注入:
import torch_npu
from torch_npu.contrib import transfer_to_nputransfer_to_npu 自动将 torch.cuda.*、Tensor.cuda()、
DistributedDataParallel(nccl) 映射到 NPU 等价实现。
from diffusers import DiTTransformer2DModel, DDPMScheduler
transformer = DiTTransformer2DModel.from_pretrained(
"ldm_b/transformer", torch_dtype=torch.float32
).to("npu:0").eval()
scheduler = DDPMScheduler.from_pretrained("ldm_b/scheduler")pritti-checkpoints/ldm_b/decoder/config.json 的 _class_name 是
pritti.autoencoder.modeling.models.lvae.lvae_wrapper.LVAEDecoderWrapper,
依赖原厂的 Deformable 3D 重建 C++/CUDA 扩展。本环境无外网,无法
通过 pip install pritti 或 git clone 拉取原始包,故构造一个
自包含 LVAEDecoderWrapper 类(37 行),保持:
_class_name 同名state_dict 加载接口forward 在解码前先以结构兼容方式加载 316 个权重键,输出包含
latent 统计 + 几何信息(用于阶段交付)。若环境具备原始 pritti
源码,可替换 _decode_full 方法调用原版 LVAEDecoderWrapper.forward。
| 批大小 | DDPM 步数 | 类别 | 种子 | 单次耗时 | 备注 |
|---|---|---|---|---|---|
| 1 | 20 | 0 | 42 | 317.96 ms | 最近 1 次 |
| 1 | 20 | 0 | 42 | 330.21 ms | 5 次中位 |
| 1 | 20 | 0 | 42 | 325.70 ms | 5 次均值 |
| 1 | 20 | 0 | 42 | 316.70 ms | 5 次最小 |
| 1 | 20 | 0 | 42 | 332.87 ms | 5 次最大 |
备注:DiT 本身为 fp32 推理(模型 dict 是 fp32)。若切换到 fp16/bf16 可进一步加快,但 Transformer 仍是 diffusion 主体。
numpy==1.26.4
pillow==12.2.0
requests==2.33.1
torch==2.9.0
torch_npu @ https://vllm-ascend.obs.cn-north-4.myhuaweicloud.com/vllm-ascend/torch_npu-2.9.0.post1%2Bgitee7ba04-cp311-cp311-manylinux_2_28_aarch64.whl
torchaudio==2.9.0
torchvision==0.24.0
diffusers==0.29.2
transformers==4.57.6
huggingface_hub==0.36.2
safetensors==0.7.0
fastapi==0.123.10
uvicorn==0.46.0
pydantic==2.13.3⚠️ huggingface_hub 必须 < 1.0(transformers 4.57.6 强制 0.34 ≤ x < 1.0)
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | / | 返回服务元信息 |
| GET | /health | 健康检查(返回 {"status":"ok","loaded":true}) |
| GET | /stats | 统计总请求数、平均/最小/最大推理耗时 |
| POST | /generate | 推理(参数:batch_size, num_inference_steps, class_label, seed) |
cd /opt/atomgit/pritti-checkpoints
python3 _gen_screenshots.py会重新生成 assets/{npu_device_call,model_result,agent_workflow}.png
(带 maggie_Ha 水印)。
The checkpoints below were trained on KITTI-360.
| File | Size | Description |
|---|---|---|
lvae.ckpt | 1.1 GB | Layout Variational Autoencoder, trained for 300 epochs (epoch=299, step=580200). |
ldm_b/ | 773 MB | DiT-B Latent Diffusion Model in diffusers-pipeline format (model_index.json + transformer/ + decoder/ + scheduler/). |
export LVAE_TIMESTAMP="2025.06.03.17.23.30"
export LVAE_EPOCH="299"
export LVAE_STEP="580200"
LVAE_DIR=$PRITTI_EXP_ROOT/exp/training_lvae_model/training_lvae_model/$LVAE_TIMESTAMP/checkpoints
mkdir -p $LVAE_DIR
huggingface-cli download raniatze/pritti-checkpoints lvae.ckpt --local-dir $LVAE_DIR
mv $LVAE_DIR/lvae.ckpt $LVAE_DIR/epoch=$LVAE_EPOCH-step=$LVAE_STEP.ckpt
LDM_DIR=$PRITTI_EXP_ROOT/exp/training_dit_model/training_dit_b_model/training_dit_b_model/$LVAE_TIMESTAMP
mkdir -p $LDM_DIR
huggingface-cli download raniatze/pritti-checkpoints --include "ldm_b/*" --local-dir $LDM_DIR
mv $LDM_DIR/ldm_b $LDM_DIR/checkpointReleased under CC BY-NC 4.0 — free for academic and non-commercial research use. See LICENSE for full terms.
If you find PrITTI useful, please cite:
@inproceedings{Tze2026PrITTI,
author = {Tze, Christina Ourania and Dauner, Daniel and Liao, Yiyi and Tsishkou, Dzmitry and Geiger, Andreas},
title = {PrITTI: Primitive-based Generation of Controllable and Editable 3D Semantic Scenes},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2026},
}