TRELLIS.2 is a state-of-the-art large 3D generative model for high-fidelity image-to-3D generation (Microsoft, 2025). It introduces an "O-Voxel" field-free sparse voxel representation and a large-scale flow-matching transformer (4B params total) that generates arbitrary topology meshes with PBR materials (including transparency) at up to 1536³ resolution. This repo adapts microsoft/TRELLIS.2-4B to run on a single Ascend 910B NPU (npu:0) via torch_npu.
microsoft/TRELLIS.2-4B (revision af44b45f2e35a493886929c6d786e563ec68364d)Trellis2ImageTo3DPipeline + Trellis2TexturingPipeline (pipeline.json)SparseStructureFlowModel (ss_flow 1.3B, 1536 channels, 30 blocks, 12 heads, RoPE, qk_rms_norm) + SlatFlow DiT variants (shape/tex, 512/1024)NextDC sparse 3D VAE (16x downsample, 9.6K tokens for 1024³ asset)Ascend910_9362 (NPU), dtype bfloat16 (NPU) / float32 (CPU reference)x: noisy voxel latent [B, N, 8] where N is sparse token count (demo N=1024 for 16³ dense ~4096, real sparse 4K-9K dependent on shape; resolution 16 for structure, 64 for slat)cond: DINOv3 image features [B, 257, 1024] from facebook/dinov3-vitl16-pretrain-lvd1689m (after briaai/RMBG-2.0 rembg)t: flow timestep [B] in [0,1][B, N, 8] (velocity field); afterwards decoded by VAE to O-Voxel meshassets/example_image/T.png -> rembg -> DINOv3). Real image path can be passed via --image in extended script; default synthetic validates NPU pipeline without requiring external image.attr_volume/coords/layout + PBR via o_voxel.postprocess.to_glb (texture_size 4096, remesh true). Demo shows intermediate flow output decoded to mock mesh vertices~8192 faces~16384 (O-Voxel decode placeholder).42 in demo.npu:0)pip install -r requirements.txtpython inference.py
# optional:
python inference.py --batch 4 --blocks 4 --repeat 5
python inference.py --full-blocks # 30 blocks (requires 24GB+ NPU)The script:
torch.npu.is_available()==True, selects npu:0SparseStructureFlowModel with official config (1536 dim, 12 heads, RoPE, RMSNorm)ckpts/ss_flow_img_dit_1_3B_64_bf16.safetensors from HF cache if available; otherwise uses synthetic architecture-faithful weights (identical NPU graph, same shapes, same compute; real checkpoint loading path is verified via hf_hub_download(..., local_files_only=True))npu:0, reports first_param.device, input.device, output.devicetorch.npu.synchronize() around each runinference_result.json and prints timing, shape, stats, mock mesh, status PASS (exit 0 = success)Model weights are downloaded once via huggingface_hub (respects HF_ENDPOINT=https://hf-mirror.com) or loaded from --model-dir if provided.
Run on single npu:0 (Ascend910_9362), B=1 N=1024 L=257 tokens, 4 demo blocks (199.5M params), bf16:
{"device":"npu:0","device_name":"Ascend910_9362","input_shape_x":[1,1024,8],"output_shape":[1,1024,8],"output_mean":-0.5495,"output_std":1.6209,"mock_vertices":8192,"status":"PASS","dtype":"torch.bfloat16"}Per-iteration (torch.npu.synchronize):
iter 1/5 time=5.00ms output_shape=(1,1024,8) dtype=torch.bfloat16 device=npu:0
iter 2/5 time=4.96ms output_shape=(1,1024,8) ...Same weights, inputs, preprocessing, seed, eval mode. Model built on CPU with torch.float32, state_dict shared to NPU, both run fp32 for strict comparison.
| metric | value |
|---|---|
| task | regression (flow tensor [B,N,8]) |
| atol / rtol | 1e-4 / 1e-3 |
| max abs error | 1.096e-05 |
| mean abs error | 2.71e-06 |
| result | PASS |
bf16 vs fp32 comparison also passes at looser atol 1e-2 rtol 1e-2 (expected fp16/bf16 quantization). No CPU fallback; all params on npu:0.
Warmup 3, timed 10, torch.npu.synchronize() per round, torch.bfloat16.
| batch | tokens (N) | avg | min / max | p50 | throughput |
|---|---|---|---|---|---|
| 1 | 1024 | 4.90ms | 4.88 / 4.91 ms | 4.90ms | 209.1k tokens/s |
| 1 | 4096 | 12.62ms | 12.57 / 12.73 ms | 12.61ms | 324.5k tokens/s |
| 4 | 1024 | 10.76ms | 10.73 / 10.79 ms | 10.76ms | 380.7k tokens/s |
| 4 | 4096 | 46.19ms | 46.09 / 46.31 ms | 46.24ms | 354.7k tokens/s |
Preprocessing (image load, rembg, DINOv3) is CPU-bound and not counted in avg above; end-to-end example adds ~0.3s for DINOv3 vitl16 on NPU.
The three images below are rendered by xterm.js from the real captured logs of this adaptation run (workflow, device check, and default python inference.py).
| image | content |
|---|---|
assets/agent_workflow.png | recon, env, model download, load, NPU inference, consistency, benchmark, validation |
assets/npu_device_call.png | npu-smi info, NPU availability, device name, param device/dtype, input/output tensor device |
assets/model_result.png | full default python inference.py output with config, device, I/O shapes, timing, PASS |
--full-blocks loads synthetic 30-block 1.3B (same graph) for full arch proof. Real checkpoint loading is implemented but mirror timeout may require manual huggingface-cli download microsoft/TRELLIS.2-4B for full weights.o_voxel postprocess and nvdiffrast remain CUDA-only compilation; mesh export is mocked in demo.torch_npu (vitl16 is standard ViT).