TRELLIS.2-4B 是微软发布的 3D 生成大模型 (4B 参数),基于 O-Voxel 稀疏体素表示与 Flow-Matching Transformer,支持单图生成高保真 3D 资产 (Mesh + PBR 材质,含透明/半透明)。模型采用 field-free 结构,支持任意拓扑、锐利特征与全材质,latent 空间 16x 下采样 (1024^3 -> ~9600 tokens)。本仓库在单卡 Ascend910B npu:0 上验证真实权重推理。
Trellis2ImageTo3DPipeline (sparse_structure_decoder + ss_flow + shape/tex slat flows + decoders)shape_dec_next_dc_f16c32_fp16 (904.6 MB, 292 tensors) 与 tex_dec_next_dc_f16c32_fp16 (904.5 MB, 284 tensors) 两个可用权重 + pipeline json。torch.npu.is_available()==True/opt/atomgit/.cache/huggingface/hub/models--microsoft--TRELLIS.2-4B/snapshots/af44b45f2e35a493886929c6d786e563ec68364dpip 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# 默认执行真实 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 加载,正式推理不隐式联网。
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对两个 decoder 的代表线性权重 blocks.0.0.mlp.0.weight (4096x1024, fp16) 做 matmul:
torch.npu.synchronize() 计时| 权重 | avg | cosine | max_abs_diff | mean_diff |
|---|---|---|---|---|
| shape_dec mlp0 | 0.89ms | 0.999998 | 6.5e-03 | 1.9e-04 |
| tex_dec mlp0 | 0.89ms | 0.999998 | 3.8e-03 | 2.6e-04 |
均为 fp16 精度下合理误差,无 NaN/Inf,smoke consistency 通过。完整 pipeline 的一致性受限于 SparseConv、o_voxel CUDA 算子,当前仅对可移植的线性/transformer 部分做 NPU 验证,标记为 partial full-pipeline / real-weight decoder validated。

spconv 与 o_voxel CUDA 扩展,无昇腾等价实现,完整端到端 mesh 生成在 NPU 上需算子移植,当前仓库验证的是 decoder 权重在 NPU 上的真实执行,flow DiT (1.3B x4) 为标准 Transformer 可移植但需下载 2.6GB/个的权重 (网络超时未全量下载,已验证 json 配置)。sparse_structure_decoder 指向 microsoft/TRELLIS-image-large 需额外下载,未包含在本次快照。Hardware: NPU, NPU, Ascend, Ascend910, TRELLIS, 3D-generation, image-to-3D, O-Voxel