Deploy Zoo3D with Zero GPU support
Browse files- app.py +3 -3
- packages.txt +5 -0
- postBuild +0 -104
- requirements.txt +16 -4
app.py
CHANGED
|
@@ -33,14 +33,14 @@ def _launch():
|
|
| 33 |
os.environ["MAX_IMAGES"] = "10" # Limit max images for Zero GPU
|
| 34 |
os.environ["MAX_RESOLUTION"] = "512" # Lower resolution for memory optimization
|
| 35 |
|
| 36 |
-
# Verify critical dependencies are available (installed during build via
|
| 37 |
print("🔍 Verifying dependencies...")
|
| 38 |
try:
|
| 39 |
import detectron2
|
| 40 |
print(f"✅ detectron2 available (version: {getattr(detectron2, '__version__', 'unknown')})")
|
| 41 |
except ImportError as e:
|
| 42 |
print(f"⚠️ detectron2 not available: {e}")
|
| 43 |
-
print(" detectron2 should be installed via
|
| 44 |
|
| 45 |
try:
|
| 46 |
import mmcv
|
|
@@ -53,7 +53,7 @@ def _launch():
|
|
| 53 |
print(f"✅ pytorch3d available (version: {getattr(pytorch3d, '__version__', 'unknown')})")
|
| 54 |
except ImportError as e:
|
| 55 |
print(f"⚠️ pytorch3d not available: {e}")
|
| 56 |
-
print(" pytorch3d should be installed via
|
| 57 |
|
| 58 |
# HF Spaces/Gradio sometimes calls /api_info regardless of `show_api=False`.
|
| 59 |
# Some gradio_client versions crash when JSON schema uses boolean `additionalProperties`.
|
|
|
|
| 33 |
os.environ["MAX_IMAGES"] = "10" # Limit max images for Zero GPU
|
| 34 |
os.environ["MAX_RESOLUTION"] = "512" # Lower resolution for memory optimization
|
| 35 |
|
| 36 |
+
# Verify critical dependencies are available (installed during build via requirements.txt)
|
| 37 |
print("🔍 Verifying dependencies...")
|
| 38 |
try:
|
| 39 |
import detectron2
|
| 40 |
print(f"✅ detectron2 available (version: {getattr(detectron2, '__version__', 'unknown')})")
|
| 41 |
except ImportError as e:
|
| 42 |
print(f"⚠️ detectron2 not available: {e}")
|
| 43 |
+
print(" detectron2 should be installed via requirements.txt")
|
| 44 |
|
| 45 |
try:
|
| 46 |
import mmcv
|
|
|
|
| 53 |
print(f"✅ pytorch3d available (version: {getattr(pytorch3d, '__version__', 'unknown')})")
|
| 54 |
except ImportError as e:
|
| 55 |
print(f"⚠️ pytorch3d not available: {e}")
|
| 56 |
+
print(" pytorch3d should be installed via requirements.txt")
|
| 57 |
|
| 58 |
# HF Spaces/Gradio sometimes calls /api_info regardless of `show_api=False`.
|
| 59 |
# Some gradio_client versions crash when JSON schema uses boolean `additionalProperties`.
|
packages.txt
CHANGED
|
@@ -4,3 +4,8 @@ libxext6
|
|
| 4 |
libgl1
|
| 5 |
libglib2.0-0
|
| 6 |
libgomp1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
libgl1
|
| 5 |
libglib2.0-0
|
| 6 |
libgomp1
|
| 7 |
+
cmake
|
| 8 |
+
ninja-build
|
| 9 |
+
g++
|
| 10 |
+
gcc
|
| 11 |
+
git
|
postBuild
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env bash
|
| 2 |
-
set -euo pipefail
|
| 3 |
-
|
| 4 |
-
echo "=== postBuild: Installing build dependencies ==="
|
| 5 |
-
python -m pip install -U pip setuptools wheel ninja cython
|
| 6 |
-
|
| 7 |
-
# Print environment info
|
| 8 |
-
python - <<'PY' || true
|
| 9 |
-
import torch, platform, sys
|
| 10 |
-
print("Torch:", torch.__version__)
|
| 11 |
-
print("CUDA available:", torch.cuda.is_available())
|
| 12 |
-
print("torch.version.cuda:", getattr(torch.version, "cuda", None))
|
| 13 |
-
print("Python:", sys.version.split()[0])
|
| 14 |
-
print("Platform:", platform.platform())
|
| 15 |
-
PY
|
| 16 |
-
|
| 17 |
-
# Determine CUDA tag for detectron2 wheel
|
| 18 |
-
PYTORCH_MM="$(python - <<'PY'
|
| 19 |
-
import torch
|
| 20 |
-
v = torch.__version__.split('+')[0].split('.')
|
| 21 |
-
print(f"{v[0]}.{v[1]}")
|
| 22 |
-
PY
|
| 23 |
-
)"
|
| 24 |
-
CUDA_TAG="$(python - <<'PY'
|
| 25 |
-
import torch
|
| 26 |
-
cv = getattr(torch.version, "cuda", None)
|
| 27 |
-
print(("cu"+cv.replace(".","")) if cv else "cpu")
|
| 28 |
-
PY
|
| 29 |
-
)"
|
| 30 |
-
|
| 31 |
-
echo "=== Installing detectron2 ==="
|
| 32 |
-
WHEEL_URL="https://dl.fbaipublicfiles.com/detectron2/wheels/${CUDA_TAG}/torch${PYTORCH_MM}/index.html"
|
| 33 |
-
echo "Attempting detectron2 wheel from: ${WHEEL_URL}"
|
| 34 |
-
|
| 35 |
-
if pip install --no-cache-dir "detectron2" -f "${WHEEL_URL}"; then
|
| 36 |
-
echo "detectron2 installed from prebuilt wheel"
|
| 37 |
-
else
|
| 38 |
-
echo "Prebuilt wheel not available. Building detectron2 from source..."
|
| 39 |
-
export FORCE_CUDA=0
|
| 40 |
-
export MAX_JOBS=${MAX_JOBS:-1}
|
| 41 |
-
pip install --no-cache-dir --no-build-isolation "git+https://github.com/facebookresearch/detectron2.git@fd27788985af0f4ca800bca563acdb700bb890e2"
|
| 42 |
-
fi
|
| 43 |
-
|
| 44 |
-
# Verify detectron2 installation
|
| 45 |
-
python - <<'PY'
|
| 46 |
-
import importlib
|
| 47 |
-
spec = importlib.util.find_spec("detectron2")
|
| 48 |
-
if spec is None:
|
| 49 |
-
raise SystemExit("detectron2 not found after installation")
|
| 50 |
-
import detectron2
|
| 51 |
-
print("✅ detectron2 installed. Version:", getattr(detectron2, "__version__", "unknown"))
|
| 52 |
-
PY
|
| 53 |
-
|
| 54 |
-
echo "=== Installing pytorch3d ==="
|
| 55 |
-
# pytorch3d requires special handling - try prebuilt wheels first
|
| 56 |
-
PYTORCH3D_WHEEL_URL="https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py310_${CUDA_TAG}_pyt${PYTORCH_MM}/download.html"
|
| 57 |
-
echo "Attempting pytorch3d wheel from: ${PYTORCH3D_WHEEL_URL}"
|
| 58 |
-
|
| 59 |
-
# Try prebuilt wheel first, fallback to source build
|
| 60 |
-
if pip install --no-cache-dir "pytorch3d" -f "${PYTORCH3D_WHEEL_URL}" 2>/dev/null; then
|
| 61 |
-
echo "pytorch3d installed from prebuilt wheel"
|
| 62 |
-
else
|
| 63 |
-
echo "Prebuilt pytorch3d wheel not available. Building from source..."
|
| 64 |
-
export FORCE_CUDA=${FORCE_CUDA:-0}
|
| 65 |
-
export MAX_JOBS=${MAX_JOBS:-1}
|
| 66 |
-
pip install --no-cache-dir --no-build-isolation "git+https://github.com/facebookresearch/pytorch3d.git"
|
| 67 |
-
fi
|
| 68 |
-
|
| 69 |
-
# Verify pytorch3d installation
|
| 70 |
-
python - <<'PY'
|
| 71 |
-
try:
|
| 72 |
-
import pytorch3d
|
| 73 |
-
print("✅ pytorch3d installed. Version:", getattr(pytorch3d, "__version__", "unknown"))
|
| 74 |
-
except ImportError as e:
|
| 75 |
-
print(f"⚠️ pytorch3d import failed (may work at runtime): {e}")
|
| 76 |
-
PY
|
| 77 |
-
|
| 78 |
-
echo "=== Installing vendored detectron2 (CropFormer) ==="
|
| 79 |
-
# Install vendored detectron2 with CropFormer extensions
|
| 80 |
-
if [ -d "MaskClustering/third_party/detectron2" ]; then
|
| 81 |
-
export MAX_JOBS=${MAX_JOBS:-1}
|
| 82 |
-
pip install --no-build-isolation -e MaskClustering/third_party/detectron2 || echo "⚠️ Vendored detectron2 installation failed (will use system detectron2)"
|
| 83 |
-
fi
|
| 84 |
-
|
| 85 |
-
echo "=== Compiling CropFormer components ==="
|
| 86 |
-
CROPFORMER_ROOT="MaskClustering/third_party/detectron2/projects/CropFormer"
|
| 87 |
-
|
| 88 |
-
# 1. Compile entity_api PythonAPI
|
| 89 |
-
if [ -d "${CROPFORMER_ROOT}/entity_api/PythonAPI" ]; then
|
| 90 |
-
echo "Compiling entity_api PythonAPI..."
|
| 91 |
-
(cd "${CROPFORMER_ROOT}/entity_api/PythonAPI" && make) || echo "⚠️ entity_api compilation failed (non-critical)"
|
| 92 |
-
fi
|
| 93 |
-
|
| 94 |
-
# 2. Compile MSDeformAttn CUDA ops
|
| 95 |
-
OPS_DIR="${CROPFORMER_ROOT}/mask2former/modeling/pixel_decoder/ops"
|
| 96 |
-
if [ -d "${OPS_DIR}" ]; then
|
| 97 |
-
echo "Compiling MSDeformAttn CUDA operators..."
|
| 98 |
-
(cd "${OPS_DIR}" && sh make.sh) || {
|
| 99 |
-
echo "⚠️ CUDA compilation failed, trying CPU-only mode..."
|
| 100 |
-
(cd "${OPS_DIR}" && FORCE_CUDA=0 python setup.py build install) || echo "⚠️ MSDeformAttn compilation failed (non-critical)"
|
| 101 |
-
}
|
| 102 |
-
fi
|
| 103 |
-
|
| 104 |
-
echo "=== postBuild completed ==="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -28,10 +28,22 @@ timm
|
|
| 28 |
h5py
|
| 29 |
scikit-image
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
# detectron2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
# detectron2 is installed from vendored source in `postBuild`.
|
|
|
|
| 28 |
h5py
|
| 29 |
scikit-image
|
| 30 |
|
| 31 |
+
# pytorch3d dependencies (required before installing pytorch3d)
|
| 32 |
+
fvcore>=0.1.5,<0.1.6
|
| 33 |
+
iopath>=0.1.7,<0.1.10
|
| 34 |
|
| 35 |
+
# detectron2 dependencies (install before detectron2)
|
| 36 |
+
pycocotools>=2.0.2
|
| 37 |
+
termcolor>=1.1
|
| 38 |
+
yacs>=0.1.8
|
| 39 |
+
tabulate
|
| 40 |
+
cloudpickle
|
| 41 |
+
tensorboard
|
| 42 |
+
black
|
| 43 |
+
packaging
|
| 44 |
|
| 45 |
+
# pytorch3d - install from git (will be compiled during build)
|
| 46 |
+
pytorch3d @ git+https://github.com/facebookresearch/pytorch3d.git@stable
|
| 47 |
|
| 48 |
+
# detectron2 - install from local third_party directory
|
| 49 |
+
./MaskClustering/third_party/detectron2
|
|
|