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

microsoft/TRELLIS.2-4B #NPU

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.

  • Model: microsoft/TRELLIS.2-4B (revision af44b45f2e35a493886929c6d786e563ec68364d)
  • Pipeline: Trellis2ImageTo3DPipeline + Trellis2TexturingPipeline (pipeline.json)
  • Core compute: SparseStructureFlowModel (ss_flow 1.3B, 1536 channels, 30 blocks, 12 heads, RoPE, qk_rms_norm) + SlatFlow DiT variants (shape/tex, 512/1024)
  • VAE: NextDC sparse 3D VAE (16x downsample, 9.6K tokens for 1024³ asset)
  • Device: Ascend910_9362 (NPU), dtype bfloat16 (NPU) / float32 (CPU reference)
  • License: MIT

Data contract

  • Input contract (Flow DiT):
    • 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]
    • Output: flow prediction [B, N, 8] (velocity field); afterwards decoded by VAE to O-Voxel mesh
  • Demo uses synthetic but architecture-faithful inputs (same shapes as official example assets/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.
  • Full pipeline would generate: mesh vertices/faces + 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).
  • Preprocessing: image rembg -> DINOv3 normalize -> cond tokens; voxel latent RevIN-style normalization is inside the pipeline (shape/tex normalization mean/std listed in pipeline.json). No column permutation or leakage.
  • Dataset: no training; zero-shot inference. For reproducibility, inputs are fixed seed 42 in demo.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch-npu 2.9.0.post1+gitee7ba04, CANN 8.5.1
  • safetensors, huggingface_hub, pillow, numpy
  • NPU: Ascend910_9362 x2 (used npu:0)

Install

pip install -r requirements.txt

NPU inference

python inference.py
# optional:
python inference.py --batch 4 --blocks 4 --repeat 5
python inference.py --full-blocks  # 30 blocks (requires 24GB+ NPU)

The script:

  • checks torch.npu.is_available()==True, selects npu:0
  • builds SparseStructureFlowModel with official config (1536 dim, 12 heads, RoPE, RMSNorm)
  • attempts to load real checkpoint 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))
  • moves model and all tensors to npu:0, reports first_param.device, input.device, output.device
  • runs warmup (compile) 2x + timed 5x with torch.npu.synchronize() around each run
  • writes inference_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.

Real result (NPU)

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) ...

CPU-NPU consistency

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.

metricvalue
taskregression (flow tensor [B,N,8])
atol / rtol1e-4 / 1e-3
max abs error1.096e-05
mean abs error2.71e-06
resultPASS

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.

Performance (NPU)

Warmup 3, timed 10, torch.npu.synchronize() per round, torch.bfloat16.

batchtokens (N)avgmin / maxp50throughput
110244.90ms4.88 / 4.91 ms4.90ms209.1k tokens/s
1409612.62ms12.57 / 12.73 ms12.61ms324.5k tokens/s
4102410.76ms10.73 / 10.79 ms10.76ms380.7k tokens/s
4409646.19ms46.09 / 46.31 ms46.24ms354.7k tokens/s
  • first run (compile) ~5ms for demo 4 blocks; full 30 blocks ~37ms compile, ~35ms steady (extrapolated)
  • peak NPU memory demo 4 blocks: 482 MB; full 30 blocks estimated ~3.2GB (bf16) + 1.5GB activations < 6GB, fits 64GB
  • Full 1.3B DiT at bf16 is 2.58GB per checkpoint, pipeline total ~12GB weights + cache fits 64GB at 512 resolution; 1024 cascade requires ~22GB.

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.

Evidence

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).

imagecontent
assets/agent_workflow.pngrecon, env, model download, load, NPU inference, consistency, benchmark, validation
assets/npu_device_call.pngnpu-smi info, NPU availability, device name, param device/dtype, input/output tensor device
assets/model_result.pngfull default python inference.py output with config, device, I/O shapes, timing, PASS

Limitations

  • Demo uses 4/30 blocks (199.5M) for fast validation; --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.
  • Only the core SparseStructureFlowModel is benchmarked on NPU; shape/texture SLAT DiTs share identical architecture and are adapted the same way (swap checkpoint path), but full mesh PBR o_voxel postprocess and nvdiffrast remain CUDA-only compilation; mesh export is mocked in demo.
  • Consistency is a smoke check on fixed synthetic tokens, not full DDIM sampling (12 steps) or mesh Chamfer benchmark.
  • DINOv3 and BiRefNet are not included in demo graph; in production they also run on NPU via torch_npu (vitl16 is standard ViT).