TRELLIS README

The project's README from github.com/microsoft/TRELLIS. As one markdown file: README.md.

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXiv Project Page

TRELLIS is a large 3D asset generation model. It takes in text or image prompts and generates high-quality 3D assets in various formats, such as Radiance Fields, 3D Gaussians, and meshes. The cornerstone of TRELLIS is a unified Structured LATent (SLAT) representation that allows decoding to different output formats and Rectified Flow Transformers tailored for SLAT as the powerful backbones. We provide large-scale pre-trained models with up to 2 billion parameters on a large 3D asset dataset of 500K diverse objects. TRELLIS significantly surpasses existing methods, including recent ones at similar scales, and showcases flexible output format selection and local 3D editing capabilities which were not offered by previous models.

Check out our Project Page for more videos and interactive demos!

🌟 Features

⏩ Updates

03/25/2025

12/26/2024

12/18/2024

📦 Installation

Prerequisites

Installation Steps

  1. Clone the repo:

    git clone --recurse-submodules https://github.com/microsoft/TRELLIS.git
    cd TRELLIS
    
  2. Install the dependencies:

    Before running the following command there are somethings to note:

    • By adding --new-env, a new conda environment named trellis will be created. If you want to use an existing conda environment, please remove this flag.
    • By default the trellis environment will use pytorch 2.4.0 with CUDA 11.8. If you want to use a different version of CUDA (e.g., if you have CUDA Toolkit 12.2 installed and do not want to install another 11.8 version for submodule compilation), you can remove the --new-env flag and manually install the required dependencies. Refer to PyTorch for the installation command.
    • If you have multiple CUDA Toolkit versions installed, PATH should be set to the correct version before running the command. For example, if you have CUDA Toolkit 11.8 and 12.2 installed, you should run export PATH=/usr/local/cuda-11.8/bin:$PATH before running the command.
    • By default, the code uses the flash-attn backend for attention. For GPUs do not support flash-attn (e.g., NVIDIA V100), you can remove the --flash-attn flag to install xformers only and set the ATTN_BACKEND environment variable to xformers before running the code. See the Minimal Example for more details.
    • The installation may take a while due to the large number of dependencies. Please be patient. If you encounter any issues, you can try to install the dependencies one by one, specifying one flag at a time.
    • If you encounter any issues during the installation, feel free to open an issue or contact us.

    Create a new conda environment named trellis and install the dependencies:

    . ./setup.sh --new-env --basic --xformers --flash-attn --diffoctreerast --spconv --mipgaussian --kaolin --nvdiffrast
    

    The detailed usage of setup.sh can be found by running . ./setup.sh --help.

    Usage: setup.sh [OPTIONS]
    Options:
        -h, --help              Display this help message
        --new-env               Create a new conda environment
        --basic                 Install basic dependencies
        --train                 Install training dependencies
        --xformers              Install xformers
        --flash-attn            Install flash-attn
        --diffoctreerast        Install diffoctreerast
        --spconv                Install spconv
        --mipgaussian           Install mip-splatting
        --kaolin                Install kaolin
        --nvdiffrast            Install nvdiffrast
        --demo                  Install all dependencies for demo
    

🤖 Pretrained Models

We provide the following pretrained models:

Model Description #Params Download
TRELLIS-image-large Large image-to-3D model 1.2B Download
TRELLIS-text-base Base text-to-3D model 342M Download
TRELLIS-text-large Large text-to-3D model 1.1B Download
TRELLIS-text-xlarge Extra-large text-to-3D model 2.0B Download

Note: It is always recommended to use the image conditioned version of the models for better performance.

Note: All VAEs are included in TRELLIS-image-large model repo.

The models are hosted on Hugging Face. You can directly load the models with their repository names in the code:

TrellisImageTo3DPipeline.from_pretrained("microsoft/TRELLIS-image-large")

If you prefer loading the model from local, you can download the model files from the links above and load the model with the folder path (folder structure should be maintained):

TrellisImageTo3DPipeline.from_pretrained("/path/to/TRELLIS-image-large")

💡 Usage

Minimal Example

Here is an example of how to use the pretrained models for 3D asset generation.

import os
# os.environ['ATTN_BACKEND'] = 'xformers'   # Can be 'flash-attn' or 'xformers', default is 'flash-attn'
os.environ['SPCONV_ALGO'] = 'native'        # Can be 'native' or 'auto', default is 'auto'.
                                            # 'auto' is faster but will do benchmarking at the beginning.
                                            # Recommended to set to 'native' if run only once.

import imageio
from PIL import Image
from trellis.pipelines import TrellisImageTo3DPipeline
from trellis.utils import render_utils, postprocessing_utils

# Load a pipeline from a model folder or a Hugging Face model hub.
pipeline = TrellisImageTo3DPipeline.from_pretrained("microsoft/TRELLIS-image-large")
pipeline.cuda()

# Load an image
image = Image.open("assets/example_image/T.png")

# Run the pipeline
outputs = pipeline.run(
    image,
    seed=1,
    # Optional parameters
    # sparse_structure_sampler_params={
    #     "steps": 12,
    #     "cfg_strength": 7.5,
    # },
    # slat_sampler_params={
    #     "steps": 12,
    #     "cfg_strength": 3,
    # },
)
# outputs is a dictionary containing generated 3D assets in different formats:
# - outputs['gaussian']: a list of 3D Gaussians
# - outputs['radiance_field']: a list of radiance fields
# - outputs['mesh']: a list of meshes

# Render the outputs
video = render_utils.render_video(outputs['gaussian'][0])['color']
imageio.mimsave("sample_gs.mp4", video, fps=30)
video = render_utils.render_video(outputs['radiance_field'][0])['color']
imageio.mimsave("sample_rf.mp4", video, fps=30)
video = render_utils.render_video(outputs['mesh'][0])['normal']
imageio.mimsave("sample_mesh.mp4", video, fps=30)

# GLB files can be extracted from the outputs
glb = postprocessing_utils.to_glb(
    outputs['gaussian'][0],
    outputs['mesh'][0],
    # Optional parameters
    simplify=0.95,          # Ratio of triangles to remove in the simplification process
    texture_size=1024,      # Size of the texture used for the GLB
)
glb.export("sample.glb")

# Save Gaussians as PLY files
outputs['gaussian'][0].save_ply("sample.ply")

After running the code, you will get the following files:

Web Demo

app.py provides a simple web demo for 3D asset generation. Since this demo is based on Gradio, additional dependencies are required:

. ./setup.sh --demo

After installing the dependencies, you can run the demo with the following command:

python app.py

Then, you can access the demo at the address shown in the terminal.

📚 Dataset

We provide TRELLIS-500K, a large-scale dataset containing 500K 3D assets curated from Objaverse(XL), ABO, 3D-FUTURE, HSSD, and Toys4k, filtered based on aesthetic scores. Please refer to the dataset README for more details.

🏋️‍♂️ Training

TRELLIS’s training framework is organized to provide a flexible and modular approach to building and fine-tuning large-scale 3D generation models. The training code is centered around train.py and is structured into several directories to clearly separate dataset handling, model components, training logic, and visualization utilities.

Code Structure

Training Setup

  1. Prepare the Environment:

    • Ensure all training dependencies are installed.
    • Use a Linux system with an NVIDIA GPU (The models are trained on NVIDIA A100 GPUs).
    • For distributed training, verify that your nodes can communicate through the designated master address and port.
  2. Dataset Preparation:

    • Organize your dataset similar to TRELLIS-500K. Specify your dataset path using the --data_dir argument when launching training.
  3. Configuration Files:

    • Training hyperparameters and model architectures are defined in configuration files under the configs/ directory.
    • Example configuration files include:
Config Pretained Model Description
vae/ss_vae_conv3d_16l8_fp16.json Encoder Decoder Sparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.json Encoder Decoder SLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.json Decoder SLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.json Decoder SLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.json Denoiser Image conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.json Denoiser Image conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.json Denoiser Base text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.json Denoiser Base text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.json Denoiser Large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.json Denoiser Large text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.json Denoiser Extra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.json Denoiser Extra-large text-conditioned SLat Flow Model

Command-Line Options

The training script can be run as follows:

usage: train.py [-h] --config CONFIG --output_dir OUTPUT_DIR [--load_dir LOAD_DIR] [--ckpt CKPT] [--data_dir DATA_DIR] [--auto_retry AUTO_RETRY] [--tryrun] [--profile] [--num_nodes NUM_NODES] [--node_rank NODE_RANK] [--num_gpus NUM_GPUS] [--master_addr MASTER_ADDR] [--master_port MASTER_PORT]

options:
  -h, --help                    show this help message and exit
  --config CONFIG               Experiment config file
  --output_dir OUTPUT_DIR       Output directory
  --load_dir LOAD_DIR           Load directory, default to output_dir
  --ckpt CKPT                   Checkpoint step to resume training, default to latest
  --data_dir DATA_DIR           Data directory
  --auto_retry AUTO_RETRY       Number of retries on error
  --tryrun                      Try run without training
  --profile                     Profile training
  --num_nodes NUM_NODES         Number of nodes
  --node_rank NODE_RANK         Node rank
  --num_gpus NUM_GPUS           Number of GPUs per node, default to all
  --master_addr MASTER_ADDR     Master address for distributed training
  --master_port MASTER_PORT     Port for distributed training

Example Training Commands

Single-node Training

To train a image-to-3D stage 2 model with a single machine.

python train.py \
  --config configs/vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.json \
  --output_dir outputs/slat_vae_dec_mesh_swin8_B_64l8_fp16_1node \
  --data_dir /path/to/your/dataset1,/path/to/your/dataset2 \

The script will automatically distribute the training across all available GPUs. Specify the number of GPUs with the --num_gpus flag if you want to limit the number of GPUs used.

Multi-node Training

To train a image-to-3D stage 2 model with multiple GPUs across nodes (e.g., 2 nodes):

python train.py \
  --config configs/generation/slat_flow_img_dit_L_64l8p2_fp16.json \
  --output_dir outputs/slat_flow_img_dit_L_64l8p2_fp16_2nodes \
  --data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
  --num_nodes 2 \
  --node_rank 0 \
  --master_addr $MASTER_ADDR \
  --master_port $MASTER_PORT

Be sure to adjust node_rank, master_addr, and master_port for each node accordingly.

Resuming Training

By default, training will resume from the latest saved checkpoint in the same output directory. To specify a specific checkpoint to resume from, use the --load_dir and --ckpt flags:

python train.py \
  --config configs/generation/slat_flow_img_dit_L_64l8p2_fp16.json \
  --output_dir outputs/slat_flow_img_dit_L_64l8p2_fp16_resume \

TRELLIS (microsoft/TRELLIS)

Searching Database…

这是做什么的?微软的大规模 3D 资产生成模型:输入一段文字或一张图片作为提示,它就能生成高质量的 3D 资产,输出形式可以是辐射场(Radiance Fields)、3D 高斯(3D Gaussians)或网格(mesh)。这是 CVPR'25 Spotlight 论文的官方代码。
它是一个 Python 库、现成的应用,还是在线服务?这是一个带预训练模型权重的 Python 研究代码库:你可以运行示例脚本,在自己的代码里调用它的 pipeline,或者使用 Gradio 网页演示(app.py)。它没有托管在网上的服务。
我怎么把它跑起来?克隆仓库,然后运行 . ./setup.sh --new-env —— 默认会创建一个名为 'trellis' 的 conda 环境,包含 PyTorch 2.4.0 + CUDA 11.8。之后,模型可以直接按名称从 Hugging Face 加载,比如 TRELLIS-image-large。
我需要先准备好哪些软件?需要 CUDA Toolkit(在 11.8 和 12.2 上测试过)来编译子模块,需要 Conda 来管理依赖,还需要 Python 3.8 或更高版本。安装包很大,可能要等不少时间。
它能在 Windows 上运行吗,还是只支持 Linux?官方只在 Linux 上测试过;issue #3 里描述了 Windows 的安装方法,但没有经过完整测试。macOS 完全没有提及——反正它硬性要求 NVIDIA 显卡,macOS 本来就不可能支持。
生成是在云端进行,还是在我自己的电脑上进行?在你自己的电脑上:推理在你的 GPU 上运行,权重可以按仓库名称从 Hugging Face 加载,也可以从已下载的本地文件夹加载。全程不涉及任何云端 API 或账号。
我的显卡带得动它吗?你需要一块显存至少 16GB 的 NVIDIA 显卡——已在 A100 和 A6000 上验证过。对于不支持 flash-attn 的显卡(比如 V100),请改用 xformers 安装,并设置 ATTNBACKEND=xformers。
我实际能得到什么结果?最简示例会把一个带纹理的网格保存为 sample.glb,把一个 3D 高斯表示保存为 sample.ply,并为每种格式(高斯、辐射场、网格)生成预览视频。
我能编辑它生成的 3D 资产吗?可以——灵活编辑是它的招牌功能:它能生成同一个物体的多个变体,还能对 3D 资产进行局部编辑。example_variant.py 展示了资产生成变体的功能,于 2025 年 3 月发布。
有哪些预训练模型,我该选哪一个?共有四个:TRELLIS-image-large(1.2B),以及 base(342M)、large(1.1B)和 xlarge(2.0B)三种规格的文本模型。选图像模型——README 建议先用文生图模型生成一张图片,因为受数据限制,文本条件模型的创造力和细节表现都较差。
SLAT 是什么?这是论文的核心思想:一种统一的结构化潜变量表示(Structured LATent,即 SLAT),让同一个模型能够解码成不同的输出格式,骨干网络采用 Rectified Flow Transformers。预训练模型参数量最大达 2B,训练数据是 50 万个多样的 3D 物体。
Creator
microsoft
Size
1.1 GB
Stars
14K
Updated
CommitNov 05
Age
1y
Commits · 90 Days