Skip to content

Instantly share code, notes, and snippets.

@sourman
Last active August 29, 2025 17:01
Show Gist options
  • Select an option

  • Save sourman/e45207b4cb04f79a791306b72f5c5074 to your computer and use it in GitHub Desktop.

Select an option

Save sourman/e45207b4cb04f79a791306b72f5c5074 to your computer and use it in GitHub Desktop.
#!/bin/bash
# trellis start bash script
set -e # Exit on error
echo "=== TRELLIS Launch Script Started ==="
echo "Current user: $(whoami)"
echo "Working directory: $(pwd)"
echo "Date: $(date)"
echo
# *** CLOUD RUN GPU COMPATIBILITY ***
# Google Cloud Run provides managed GPU drivers and runtime at /usr/local/nvidia/
# We need to set the proper environment variables for PyTorch to detect CUDA
# Set up CUDA environment for Google's managed runtime
export CUDA_HOME=/usr/local/nvidia
export PATH=${CUDA_HOME}/bin:${PATH}
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
# Cloud Run GPU environment variables
export NVIDIA_VISIBLE_DEVICES=all
export NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics
# TRELLIS specific environment variables
export PYTHONPATH=/app/TRELLIS
export TORCH_DISABLE_VERSION_CHECK=1
export FORCE_CUDA=1 # Force CUDA detection
echo "=== Environment Setup ==="
echo "CUDA_HOME: $CUDA_HOME"
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
echo "NVIDIA_VISIBLE_DEVICES: $NVIDIA_VISIBLE_DEVICES"
echo "PYTHONPATH: $PYTHONPATH"
echo "TORCH_DISABLE_VERSION_CHECK: $TORCH_DISABLE_VERSION_CHECK"
echo "FORCE_CUDA: $FORCE_CUDA"
echo
# Activate conda environment
echo "=== Activating Conda Environment ==="
source /opt/conda/etc/profile.d/conda.sh
conda activate trellis
echo "Conda environment activated: $CONDA_DEFAULT_ENV"
echo "Python: $(which python3)"
echo "Python version: $(python3 --version)"
echo
# Test CUDA access before starting TRELLIS
echo "=== CUDA Runtime Test ==="
echo "Testing PyTorch CUDA detection..."
# Check if CUDA libraries exist
echo "Checking CUDA libraries..."
if [ -f "/usr/local/nvidia/lib64/libcuda.so" ]; then
echo "✓ CUDA libraries found at /usr/local/nvidia/lib64/"
ls -la /usr/local/nvidia/lib64/libcuda*
else
echo "✗ CUDA libraries not found at /usr/local/nvidia/lib64/"
fi
# Test PyTorch CUDA with proper error handling
python3 -c "
import torch
print(f'PyTorch version: {torch.__version__}')
print(f'CUDA available: {torch.cuda.is_available()}')
if torch.cuda.is_available():
print(f'CUDA device count: {torch.cuda.device_count()}')
print(f'CUDA device name: {torch.cuda.get_device_name(0)}')
print(f'CUDA version: {torch.version.cuda}')
# Test basic CUDA operation
x = torch.randn(3, 3).cuda()
print(f'✓ CUDA tensor created successfully: {x.device}')
else:
print('CUDA not available - checking environment...')
import os
print(f'CUDA_HOME: {os.environ.get(\"CUDA_HOME\", \"Not set\")}')
print(f'LD_LIBRARY_PATH: {os.environ.get(\"LD_LIBRARY_PATH\", \"Not set\")}')
" || echo "PyTorch CUDA test failed"
echo
# *** MODEL WEIGHTS SYMBOLIC LINK SETUP ***
echo "=== Setting up Model Weights Symbolic Links ==="
# Define source and destination directories for HuggingFace models
GCS_MODELS_DIR="/models/.cache"
TRELLIS_CACHE_DIR="/home/user/.cache"
echo "GCS models directory: $GCS_MODELS_DIR"
echo "TRELLIS cache directory: $TRELLIS_CACHE_DIR"
# Check if GCS models directory exists and is accessible
if [ ! -d "$GCS_MODELS_DIR" ]; then
echo "⚠ GCS models directory not found: $GCS_MODELS_DIR"
echo "⚠ Will proceed without pre-loaded models - they will be downloaded at runtime"
else
echo "✓ GCS models directory found"
# List available models in GCS
echo "Available models in GCS:"
ls -la "$GCS_MODELS_DIR" || echo "Cannot list GCS models directory"
# Create copies for all model files in the expected locations
echo "Creating copies for HuggingFace models..."
cp -r "$GCS_MODELS_DIR/huggingface" "$TRELLIS_CACHE_DIR/huggingface"
find "$TRELLIS_CACHE_DIR" -type l -name "*.safetensors" | head -5 || echo "No symbolic links found"
fi
# Change to TRELLIS directory
cd /app/TRELLIS
echo "=== Starting TRELLIS Application ==="
echo "Directory: $(pwd)"
echo "Starting app.py..."
python3 app.py
echo "=== TRELLIS Application Finished ==="
echo "BAAAAD. Trellis app.py has been launched and looks like execution is about to finish"
echo "If execution finished the container exits and the gradio service shuts down"
echo "&&&&&*&&&&&&&*&&&&&&&&&*&&&&&&&&&&&*&&&&&&&&&*&&&&&*&&&&&&"
echo "&&&&&*&&&&&&&*&&&&&&&&&*&&&&&&&&&&&*&&&&&&&&&*&&&&&*&&&&&&"
echo "&&&&&*&&&&&&&*&&&&&&&&&*&&&&&&&&&&&*&&&&&&&&&*&&&&&*&&&&&&"
echo "&&&&&*&&&&&&&*&&&&&&&&&*&&&&&&&&&&&*&&&&&&&&&*&&&&&*&&&&&&"
echo "&&&&&*&&&&&&&*&&&&&&&&&*&&&&&&&&&&&*&&&&&&&&&*&&&&&*&&&&&&"
echo "&&&&&*&&&&&&&*&&&&&&&&&*&&&&&&&&&&&*&&&&&&&&&*&&&&&*&&&&&&"
echo "&&&&&*&&&&&&&*&&&&&&&&&*&&&&&&&&&&&*&&&&&&&&&*&&&&&*&&&&&&"
sleep 10 # we should never get here. we need this sleep for the logs to propagate to Cloud Run Logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment