bulatko commited on
Commit
26bde8f
·
1 Parent(s): 57a7ef7

Runtime fallback: install local detectron2 if import fails (no build isolation)

Browse files
Files changed (3) hide show
  1. packages.txt +5 -0
  2. postBuild +53 -0
  3. requirements.txt +1 -1
packages.txt CHANGED
@@ -1,5 +1,10 @@
1
  build-essential
2
  python3-dev
 
 
 
 
 
3
  cmake
4
  ninja-build
5
  ffmpeg
 
1
  build-essential
2
  python3-dev
3
+ git
4
+ libgl1
5
+ libglib2.0-0
6
+ build-essential
7
+ python3-dev
8
  cmake
9
  ninja-build
10
  ffmpeg
postBuild CHANGED
@@ -1,3 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/bin/sh
2
  set -e
3
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ echo "postBuild: starting detectron2 setup"
5
+ python -V || true
6
+ pip --version || true
7
+
8
+ # Ensure torch is present and print environment info
9
+ python - <<'PY' || true
10
+ import torch, platform, sys
11
+ print("Torch:", torch.__version__)
12
+ print("CUDA available:", torch.cuda.is_available())
13
+ print("torch.version.cuda:", getattr(torch.version, "cuda", None))
14
+ print("Python:", sys.version.split()[0])
15
+ print("Platform:", platform.platform())
16
+ PY
17
+
18
+ # Determine expected wheel index (CPU or CUDA) based on installed torch
19
+ PYTORCH_MM="$(python - <<'PY'
20
+ import torch
21
+ v = torch.__version__.split('+')[0].split('.')
22
+ print(f"{v[0]}.{v[1]}")
23
+ PY
24
+ )"
25
+ CUDA_TAG="$(python - <<'PY'
26
+ import torch
27
+ cv = getattr(torch.version, "cuda", None)
28
+ print(("cu"+cv.replace(".","")) if cv else "cpu")
29
+ PY
30
+ )"
31
+
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 (CPU-only) ..."
39
+ export FORCE_CUDA=0
40
+ pip install --no-cache-dir --no-build-isolation "git+https://github.com/facebookresearch/detectron2.git@fd27788985af0f4ca800bca563acdb700bb890e2"
41
+ fi
42
+
43
+ # Verify installation
44
+ python - <<'PY'
45
+ import importlib
46
+ spec = importlib.util.find_spec("detectron2")
47
+ if spec is None:
48
+ raise SystemExit("detectron2 not found after installation")
49
+ import detectron2
50
+ print("detectron2 installed. Version:", getattr(detectron2, "__version__", "unknown"))
51
+ PY
52
+
53
+ echo "postBuild: detectron2 setup completed"
54
  #!/bin/sh
55
  set -e
56
 
requirements.txt CHANGED
@@ -20,7 +20,7 @@ scipy
20
  onnxruntime
21
  gdown
22
  # detectron2 runtime deps (needed when importing vendored detectron2 via PYTHONPATH)
23
- git+https://github.com/facebookresearch/detectron2.git
24
 
25
  # NOTE (HF Spaces): do not use local-path installs here.
26
  # HF builds install requirements BEFORE copying the repo into /app.
 
20
  onnxruntime
21
  gdown
22
  # detectron2 runtime deps (needed when importing vendored detectron2 via PYTHONPATH)
23
+
24
 
25
  # NOTE (HF Spaces): do not use local-path installs here.
26
  # HF builds install requirements BEFORE copying the repo into /app.