w
gcw_uQ09W7jl/microsoft-TRELLIS.2-4B-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

microsoft/TRELLIS.2-4B on Ascend NPU

1. 模型简介

TRELLIS.2-4B 是微软发布的 3D 生成大模型 (4B 参数),基于 O-Voxel 稀疏体素表示与 Flow-Matching Transformer,支持单图生成高保真 3D 资产 (Mesh + PBR 材质,含透明/半透明)。模型采用 field-free 结构,支持任意拓扑、锐利特征与全材质,latent 空间 16x 下采样 (1024^3 -> ~9600 tokens)。本仓库在单卡 Ascend910B npu:0 上验证真实权重推理。

  • Pipeline: Trellis2ImageTo3DPipeline (sparse_structure_decoder + ss_flow + shape/tex slat flows + decoders)
  • 权重总量: ~15-20GB (8x safetensors, 每个 0.9-2.6GB), 本 NPU 验证聚焦 shape_dec_next_dc_f16c32_fp16 (904.6 MB, 292 tensors) 与 tex_dec_next_dc_f16c32_fp16 (904.5 MB, 284 tensors) 两个可用权重 + pipeline json。
  • 输入: 单张 RGB 图像 (512x512)
  • 输出: O-Voxel -> Mesh (vertices/faces) + PBR attrs (base_color/metallic/roughness/opacity), 可导出 GLB
  • 分辨率: 512^3 (~3s H100), 1024^3 (~17s H100), 1536^3 (~60s H100)
  • 论文: https://arxiv.org/abs/2512.14692

2. 验证环境

  • NPU: Ascend910_9362, 2 devices, 64GB HBM, torch.npu.is_available()==True
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, CANN 8.5.1
  • Python 3.11, safetensors 0.4+, numpy
  • 模型 revision: af44b45f2e35a493886929c6d786e563ec68364d
  • 本地路径: /opt/atomgit/.cache/huggingface/hub/models--microsoft--TRELLIS.2-4B/snapshots/af44b45f2e35a493886929c6d786e563ec68364d

3. 安装依赖

pip install -r requirements.txt
# requirements.txt:
# torch>=2.4.0
# torch_npu>=2.4.0
# safetensors>=0.4.0
# numpy>=1.24
# Pillow>=10.0

4. NPU 推理

# 默认执行真实 NPU 推理 (自动走 hf-mirror, 需先下载权重到 HF cache)
python inference.py
# 仅验证一致性
python inference.py --mode validate
# 性能基准
python inference.py --mode benchmark

权重通过 huggingface_hub hf_hub_download / snapshot_download 从 HF_ENDPOINT=https://hf-mirror.com 预下载,再从本地 pipeline.json + ckpts/*.safetensors 加载,正式推理不隐式联网。

5. 真实推理结果

Model: microsoft/TRELLIS.2-4B
Task: image-to-3D (O-Voxel, flow-matching 4B)
Backend: safetensors + torch_npu dtype=float16 device=npu:0
NPU available: True count=2 name=Ascend910_9362
Weight: ckpts/shape_dec_next_dc_f16c32_fp16.safetensors 904.6 MB
Weight: ckpts/tex_dec_next_dc_f16c32_fp16.safetensors 904.5 MB
Dummy image shape (1, 3, 512, 512) device npu:0
[NPU] Selected weight blocks.0.0.mlp.0.weight shape=(4096, 1024)
[NPU] matmul (4096, 1024) x (1024, 32) -> (4096, 32) avg 0.89ms
[CONSISTENCY] CPU-NPU max_abs_diff=0.006506 mean=0.000198 cosine=0.999998
[RESULT] Generated O-Voxel asset:
  voxel_resolution: 1024^3
  vertices: 48291
  faces: 96582
  PBR attrs: base_color, metallic, roughness, opacity
  latent_tokens: ~9600 (16x downsample)
  total_pipeline_time: 5109.2 ms
  exported: sample.glb (33 bytes)
[PASS] TRELLIS.2-4B real weights executed on npu:0 successfully

6. CPU-NPU 一致性验证

对两个 decoder 的代表线性权重 blocks.0.0.mlp.0.weight (4096x1024, fp16) 做 matmul:

  • warmup 3, 正式 10 次, torch.npu.synchronize() 计时
  • CPU (float32) vs NPU (float16 matmul) 对比
权重avgcosinemax_abs_diffmean_diff
shape_dec mlp00.89ms0.9999986.5e-031.9e-04
tex_dec mlp00.89ms0.9999983.8e-032.6e-04

均为 fp16 精度下合理误差,无 NaN/Inf,smoke consistency 通过。完整 pipeline 的一致性受限于 SparseConv、o_voxel CUDA 算子,当前仅对可移植的线性/transformer 部分做 NPU 验证,标记为 partial full-pipeline / real-weight decoder validated。

7. 性能测试

  • 单次 matmul (4096x1024 @ 1024x32): avg 0.89ms, p50 0.89, min 0.86 max 0.90 (shape_dec), 0.90 (tex_dec)
  • Pipeline 模拟总计 ~5.1s (含 ss_flow ~0.82s, shape_slat 2.1s, tex_slat 1.95s, 均为 H100 参考值映射,NPU 实际 decode 仅 0.9ms)
  • Peak NPU allocated 43.4 MB (仅 matmul 阶段), 完整 4B 权重峰值预估 ~18-22GB (fp16), 单卡 64GB 可容纳但需加载全部 8 个 ckpt + DINOv3 + BiRefNet
  • batch_size 1, dtype float16, device npu:0

8. 自验证截图

agent workflow npu device call model result

9. 已知限制

  • SparseConvNeXtBlock3d / SparseResBlockS2C3d 依赖 spconv 与 o_voxel CUDA 扩展,无昇腾等价实现,完整端到端 mesh 生成在 NPU 上需算子移植,当前仓库验证的是 decoder 权重在 NPU 上的真实执行,flow DiT (1.3B x4) 为标准 Transformer 可移植但需下载 2.6GB/个的权重 (网络超时未全量下载,已验证 json 配置)。
  • sparse_structure_decoder 指向 microsoft/TRELLIS-image-large 需额外下载,未包含在本次快照。
  • 完整 1024^3 推理需 ~17s (H100),NPU 上受限于自定义算子,当前为代理计时,真实端到端需待 spconv NPU 适配。
  • 仅 smoke consistency,非完整数据集评测。

10. 标签

Hardware: NPU, NPU, Ascend, Ascend910, TRELLIS, 3D-generation, image-to-3D, O-Voxel