Spaces:
Running
on
Zero
Running
on
Zero
Update setup_blender.sh
Browse files- setup_blender.sh +39 -34
setup_blender.sh
CHANGED
@@ -8,40 +8,44 @@ BLENDER_PYTHON_VERSION="python3.11" # Should match the -dev package (e.g., pytho
|
|
8 |
BLENDER_TARBALL="blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
9 |
BLENDER_URL="https://download.blender.org/release/Blender${BLENDER_MAJOR_MINOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
INSTALL_DIR="${BLENDER_INSTALL_BASE}/blender-${BLENDER_VERSION}-linux-x64" # Specific version install
|
16 |
-
LOCAL_BIN_DIR="${APP_DIR}/local_bin" # For local symlinks, if used
|
17 |
|
18 |
BLENDER_PY_EXEC="${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}/python/bin/${BLENDER_PYTHON_VERSION}"
|
19 |
|
20 |
UNIRIG_REQS_FILE_IN_SPACE="${APP_DIR}/unirig_requirements.txt"
|
21 |
UNIRIG_REPO_CLONE_DIR="${APP_DIR}/UniRig"
|
22 |
|
23 |
-
# PyTorch specific versions and URLs for pre-installation
|
24 |
TORCH_VERSION="2.3.1"
|
25 |
TORCHVISION_VERSION="0.18.1"
|
26 |
-
TARGET_CUDA_VERSION_SHORT="cu121"
|
27 |
TORCH_INDEX_URL="https://download.pytorch.org/whl/${TARGET_CUDA_VERSION_SHORT}"
|
28 |
-
# PYG_FIND_LINKS_URL is used when installing from requirements.txt later
|
29 |
-
# PYG_FIND_LINKS_URL="https://data.pyg.org/whl/torch-${TORCH_VERSION}+${TARGET_CUDA_VERSION_SHORT}.html"
|
30 |
|
31 |
# --- Set Environment Variables for Build ---
|
32 |
-
export CUDA_HOME=${CUDA_HOME:-/usr/local/cuda}
|
33 |
-
export PATH="${CUDA_HOME}/bin:${LOCAL_BIN_DIR}:${PATH}"
|
34 |
-
export MAX_JOBS=${MAX_JOBS:-4}
|
35 |
|
36 |
-
PYTHON_INCLUDE_DIR="/usr/include/python${BLENDER_PYTHON_VERSION#python}"
|
37 |
export CPATH="${PYTHON_INCLUDE_DIR}:${CPATH}"
|
38 |
export C_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${C_INCLUDE_PATH}"
|
39 |
export CPLUS_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${CPLUS_INCLUDE_PATH}"
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
echo "--- Setup Script Start ---"
|
42 |
echo "Target Blender Installation Directory: ${INSTALL_DIR}"
|
43 |
echo "Blender Python Executable: ${BLENDER_PY_EXEC}"
|
44 |
echo "Using CUDA_HOME=${CUDA_HOME}"
|
|
|
45 |
echo "Initial PATH: ${PATH}"
|
46 |
echo "CPATH set to: ${CPATH}"
|
47 |
echo "Expected Python include directory: ${PYTHON_INCLUDE_DIR}"
|
@@ -53,12 +57,9 @@ else
|
|
53 |
fi
|
54 |
|
55 |
# --- Download and Extract Blender ---
|
56 |
-
# Create the local installation base directory
|
57 |
mkdir -p "${BLENDER_INSTALL_BASE}"
|
58 |
-
mkdir -p "${LOCAL_BIN_DIR}"
|
59 |
|
60 |
-
# Check if the *specific version's directory* inside INSTALL_DIR exists and is not empty.
|
61 |
-
# Blender extracts to a folder like "blender-4.2.0-linux-x64"
|
62 |
if [ ! -d "${INSTALL_DIR}" ] || [ -z "$(ls -A "${INSTALL_DIR}")" ]; then
|
63 |
echo "Blender not found or directory empty at ${INSTALL_DIR}. Proceeding with download and extraction."
|
64 |
echo "Downloading Blender ${BLENDER_VERSION}..."
|
@@ -69,14 +70,11 @@ if [ ! -d "${INSTALL_DIR}" ] || [ -z "$(ls -A "${INSTALL_DIR}")" ]; then
|
|
69 |
fi
|
70 |
|
71 |
echo "Extracting Blender to ${BLENDER_INSTALL_BASE}..."
|
72 |
-
# Extracts to a subdirectory like blender-4.2.0-linux-x64 inside BLENDER_INSTALL_BASE
|
73 |
tar -xJf "/tmp/${BLENDER_TARBALL}" -C "${BLENDER_INSTALL_BASE}"
|
74 |
-
# The tarball extracts into a folder named "blender-4.2.0-linux-x64", so INSTALL_DIR should be correct.
|
75 |
if [ -d "${INSTALL_DIR}" ]; then
|
76 |
echo "Blender extracted successfully to ${INSTALL_DIR}"
|
77 |
else
|
78 |
echo "ERROR: Blender extraction failed or extracted to an unexpected path. Expected: ${INSTALL_DIR}"
|
79 |
-
# List contents of BLENDER_INSTALL_BASE for debugging
|
80 |
ls -la "${BLENDER_INSTALL_BASE}"
|
81 |
exit 1
|
82 |
fi
|
@@ -85,21 +83,18 @@ else
|
|
85 |
fi
|
86 |
echo "Extraction complete."
|
87 |
|
88 |
-
# --- Create Blender Symlink (Optional - to local_bin) ---
|
89 |
if [ -f "${INSTALL_DIR}/blender" ]; then
|
90 |
echo "Creating local symlink for Blender executable in ${LOCAL_BIN_DIR}..."
|
91 |
ln -sf "${INSTALL_DIR}/blender" "${LOCAL_BIN_DIR}/blender"
|
92 |
-
echo "Local symlink created at ${LOCAL_BIN_DIR}/blender.
|
93 |
else
|
94 |
echo "WARNING: Blender executable not found at ${INSTALL_DIR}/blender. Cannot create symlink."
|
95 |
fi
|
96 |
|
97 |
-
|
98 |
# --- Install Dependencies into Blender's Python ---
|
99 |
echo "Installing dependencies into Blender's Python (${BLENDER_PY_EXEC})..."
|
100 |
if [ ! -f "${BLENDER_PY_EXEC}" ]; then
|
101 |
echo "ERROR: Blender Python executable not found at ${BLENDER_PY_EXEC}!"
|
102 |
-
echo "Check Blender extraction and paths."
|
103 |
exit 1
|
104 |
fi
|
105 |
if [ ! -f "${UNIRIG_REQS_FILE_IN_SPACE}" ]; then
|
@@ -111,19 +106,30 @@ echo "Upgrading pip for Blender Python..."
|
|
111 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir --upgrade pip setuptools wheel -vvv
|
112 |
|
113 |
echo "Step 1: Installing PyTorch ${TORCH_VERSION} and Torchvision ${TORCHVISION_VERSION} for Blender's Python..."
|
114 |
-
# Install torch and torchvision first, as other packages (torch-scatter, etc.) depend on it being present for their setup.
|
115 |
-
# Ensure your unirig_requirements.txt also lists these versions so pip can resolve correctly later if needed,
|
116 |
-
# but this direct install ensures they are present for build steps of other packages.
|
117 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir \
|
118 |
torch==${TORCH_VERSION} \
|
119 |
torchvision==${TORCHVISION_VERSION} \
|
120 |
--index-url ${TORCH_INDEX_URL} -vvv
|
121 |
echo "PyTorch and Torchvision installation attempted."
|
122 |
|
123 |
-
|
124 |
-
#
|
125 |
-
#
|
126 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir -r "${UNIRIG_REQS_FILE_IN_SPACE}" -vvv
|
128 |
|
129 |
echo "Dependency installation for Blender's Python complete."
|
@@ -144,11 +150,10 @@ else
|
|
144 |
fi
|
145 |
|
146 |
# (Optional) VRM Addon installation
|
147 |
-
VRM_ADDON_REL_PATH="blender/add-on-vrm-v2.20.77_modified.zip"
|
148 |
ABSOLUTE_ADDON_PATH="${UNIRIG_REPO_CLONE_DIR}/${VRM_ADDON_REL_PATH}"
|
149 |
if [ -f "${ABSOLUTE_ADDON_PATH}" ]; then
|
150 |
echo "Installing optional VRM addon for Blender..."
|
151 |
-
# Ensure CWD is UniRig repo for relative path in addon script if any
|
152 |
(cd "${UNIRIG_REPO_CLONE_DIR}" && \
|
153 |
"${BLENDER_PY_EXEC}" -c "import bpy, os; bpy.ops.preferences.addon_install(overwrite=True, filepath=os.path.abspath('${VRM_ADDON_REL_PATH}')); bpy.ops.preferences.addon_enable(module='io_scene_vrm'); print('VRM Addon installed and enabled.')")
|
154 |
echo "VRM addon installation attempted."
|
|
|
8 |
BLENDER_TARBALL="blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
9 |
BLENDER_URL="https://download.blender.org/release/Blender${BLENDER_MAJOR_MINOR}/blender-${BLENDER_VERSION}-linux-x64.tar.xz"
|
10 |
|
11 |
+
APP_DIR="/home/user/app"
|
12 |
+
BLENDER_INSTALL_BASE="${APP_DIR}/blender_installation"
|
13 |
+
INSTALL_DIR="${BLENDER_INSTALL_BASE}/blender-${BLENDER_VERSION}-linux-x64"
|
14 |
+
LOCAL_BIN_DIR="${APP_DIR}/local_bin"
|
|
|
|
|
15 |
|
16 |
BLENDER_PY_EXEC="${INSTALL_DIR}/${BLENDER_MAJOR_MINOR}/python/bin/${BLENDER_PYTHON_VERSION}"
|
17 |
|
18 |
UNIRIG_REQS_FILE_IN_SPACE="${APP_DIR}/unirig_requirements.txt"
|
19 |
UNIRIG_REPO_CLONE_DIR="${APP_DIR}/UniRig"
|
20 |
|
|
|
21 |
TORCH_VERSION="2.3.1"
|
22 |
TORCHVISION_VERSION="0.18.1"
|
23 |
+
TARGET_CUDA_VERSION_SHORT="cu121"
|
24 |
TORCH_INDEX_URL="https://download.pytorch.org/whl/${TARGET_CUDA_VERSION_SHORT}"
|
|
|
|
|
25 |
|
26 |
# --- Set Environment Variables for Build ---
|
27 |
+
export CUDA_HOME=${CUDA_HOME:-/usr/local/cuda}
|
28 |
+
export PATH="${CUDA_HOME}/bin:${LOCAL_BIN_DIR}:${PATH}"
|
29 |
+
export MAX_JOBS=${MAX_JOBS:-4}
|
30 |
|
31 |
+
PYTHON_INCLUDE_DIR="/usr/include/python${BLENDER_PYTHON_VERSION#python}"
|
32 |
export CPATH="${PYTHON_INCLUDE_DIR}:${CPATH}"
|
33 |
export C_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${C_INCLUDE_PATH}"
|
34 |
export CPLUS_INCLUDE_PATH="${PYTHON_INCLUDE_DIR}:${CPLUS_INCLUDE_PATH}"
|
35 |
|
36 |
+
# ** ADDED FOR FLASH-ATTN: Specify CUDA Architectures **
|
37 |
+
# For ZeroGPU, common architectures are Ampere (8.0, 8.6) or Hopper (9.0).
|
38 |
+
# Adjust if you know the specific GPU architecture of your ZeroGPU instance.
|
39 |
+
# Using a common set for broader compatibility.
|
40 |
+
export TORCH_CUDA_ARCH_LIST="8.0;8.6;9.0"
|
41 |
+
# Alternatively, for a more focused build if you know the target:
|
42 |
+
# export TORCH_CUDA_ARCH_LIST="8.6" # Example for A10G on ZeroGPU
|
43 |
+
|
44 |
echo "--- Setup Script Start ---"
|
45 |
echo "Target Blender Installation Directory: ${INSTALL_DIR}"
|
46 |
echo "Blender Python Executable: ${BLENDER_PY_EXEC}"
|
47 |
echo "Using CUDA_HOME=${CUDA_HOME}"
|
48 |
+
echo "TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST}"
|
49 |
echo "Initial PATH: ${PATH}"
|
50 |
echo "CPATH set to: ${CPATH}"
|
51 |
echo "Expected Python include directory: ${PYTHON_INCLUDE_DIR}"
|
|
|
57 |
fi
|
58 |
|
59 |
# --- Download and Extract Blender ---
|
|
|
60 |
mkdir -p "${BLENDER_INSTALL_BASE}"
|
61 |
+
mkdir -p "${LOCAL_BIN_DIR}"
|
62 |
|
|
|
|
|
63 |
if [ ! -d "${INSTALL_DIR}" ] || [ -z "$(ls -A "${INSTALL_DIR}")" ]; then
|
64 |
echo "Blender not found or directory empty at ${INSTALL_DIR}. Proceeding with download and extraction."
|
65 |
echo "Downloading Blender ${BLENDER_VERSION}..."
|
|
|
70 |
fi
|
71 |
|
72 |
echo "Extracting Blender to ${BLENDER_INSTALL_BASE}..."
|
|
|
73 |
tar -xJf "/tmp/${BLENDER_TARBALL}" -C "${BLENDER_INSTALL_BASE}"
|
|
|
74 |
if [ -d "${INSTALL_DIR}" ]; then
|
75 |
echo "Blender extracted successfully to ${INSTALL_DIR}"
|
76 |
else
|
77 |
echo "ERROR: Blender extraction failed or extracted to an unexpected path. Expected: ${INSTALL_DIR}"
|
|
|
78 |
ls -la "${BLENDER_INSTALL_BASE}"
|
79 |
exit 1
|
80 |
fi
|
|
|
83 |
fi
|
84 |
echo "Extraction complete."
|
85 |
|
|
|
86 |
if [ -f "${INSTALL_DIR}/blender" ]; then
|
87 |
echo "Creating local symlink for Blender executable in ${LOCAL_BIN_DIR}..."
|
88 |
ln -sf "${INSTALL_DIR}/blender" "${LOCAL_BIN_DIR}/blender"
|
89 |
+
echo "Local symlink created at ${LOCAL_BIN_DIR}/blender."
|
90 |
else
|
91 |
echo "WARNING: Blender executable not found at ${INSTALL_DIR}/blender. Cannot create symlink."
|
92 |
fi
|
93 |
|
|
|
94 |
# --- Install Dependencies into Blender's Python ---
|
95 |
echo "Installing dependencies into Blender's Python (${BLENDER_PY_EXEC})..."
|
96 |
if [ ! -f "${BLENDER_PY_EXEC}" ]; then
|
97 |
echo "ERROR: Blender Python executable not found at ${BLENDER_PY_EXEC}!"
|
|
|
98 |
exit 1
|
99 |
fi
|
100 |
if [ ! -f "${UNIRIG_REQS_FILE_IN_SPACE}" ]; then
|
|
|
106 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir --upgrade pip setuptools wheel -vvv
|
107 |
|
108 |
echo "Step 1: Installing PyTorch ${TORCH_VERSION} and Torchvision ${TORCHVISION_VERSION} for Blender's Python..."
|
|
|
|
|
|
|
109 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir \
|
110 |
torch==${TORCH_VERSION} \
|
111 |
torchvision==${TORCHVISION_VERSION} \
|
112 |
--index-url ${TORCH_INDEX_URL} -vvv
|
113 |
echo "PyTorch and Torchvision installation attempted."
|
114 |
|
115 |
+
# ** ADDED: Separate step for flash-attn installation **
|
116 |
+
# Ensure 'flash-attn' is listed in your unirig_requirements.txt if you want pip to manage its version,
|
117 |
+
# or specify version here e.g., flash-attn==<version>
|
118 |
+
# The TORCH_CUDA_ARCH_LIST environment variable set earlier will be used by its build process.
|
119 |
+
# Also ensure 'build-essential' is in your packages.txt for g++ compiler.
|
120 |
+
echo "Step 2: Installing flash-attn for Blender's Python..."
|
121 |
+
# Assuming flash-attn is in unirig_requirements.txt and will be picked up by the next step,
|
122 |
+
# OR if it needs to be a specific version not in the file, install it explicitly:
|
123 |
+
# "${BLENDER_PY_EXEC}" -m pip install --no-cache-dir flash-attn -vvv
|
124 |
+
# For now, we'll rely on it being in unirig_requirements.txt and the env vars being set.
|
125 |
+
# If flash-attn continues to fail, you might need to install it explicitly here.
|
126 |
+
# The most robust way is to let it be installed by the requirements file if it's listed there
|
127 |
+
# with any specific version constraints UniRig might have. The environment variables should help.
|
128 |
+
|
129 |
+
echo "Step 3: Installing remaining dependencies from ${UNIRIG_REQS_FILE_IN_SPACE}..."
|
130 |
+
# This will install torch-scatter, torch-cluster, spconv, flash-attn (if listed), bpy, etc.
|
131 |
+
# flash-attn build will use TORCH_CUDA_ARCH_LIST.
|
132 |
+
# torch-scatter etc. will use the pre-installed PyTorch.
|
133 |
"${BLENDER_PY_EXEC}" -m pip install --no-cache-dir -r "${UNIRIG_REQS_FILE_IN_SPACE}" -vvv
|
134 |
|
135 |
echo "Dependency installation for Blender's Python complete."
|
|
|
150 |
fi
|
151 |
|
152 |
# (Optional) VRM Addon installation
|
153 |
+
VRM_ADDON_REL_PATH="blender/add-on-vrm-v2.20.77_modified.zip"
|
154 |
ABSOLUTE_ADDON_PATH="${UNIRIG_REPO_CLONE_DIR}/${VRM_ADDON_REL_PATH}"
|
155 |
if [ -f "${ABSOLUTE_ADDON_PATH}" ]; then
|
156 |
echo "Installing optional VRM addon for Blender..."
|
|
|
157 |
(cd "${UNIRIG_REPO_CLONE_DIR}" && \
|
158 |
"${BLENDER_PY_EXEC}" -c "import bpy, os; bpy.ops.preferences.addon_install(overwrite=True, filepath=os.path.abspath('${VRM_ADDON_REL_PATH}')); bpy.ops.preferences.addon_enable(module='io_scene_vrm'); print('VRM Addon installed and enabled.')")
|
159 |
echo "VRM addon installation attempted."
|