Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build_cumesh.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
set TORCH_CUDA_ARCH_LIST=12.0
set CUDA_HOME=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8
set EXT_DIR=%TEMP%\trellis2_extensions
mkdir "%EXT_DIR%" 2>nul
if not exist "%EXT_DIR%\CuMesh" (
git clone https://github.com/JeffreyXiang/CuMesh.git "%EXT_DIR%\CuMesh" --recursive
)
C:\workspace\MODEL\TRELLIS.2\.venv\Scripts\pip install "%EXT_DIR%\CuMesh" --no-build-isolation --force-reinstall
5 changes: 5 additions & 0 deletions build_flexgemm.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
set TORCH_CUDA_ARCH_LIST=12.0
C:\workspace\MODEL\TRELLIS.2\.venv\Scripts\pip.exe install C:\Users\kschmid\AppData\Local\Temp\trellis2_extensions\FlexGEMM --no-build-isolation --force-reinstall --no-deps > C:\workspace\flexgemm_build.log 2>&1
echo Exit code: %ERRORLEVEL% >> C:\workspace\flexgemm_build.log
5 changes: 5 additions & 0 deletions build_nvdiffrast.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
set TORCH_CUDA_ARCH_LIST=12.0
c:\workspace\MODEL\TRELLIS.2\.venv\Scripts\pip install --no-build-isolation --force-reinstall git+https://github.com/NVlabs/nvdiffrast.git
pause
127 changes: 127 additions & 0 deletions download_texture_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""
Download all models required for Trellis2TexturingPipeline.

Models downloaded:
microsoft/TRELLIS.2-4B
- texturing_pipeline.json
- ckpts/shape_enc_next_dc_f16c32_fp16 (~400 MB)
- ckpts/tex_dec_next_dc_f16c32_fp16 (~400 MB)
- ckpts/slat_flow_imgshape2tex_dit_1_3B_512_bf16 (~2.6 GB)
- ckpts/slat_flow_imgshape2tex_dit_1_3B_1024_bf16 (~2.6 GB)
briaai/RMBG-2.0 (background removal) (~1.0 GB)
facebook/dinov3-vitl16-pretrain-lvd1689m (~1.1 GB)

Total: ~8.1 GB
"""

import argparse
import os
from pathlib import Path

try:
from huggingface_hub import hf_hub_download, snapshot_download
except ImportError:
raise SystemExit("huggingface_hub not installed. Run: pip install huggingface_hub")

TRELLIS_REPO = "microsoft/TRELLIS.2-4B"
RMBG_REPO = "briaai/RMBG-2.0"
DINO_REPO = "facebook/dinov3-vitl16-pretrain-lvd1689m"
DINO_DIRECT_FILENAME = "dinov3_vitl16_pretrain_lvd1689m-8aa4cbdd.pth"
DINO_DIRECT_URL = (
"https://dinov3.llamameta.net/dinov3_vitl16/dinov3_vitl16_pretrain_lvd1689m-8aa4cbdd.pth"
"?Policy=eyJTdGF0ZW1lbnQiOlt7InVuaXF1ZV9oYXNoIjoiYTdwYzV6YzI3bDczbmJxcjNhZXAyYnhkIiwiUmVzb3VyY2UiOiJodHRwczpcL1wvZGlub3YzLmxsYW1hbWV0YS5uZXRcLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE3NzQ0MTgxMDl9fX1dfQ__"
"&Signature=qIEnfQZHBmwdp38IDvUjV3wkZMiNX3v9-K-YXheXCFRo97GBhwNHG-PbJkb1Fw9PECXYcklow%7EiJ%7EV3Qh8TfytTe2t%7ElcNs63kCoxmRuBB8%7ElUXD5R%7E0nKX1HqqZQzxV%7ECXUcDh6wKWX5dcEeMG39bVjOAhADvItOLCPQU-l%7ECP9NM2Nb9sXi2Eyp21gU5PNAL11ziKY2U4dRuKvjDn9EhfGS1cvftO8AFGsIOEapmWbEZ9lpWgEGFWiWbt6ajy%7EnK6NoiycLatTTNF-hFCmSiD6xavV7MfgtXHmFi8SE7Vvrv%7EwAjGuA0ZFOQnUNSCbVzyQ8Rj-S8PA1OGp28svxA__"
"&Key-Pair-Id=K15QRJLYKIFSLZ&Download-Request-ID=3857627804367069"
)

TRELLIS_TEXTURE_FILES = [
"texturing_pipeline.json",
"ckpts/shape_enc_next_dc_f16c32_fp16.json",
"ckpts/shape_enc_next_dc_f16c32_fp16.safetensors",
"ckpts/tex_dec_next_dc_f16c32_fp16.json",
"ckpts/tex_dec_next_dc_f16c32_fp16.safetensors",
"ckpts/slat_flow_imgshape2tex_dit_1_3B_512_bf16.json",
"ckpts/slat_flow_imgshape2tex_dit_1_3B_512_bf16.safetensors",
"ckpts/slat_flow_imgshape2tex_dit_1_3B_1024_bf16.json",
"ckpts/slat_flow_imgshape2tex_dit_1_3B_1024_bf16.safetensors",
]


def download_trellis(local_dir: Path, token: str = None):
print(f"\n[1/3] Downloading TRELLIS.2-4B texture models -> {local_dir}")
local_dir.mkdir(parents=True, exist_ok=True)
for filename in TRELLIS_TEXTURE_FILES:
dest = local_dir / filename
if dest.exists():
print(f" skip {filename}")
continue
print(f" fetch {filename} ...")
hf_hub_download(
repo_id=TRELLIS_REPO,
filename=filename,
local_dir=str(local_dir),
token=token,
)
print(" done.")


def download_rmbg(local_dir: Path, token: str = None):
print(f"\n[2/3] Downloading RMBG-2.0 (background removal) -> {local_dir}")
if any(local_dir.glob("*.safetensors")) or any(local_dir.glob("*.bin")):
print(" skip (already exists)")
return
snapshot_download(
repo_id=RMBG_REPO,
local_dir=str(local_dir),
token=token,
ignore_patterns=["*.md", "*.txt", "*.png", "*.jpg"],
)
print(" done.")


def download_dino(local_dir: Path, token: str = None):
print(f"\n[3/3] Downloading DINOv3-L ({DINO_DIRECT_FILENAME}) -> {local_dir}")
local_dir.mkdir(parents=True, exist_ok=True)
dest = local_dir / DINO_DIRECT_FILENAME
if dest.exists():
print(f" skip {DINO_DIRECT_FILENAME} (already exists)")
return
import urllib.request
print(f" fetch {DINO_DIRECT_FILENAME} ...")
urllib.request.urlretrieve(DINO_DIRECT_URL, str(dest))
print(" done.")


def main():
parser = argparse.ArgumentParser(description="Download TRELLIS.2 texture pipeline models")
parser.add_argument(
"--model-dir",
type=Path,
default=Path(__file__).parent / "models",
help="Root directory to save models (default: ./models)",
)
parser.add_argument(
"--token",
default=os.environ.get("HF_TOKEN"),
help="HuggingFace access token (or set HF_TOKEN env var)",
)
args = parser.parse_args()

trellis_dir = args.model_dir / "TRELLIS.2-4B"
rmbg_dir = args.model_dir / "RMBG-2.0"
dino_dir = args.model_dir / "dinov3-vitl16-pretrain-lvd1689m"

print(f"Model root : {args.model_dir.resolve()}")
print("Est. size : ~8.1 GB")

download_trellis(trellis_dir, args.token)
download_rmbg(rmbg_dir, args.token)
download_dino(dino_dir, args.token)

print("\nAll models downloaded.")
print(f"\nLoad the pipeline with:")
print(f" Trellis2TexturingPipeline.from_pretrained(r'{trellis_dir}', config_file='texturing_pipeline.json')")


if __name__ == "__main__":
main()
163 changes: 163 additions & 0 deletions setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
@echo off
setlocal EnableDelayedExpansion

:: ============================================================
:: setup.bat -- Windows equivalent of setup.sh for TRELLIS.2
:: ============================================================

set NEW_ENV=0
set BASIC=0
set FLASHATTN=0
set CUMESH=0
set OVOXEL=0
set FLEXGEMM=0
set NVDIFFRAST=0
set NVDIFFREC=0
set HELP=0

if "%~1"=="" set HELP=1

:parse_args
if "%~1"=="" goto done_args
if /i "%~1"=="-h" set HELP=1 & shift & goto parse_args
if /i "%~1"=="--help" set HELP=1 & shift & goto parse_args
if /i "%~1"=="--new-env" set NEW_ENV=1 & shift & goto parse_args
if /i "%~1"=="--basic" set BASIC=1 & shift & goto parse_args
if /i "%~1"=="--flash-attn" set FLASHATTN=1 & shift & goto parse_args
if /i "%~1"=="--cumesh" set CUMESH=1 & shift & goto parse_args
if /i "%~1"=="--o-voxel" set OVOXEL=1 & shift & goto parse_args
if /i "%~1"=="--flexgemm" set FLEXGEMM=1 & shift & goto parse_args
if /i "%~1"=="--nvdiffrast" set NVDIFFRAST=1 & shift & goto parse_args
if /i "%~1"=="--nvdiffrec" set NVDIFFREC=1 & shift & goto parse_args
if /i "%~1"=="--texture" set BASIC=1 & set FLASHATTN=1 & set OVOXEL=1 & set CUMESH=1 & set FLEXGEMM=1 & set NVDIFFRAST=1 & shift & goto parse_args
if /i "%~1"=="--all" set NEW_ENV=1 & set BASIC=1 & set FLASHATTN=1 & set CUMESH=1 & set OVOXEL=1 & set FLEXGEMM=1 & set NVDIFFRAST=1 & set NVDIFFREC=1 & shift & goto parse_args
echo Error: Invalid argument: %~1
set HELP=1
shift & goto parse_args

:done_args

if %HELP%==1 (
echo Usage: setup.bat [OPTIONS]
echo Options:
echo -h, --help Display this help message
echo --new-env Create a new venv at .venv ^(requires Python 3.10^)
echo --basic Install basic dependencies
echo --flash-attn Install flash-attention ^(CUDA only^)
echo --cumesh Install cumesh
echo --o-voxel Install o-voxel
echo --flexgemm Install flexgemm
echo --nvdiffrast Install nvdiffrast ^(CUDA only^)
echo --nvdiffrec Install nvdiffrec ^(CUDA only^)
echo --texture Install all dependencies for texturing ^(basic, flash-attn, o-voxel, cumesh, flexgemm, nvdiffrast^)
echo --all Run all of the above
goto :eof
)

:: ---- Detect GPU platform ----------------------------------------
set GPU_PLATFORM=
nvidia-smi >nul 2>&1
if %errorlevel%==0 (
set GPU_PLATFORM=cuda
) else (
rocminfo >nul 2>&1
if !errorlevel!==0 (
set GPU_PLATFORM=hip
)
)

if "%GPU_PLATFORM%"=="" (
echo Error: No supported GPU found ^(nvidia-smi and rocminfo both failed^)
exit /b 1
)
echo Detected platform: %GPU_PLATFORM%

set WORKDIR=%CD%
set EXT_DIR=%TEMP%\trellis2_extensions

:: ---- Activate MSVC environment (needed for CUDA extension builds) ----
:: NOTE: vcvarsall.bat sets PLATFORM=x64, so we use GPU_PLATFORM instead
set VCVARS="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat"
if exist %VCVARS% (
call %VCVARS% x64
) else (
echo Warning: vcvarsall.bat not found at %VCVARS%
echo CUDA extension builds ^(cumesh, flexgemm, nvdiffrast, nvdiffrec, o-voxel^) will likely fail.
echo Open a Developer Command Prompt for VS 2022 and re-run setup.bat if needed.
)

:: ---- --new-env --------------------------------------------------
if %NEW_ENV%==1 (
python -m venv "%WORKDIR%\.venv"
call "%WORKDIR%\.venv\Scripts\activate.bat"
if "%GPU_PLATFORM%"=="cuda" (
pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128 --no-build-isolation
) else if "%GPU_PLATFORM%"=="hip" (
pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/rocm6.2.4 --no-build-isolation
)
)

:: ---- --basic ----------------------------------------------------
if %BASIC%==1 (
pip install packaging wheel setuptools imageio imageio-ffmpeg tqdm easydict opencv-python-headless ninja trimesh transformers gradio==6.0.1 tensorboard pandas lpips zstandard --no-build-isolation
pip install git+https://github.com/EasternJournalist/utils3d.git@9a4eb15e4021b67b12c460c7057d642626897ec8 --no-build-isolation
:: NOTE: pillow-simd has no Windows wheel; install plain pillow instead
pip install pillow --no-build-isolation
pip install kornia timm --no-build-isolation
)

:: ---- --flash-attn -----------------------------------------------
if %FLASHATTN%==1 (
if "%GPU_PLATFORM%"=="cuda" (
pip install https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.4.10/flash_attn-2.8.2+cu128torch2.7-cp312-cp312-win_amd64.whl --no-build-isolation
) else (
echo [FLASHATTN] Unsupported platform on Windows: %PLATFORM%
)
)

:: ---- --nvdiffrast -----------------------------------------------
if %NVDIFFRAST%==1 (
if "%GPU_PLATFORM%"=="cuda" (
mkdir "%EXT_DIR%" 2>nul
git clone -b v0.4.0 https://github.com/NVlabs/nvdiffrast.git "%EXT_DIR%\nvdiffrast"
pip install "%EXT_DIR%\nvdiffrast" --no-build-isolation
) else (
echo [NVDIFFRAST] Unsupported platform: %PLATFORM%
)
)

:: ---- --nvdiffrec ------------------------------------------------
if %NVDIFFREC%==1 (
if "%GPU_PLATFORM%"=="cuda" (
mkdir "%EXT_DIR%" 2>nul
git clone -b renderutils https://github.com/JeffreyXiang/nvdiffrec.git "%EXT_DIR%\nvdiffrec"
pip install "%EXT_DIR%\nvdiffrec" --no-build-isolation
) else (
echo [NVDIFFREC] Unsupported platform: %PLATFORM%
)
)

:: ---- --cumesh ---------------------------------------------------
if %CUMESH%==1 (
mkdir "%EXT_DIR%" 2>nul
git clone https://github.com/JeffreyXiang/CuMesh.git "%EXT_DIR%\CuMesh" --recursive
pip install "%EXT_DIR%\CuMesh" --no-build-isolation
)

:: ---- --flexgemm -------------------------------------------------
if %FLEXGEMM%==1 (
mkdir "%EXT_DIR%" 2>nul
git clone https://github.com/JeffreyXiang/FlexGEMM.git "%EXT_DIR%\FlexGEMM" --recursive
pip install "%EXT_DIR%\FlexGEMM" --no-build-isolation
)

:: ---- --o-voxel --------------------------------------------------
if %OVOXEL%==1 (
mkdir "%EXT_DIR%" 2>nul
xcopy /E /I /Y "%WORKDIR%\o-voxel" "%EXT_DIR%\o-voxel"
pip install "%EXT_DIR%\o-voxel" --no-build-isolation
)

echo.
echo Setup complete.
endlocal
19 changes: 14 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Read Arguments
TEMP=`getopt -o h --long help,new-env,basic,flash-attn,cumesh,o-voxel,flexgemm,nvdiffrast,nvdiffrec -n 'setup.sh' -- "$@"`
TEMP=`getopt -o h --long help,new-env,basic,flash-attn,cumesh,o-voxel,flexgemm,nvdiffrast,nvdiffrec,texture,all -n 'setup.sh' -- "$@"`

eval set -- "$TEMP"

Expand Down Expand Up @@ -30,6 +30,8 @@ while true ; do
--flexgemm) FLEXGEMM=true ; shift ;;
--nvdiffrast) NVDIFFRAST=true ; shift ;;
--nvdiffrec) NVDIFFREC=true ; shift ;;
--texture) BASIC=true ; FLASHATTN=true ; OVOXEL=true ; CUMESH=true ; FLEXGEMM=true ; NVDIFFRAST=true ; shift ;;
--all) NEW_ENV=true ; BASIC=true ; FLASHATTN=true ; CUMESH=true ; OVOXEL=true ; FLEXGEMM=true ; NVDIFFRAST=true ; NVDIFFREC=true ; shift ;;
--) shift ; break ;;
*) ERROR=true ; break ;;
esac
Expand All @@ -52,7 +54,9 @@ if [ "$HELP" = true ] ; then
echo " --flexgemm Install flexgemm"
echo " --nvdiffrast Install nvdiffrast"
echo " --nvdiffrec Install nvdiffrec"
return
echo " --texture Install all dependencies for texturing (basic, flash-attn, o-voxel, cumesh, flexgemm, nvdiffrast)"
echo " --all Run all of the above"
exit 0
fi

# Get system information
Expand All @@ -67,10 +71,15 @@ else
fi

if [ "$NEW_ENV" = true ] ; then
conda create -n trellis2 python=3.10
conda activate trellis2
if command -v conda > /dev/null; then
conda create -n trellis2 python=3.10
conda activate trellis2
else
python3 -m venv "$WORKDIR/.venv"
source "$WORKDIR/.venv/bin/activate"
fi
if [ "$PLATFORM" = "cuda" ] ; then
pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu124
pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128
elif [ "$PLATFORM" = "hip" ] ; then
pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/rocm6.2.4
fi
Expand Down
Loading