Skip to content

Commit 0a8f7f1

Browse files
committed
build: fix install of detectron2 b constraining setuptools
1 parent ad7de6a commit 0a8f7f1

4 files changed

Lines changed: 75 additions & 6 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=68", "wheel", "pybind11>=2.6.0"]
2+
requires = ["setuptools>=68,<81", "wheel", "pybind11>=2.6.0"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -36,7 +36,7 @@ dependencies = [
3636
"ptflops>=0.7.3",
3737
"Cython==3.0.8",
3838
"wheel>=0.45.1",
39-
"setuptools>=68",
39+
"setuptools>=68,<81",
4040
"yuvio",
4141
]
4242

scripts/install.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ run_prepare() {
189189

190190
run_install () {
191191
detect_env
192-
"${PIP[@]}" install -U pip wheel setuptools
192+
"${PIP[@]}" install -U pip wheel "setuptools>=68,<81"
193193

194194
echo "Selected Models to be installed: ${MODEL}"
195195

@@ -212,7 +212,7 @@ run_install () {
212212
"${PIP[@]}" install -e "${COMPRESSAI_VISION_ROOT_DIR}/compressai"
213213
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
214214
echo "Building compressai C++ extensions from source..."
215-
"${PIP[@]}" install "pybind11>=2.6.0" "setuptools>=68" wheel setuptools
215+
"${PIP[@]}" install "pybind11>=2.6.0" "setuptools>=68,<81" wheel
216216
cd "${COMPRESSAI_VISION_ROOT_DIR}/compressai"
217217
rm -rf build/ **/*.so
218218
"${PIP[@]}" install -e . --no-build-isolation
@@ -291,6 +291,7 @@ install_detectron2 () {
291291

292292
cd "${MODELS_SOURCE_DIR}/detectron2"
293293
cp ${SCRIPT_DIR}/install_utils/detectron2_pyproject.toml ./pyproject.toml
294+
git apply "${SCRIPT_DIR}/install_utils/patches/0002-detectron2-lazy-torch-import.patch" || echo "Patch could not be applied. Possibly already applied."
294295

295296
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
296297
"${PIP[@]}" install --no-build-isolation -e .

scripts/install_utils/detectron2_pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ requires = [
3737
"grpcio>=1.48.2",
3838
"markdown>=2.6.8",
3939
"protobuf!=4.24.0,>=3.19.6",
40-
"setuptools>=41.0.0",
40+
"setuptools>=68,<81",
41+
"wheel",
4142
"tensorboard-data-server<0.8.0,>=0.7.0",
4243
"werkzeug>=1.0.1",
4344
"MarkupSafe>=2.1.1",
4445
]
45-
build-backend = "setuptools.build_meta"
46+
build-backend = "setuptools.build_meta"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--- a/setup.py
2+
+++ b/setup.py
3+
@@ -5,13 +5,17 @@
4+
import os
5+
import shutil
6+
from os import path
7+
+import sys
8+
from setuptools import find_packages, setup
9+
from typing import List
10+
-import torch
11+
-from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
12+
13+
-torch_ver = [int(x) for x in torch.__version__.split(".")[:2]]
14+
-assert torch_ver >= [1, 8], "Requires PyTorch >= 1.8"
15+
+
16+
+def get_torch():
17+
+ import torch
18+
+
19+
+ torch_ver = [int(x) for x in torch.__version__.split(".")[:2]]
20+
+ assert torch_ver >= [1, 8], "Requires PyTorch >= 1.8"
21+
+ return torch, torch_ver
22+
23+
24+
def get_version():
25+
@@ -44,6 +48,8 @@
26+
main_source = path.join(extensions_dir, "vision.cpp")
27+
sources = glob.glob(path.join(extensions_dir, "**", "*.cpp"))
28+
29+
+ torch, torch_ver = get_torch()
30+
+ from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
31+
from torch.utils.cpp_extension import ROCM_HOME
32+
33+
is_rocm_pytorch = (
34+
@@ -144,6 +150,24 @@
35+
"detectron2.projects.panoptic_deeplab": "projects/Panoptic-DeepLab/panoptic_deeplab",
36+
}
37+
38+
+BUILD_COMMANDS = {
39+
+ "build",
40+
+ "build_ext",
41+
+ "bdist_wheel",
42+
+ "editable_wheel",
43+
+ "develop",
44+
+ "install",
45+
+}
46+
+SHOULD_BUILD_EXTENSIONS = any(cmd in BUILD_COMMANDS for cmd in sys.argv[1:])
47+
+
48+
+if SHOULD_BUILD_EXTENSIONS:
49+
+ torch, _ = get_torch()
50+
+ ext_modules = get_extensions()
51+
+ cmdclass = {"build_ext": torch.utils.cpp_extension.BuildExtension}
52+
+else:
53+
+ ext_modules = []
54+
+ cmdclass = {}
55+
+
56+
setup(
57+
name="detectron2",
58+
version=get_version(),
59+
@@ -203,6 +227,6 @@
60+
"flake8-comprehensions",
61+
],
62+
},
63+
- ext_modules=get_extensions(),
64+
- cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
65+
+ ext_modules=ext_modules,
66+
+ cmdclass=cmdclass,
67+
)

0 commit comments

Comments
 (0)