Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

Structured 3D Latents
for Scalable and Versatile 3D Generation

arXivProject 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

  • High Quality: It produces diverse 3D assets at high quality with intricate shape and texture details.
  • Versatility: It takes text or image prompts and can generate various final 3D representations including but not limited to Radiance Fields, 3D Gaussians, and meshes, accommodating diverse downstream requirements.
  • Flexible Editing: It allows for easy editings of generated 3D assets, such as generating variants of the same object or local editing of the 3D asset.

⏩ Updates

03/25/2025

  • Release training code.
  • Release TRELLIS-text models and asset variants generation.
    • Examples are provided as example_text.py and example_variant.py.
    • Gradio demo is provided as app_text.py.
    • Note: It is always recommended to do text to 3D generation by first generating images using text-to-image models and then using TRELLIS-image models for 3D generation. Text-conditioned models are less creative and detailed due to data limitations.

12/26/2024

  • Release TRELLIS-500K dataset and toolkits for data preparation.

12/18/2024

  • Implementation of multi-image conditioning for TRELLIS-image model. (#7). This is based on tuning-free algorithm without training a specialized model, so it may not give the best results for all input images.
  • Add Gaussian export in app.py and example.py. (#40)

📦 Installation

Prerequisites

  • System: The code is currently tested only on Linux. For windows setup, you may refer to #3 (not fully tested).
  • Hardware: An NVIDIA GPU with at least 16GB of memory is necessary. The code has been verified on NVIDIA A100 and A6000 GPUs.
  • Software:
    • The CUDA Toolkit is needed to compile certain submodules. The code has been tested with CUDA versions 11.8 and 12.2.
    • Conda is recommended for managing dependencies.
    • Python version 3.8 or higher is required.

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:

ModelDescription#ParamsDownload
TRELLIS-image-largeLarge image-to-3D model1.2BDownload
TRELLIS-text-baseBase text-to-3D model342MDownload
TRELLIS-text-largeLarge text-to-3D model1.1BDownload
TRELLIS-text-xlargeExtra-large text-to-3D model2.0BDownload

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.

importos# 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.importimageiofromPILimportImagefromtrellis.pipelinesimportTrellisImageTo3DPipelinefromtrellis.utilsimportrender_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 imageimage=Image.open("assets/example_image/T.png")
# Run the pipelineoutputs=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 outputsvideo=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 outputsglb=postprocessing_utils.to_glb(
outputs['gaussian'][0],
outputs['mesh'][0],
# Optional parameterssimplify=0.95, # Ratio of triangles to remove in the simplification processtexture_size=1024, # Size of the texture used for the GLB
)
glb.export("sample.glb")
# Save Gaussians as PLY filesoutputs['gaussian'][0].save_ply("sample.ply")

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

  • sample_gs.mp4: a video showing the 3D Gaussian representation
  • sample_rf.mp4: a video showing the Radiance Field representation
  • sample_mesh.mp4: a video showing the mesh representation
  • sample.glb: a GLB file containing the extracted textured mesh
  • sample.ply: a PLY file containing the 3D Gaussian representation

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

  • train.py: Main entry point for training.
  • trellis/datasets: Dataset loading and preprocessing.
  • trellis/models: Different models and their components.
  • trellis/modules: Custom modules for various models.
  • trellis/pipelines: Inference pipelines for different models.
  • trellis/renderers: Renderers for different 3D representations.
  • trellis/representations: Different 3D representations.
  • trellis/trainers: Training logic for different models.
  • trellis/utils: Utility functions for training and visualization.

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:
ConfigPretained ModelDescription
vae/ss_vae_conv3d_16l8_fp16.jsonEncoderDecoderSparse structure VAE
vae/slat_vae_enc_dec_gs_swin8_B_64l8_fp16.jsonEncoderDecoderSLat VAE with Gaussian Decoder
vae/slat_vae_dec_rf_swin8_B_64l8_fp16.jsonDecoderSLat Radiance Field Decoder
vae/slat_vae_dec_mesh_swin8_B_64l8_fp16.jsonDecoderSLat Mesh Decoder
generation/ss_flow_img_dit_L_16l8_fp16.jsonDenoiserImage conditioned sparse structure Flow Model
generation/slat_flow_img_dit_L_64l8p2_fp16.jsonDenoiserImage conditioned SLat Flow Model
generation/ss_flow_txt_dit_B_16l8_fp16.jsonDenoiserBase text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_B_64l8p2_fp16.jsonDenoiserBase text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_L_16l8_fp16.jsonDenoiserLarge text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_L_64l8p2_fp16.jsonDenoiserLarge text-conditioned SLat Flow Model
generation/ss_flow_txt_dit_XL_16l8_fp16.jsonDenoiserExtra-large text-conditioned sparse structure Flow Model
generation/slat_flow_txt_dit_XL_64l8p2_fp16.jsonDenoiserExtra-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 \
--data_dir /path/to/your/dataset1,/path/to/your/dataset2 \
--load_dir /path/to/your/checkpoint \
--ckpt [step]

Additional Options

  • Auto Retry: Use the --auto_retry flag to specify the number of retries in case of intermittent errors.
  • Dry Run: The --tryrun flag allows you to check your configuration and environment without launching full training.
  • Profiling: Enable profiling with the --profile flag to gain insights into training performance and diagnose bottlenecks.

Adjust the file paths and parameters to match your experimental setup.

⚖️ License

TRELLIS models and the majority of the code are licensed under the MIT License. The following submodules may have different licenses:

📜 Citation

If you find this work helpful, please consider citing our paper:

@article{xiang2024structured,
title = {Structured 3D Latents for Scalable and Versatile 3D Generation},
author = {Xiang, Jianfeng and Lv, Zelong and Xu, Sicheng and Deng, Yu and Wang, Ruicheng and Zhang, Bowen and Chen, Dong and Tong, Xin and Yang, Jiaolong},
journal = {arXiv preprint arXiv:2412.01506},
year = {2024}
}

About

Official repo for paper "Structured 3D Latents for Scalable and Versatile 3D Generation" (CVPR'25 Spotlight).

Topics

Resources

Code of conduct

Security policy

Stars

13.6k stars

Watchers

140 watching

Forks

Used by

Contributors

Languages