關閉      標題:trellis2 windows
內容:
使用 2019 vs cmd 啟動 cmd line

set CUDA_HOME=C:\cuda\12.6
set PATH=C:\cuda\v12.6\bin;%PATH%
set DISTUTILS_USE_SDK=1
set TORCH_CUDA_ARCH_LIST=6.1
set HF_TOKEN=hf_....................
cd /d c:\
mkdir opt
cd \opt
git clone -b main https://github.com/microsoft/TRELLIS.2.git --recursive


git clone https://github.com/visualbruno/ComfyUI-Trellis2.git
conda create -p C:\conda\vm\trellis2 python=3.11


conda activate C:\conda\vm\trellis2



pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install xformers --index-url https://download.pytorch.org/whl/cu118
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

先裝 torch
結果 xformers 會把 torch 降版
裝完後再把 torch 升回來

cd \opt\ComfyUI-Trellis2
python -m pip install -r requirements.txt

conda install ninja -c conda-forge
pip install gradio imageio
pip install easydict
pip install transformers
pip install utils3d
pip install kornia timm


確認目前 torch 版本
python
import torch
print("torch version:", torch.__version__)
print("cuda version:", torch.version.cuda)
print("is cuda available:", torch.cuda.is_available())
if torch.cuda.is_available():
    print("gpu:", torch.cuda.get_device_name(0))
EOF

得 torch version: 2.7.1+cu118

cd C:\opt\ComfyUI-Trellis2\wheels\Windows\Torch270
python.exe -m pip install cumesh-0.0.1-cp311-cp311-win_amd64.whl
python.exe -m pip install flex_gemm-0.0.1-cp311-cp311-win_amd64.whl
python.exe -m pip install nvdiffrast-0.4.0-cp311-cp311-win_amd64.whl
python.exe -m pip install nvdiffrec_render-0.0.0-cp311-cp311-win_amd64.whl
python.exe -m pip install o_voxel-0.0.1-cp311-cp311-win_amd64.whl

copy c:\cuda\11.8\cudart64_110.dll copy c:\cuda\11.8\cudart64_12.dll


cd C:\opt\TRELLIS.2

編輯 app.py 前面加入
import gradio as gr
import sys
import os
os.environ['OPENCV_IO_ENABLE_OPENEXR'] = '1'
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
os.environ["TRELLIS_ATTENTION_BACKEND"] = "torch"
os.environ["TRELLIS_SPARSE_BACKEND"] = "torch"
#os.environ["CUDA_VISIBLE_DEVICES"] = ""
os.environ["ATTN_BACKEND"] = "naive"
os.environ["SPARSE_ATTN_BACKEND"] = "xformers"
os.environ["SPARSE_CONV_BACKEND"] = "flex_gemm"
os.environ["TRELLIS_DTYPE"] = "float16"
os.environ["TRELLIS_LOW_VRAM"] = "1"


# 指定 Python loader 先找 CUDA 11.8
os.add_dll_directory(r"C:\CUDA\11.8\bin")
os.add_dll_directory(r"C:\CUDA\11.8\libnvvp")
os.add_dll_directory(r"C:\conda\vm\trellis2")
os.add_dll_directory(r"C:\conda\vm\trellis2\Lib\site-packages\torch\lib")
os.add_dll_directory(sys.prefix)  # Python 根目錄,例如 C:\conda\vm\trellis2


python app.py