Skip to content

Commit 3a6743e

Browse files
ppwwyyxxfacebook-github-bot
authored andcommitted
build public binary wheels (#381)
Summary: Now live at https://dl.fbaipublicfiles.com/detectron2/wheels/index.html Pull Request resolved: fairinternal/detectron2#381 Differential Revision: D19776395 Pulled By: ppwwyyxx fbshipit-source-id: 363a7f5fa1499a1e1d91eccd055c9b5ca01cc160
1 parent 5bda5bb commit 3a6743e

File tree

10 files changed

+224
-23
lines changed

10 files changed

+224
-23
lines changed

.github/CONTRIBUTING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ If some part is not as extensible, you can also bring up the issue to make it mo
3232

3333
When sending a PR, please do:
3434

35-
1. Fork the repo and create your branch from `master`.
35+
1. If a PR contains multiple orthogonal changes, split it to several PRs.
3636
2. If you've added code that should be tested, add tests.
37-
3. If APIs are changed, update the documentation.
38-
4. Ensure the test suite passes.
39-
5. Make sure your code lints with `./dev/linter.sh`.
40-
6. If a PR contains multiple orthogonal changes, split it to several PRs.
41-
7. If you haven't already, complete the Contributor License Agreement ("CLA").
37+
3. For PRs that need experiments (e.g. adding a new model), you don't need to update model zoo,
38+
but do provide experiment results in the description of the PR.
39+
4. If APIs are changed, update the documentation.
40+
5. Ensure the test suite passes.
41+
6. Make sure your code lints with `./dev/linter.sh`.
42+
4243

4344
## Contributor License Agreement ("CLA")
4445
In order to accept your pull request, we need you to submit a CLA. You only need

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ _ext
1616
detectron2.egg-info/
1717
build/
1818
dist/
19+
wheels/
1920

2021
# pytorch/python/numpy formats
2122
*.pth

INSTALL.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ also installs detectron2 with a few simple commands.
1212
You can install them together at [pytorch.org](https://pytorch.org) to make sure of this.
1313
- OpenCV, optional, needed by demo and visualization
1414
- pycocotools: `pip install cython; pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'`
15-
- gcc & g++ ≥ 4.9
1615

1716

18-
### Build and Install Detectron2
17+
### Build Detectron2 from Source
1918

20-
After having the above dependencies, run:
19+
After having the above dependencies and gcc & g++ ≥ 4.9, run:
2120
```
2221
pip install 'git+https://github.com/facebookresearch/detectron2.git'
2322
# (add --user if you don't have permission)
@@ -33,8 +32,21 @@ cd detectron2 && pip install -e .
3332
To __rebuild__ detectron2 that's built from a local clone, `rm -rf build/ **/*.so` then `pip install -e .`.
3433
You often need to rebuild detectron2 after reinstalling PyTorch.
3534

35+
### Install Pre-Built Detectron2
36+
```
37+
# for CUDA 10.1:
38+
pip install detectron2 -f \
39+
https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
40+
```
41+
You can replace cu101 with "cu{100,92}" or "cpu".
42+
43+
Note that such installation has to be used with the latest official PyTorch release (currently 1.4).
44+
It will not work with your custom build of PyTorch.
45+
3646
### Common Installation Issues
3747

48+
If you met issues using the pre-built detectron2, please uninstall it and try building it from source.
49+
3850
Click each issue for its solutions:
3951

4052
<details>

dev/packaging/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
## To build a cu101 wheel for release:
3+
4+
```
5+
$ nvidia-docker run -it --storage-opt "size=20GB" --name pt pytorch/manylinux-cuda101
6+
# inside the container:
7+
# git clone https://github.com/facebookresearch/detectron2/
8+
# cd detectron2
9+
# export CU_VERSION=cu101 D2_VERSION_SUFFIX= PYTHON_VERSION=3.7 PYTORCH_VERSION=1.4
10+
# ./dev/packaging/build_wheel.sh
11+
```
12+
13+
## To build all wheels for `CUDA {9.2,10.0,10.1}` x `Python {3.6,3.7,3.8}`:
14+
```
15+
./dev/packaging/build_all_wheels.sh
16+
./dev/packaging/gen_wheel_index.sh /path/to/wheels
17+
```

dev/packaging/build_all_wheels.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash -e
2+
3+
PYTORCH_VERSION=1.4
4+
5+
build_for_one_cuda() {
6+
cu=$1
7+
8+
case "$cu" in
9+
cu*)
10+
container_name=manylinux-cuda${cu/cu/}
11+
;;
12+
cpu)
13+
container_name=manylinux-cuda101
14+
;;
15+
*)
16+
echo "Unrecognized cu=$cu"
17+
exit 1
18+
;;
19+
esac
20+
21+
echo "Launching container $container_name ..."
22+
23+
for py in 3.6 3.7 3.8; do
24+
docker run -itd \
25+
--name $container_name \
26+
--mount type=bind,source="$(pwd)",target=/detectron2 \
27+
pytorch/$container_name
28+
29+
cat <<EOF | docker exec -i $container_name sh
30+
export CU_VERSION=$cu D2_VERSION_SUFFIX=+$cu PYTHON_VERSION=$py
31+
export PYTORCH_VERSION=$PYTORCH_VERSION
32+
cd /detectron2 && ./dev/packaging/build_wheel.sh
33+
EOF
34+
35+
if [[ "$cu" == "cu101" ]]; then
36+
# build wheel without local version
37+
cat <<EOF | docker exec -i $container_name sh
38+
export CU_VERSION=$cu D2_VERSION_SUFFIX= PYTHON_VERSION=$py
39+
export PYTORCH_VERSION=$PYTORCH_VERSION
40+
cd /detectron2 && ./dev/packaging/build_wheel.sh
41+
EOF
42+
fi
43+
44+
docker exec -i $container_name rm -rf /detectron2/build/$cu
45+
docker container stop $container_name
46+
docker container rm $container_name
47+
done
48+
}
49+
50+
if [[ -n "$1" ]]; then
51+
build_for_one_cuda "$1"
52+
else
53+
for cu in cu101 cu100 cu92 cpu; do
54+
build_for_one_cuda "$cu"
55+
done
56+
fi

dev/packaging/build_wheel.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
ldconfig # https://github.com/NVIDIA/nvidia-docker/issues/854
5+
6+
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
7+
. "$script_dir/pkg_helpers.bash"
8+
9+
echo "Build Settings:"
10+
echo "CU_VERSION: $CU_VERSION" # e.g. cu100
11+
echo "D2_VERSION_SUFFIX: $D2_VERSION_SUFFIX" # e.g. +cu100 or ""
12+
echo "PYTHON_VERSION: $PYTHON_VERSION" # e.g. 3.6
13+
echo "PYTORCH_VERSION: $PYTORCH_VERSION" # e.g. 1.4
14+
15+
setup_cuda
16+
setup_wheel_python
17+
18+
export TORCH_VERSION_SUFFIX="+$CU_VERSION"
19+
if [[ "$CU_VERSION" == "cu101" ]]; then
20+
export TORCH_VERSION_SUFFIX=""
21+
fi
22+
pip_install pip numpy -U
23+
pip_install "torch==$PYTORCH_VERSION$TORCH_VERSION_SUFFIX" \
24+
-f https://download.pytorch.org/whl/$CU_VERSION/torch_stable.html
25+
26+
# use separate directories to allow parallel build
27+
BASE_BUILD_DIR=build/$CU_VERSION/$PYTHON_VERSION
28+
python setup.py \
29+
build -b $BASE_BUILD_DIR \
30+
bdist_wheel -b $BASE_BUILD_DIR/build_dist -d wheels/$CU_VERSION

dev/packaging/gen_wheel_index.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash -e
2+
3+
4+
root=$1
5+
if [[ -z "$root" ]]; then
6+
echo "Usage: ./gen_wheel_index.sh /path/to/wheels"
7+
exit
8+
fi
9+
10+
index=$root/index.html
11+
12+
cd "$root"
13+
for cu in cpu cu92 cu100 cu101; do
14+
cd $cu
15+
for whl in *.whl; do
16+
echo "<a href=\"$whl\">$whl</a><br>"
17+
done > index.html
18+
cd "$root"
19+
done
20+
21+
for whl in $(find . -type f -name '*.whl' -printf '%P\n' | sort); do
22+
echo "<a href=\"$whl\">$whl</a><br>"
23+
done > "$index"
24+

dev/packaging/pkg_helpers.bash

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash -e
2+
3+
# Function to retry functions that sometimes timeout or have flaky failures
4+
retry () {
5+
$* || (sleep 1 && $*) || (sleep 2 && $*) || (sleep 4 && $*) || (sleep 8 && $*)
6+
}
7+
# Install with pip a bit more robustly than the default
8+
pip_install() {
9+
retry pip install --progress-bar off "$@"
10+
}
11+
12+
13+
setup_cuda() {
14+
# Now work out the CUDA settings
15+
# Like other torch domain libraries, we choose common GPU architectures only.
16+
export FORCE_CUDA=1
17+
case "$CU_VERSION" in
18+
cu101)
19+
export CUDA_HOME=/usr/local/cuda-10.1/
20+
export TORCH_CUDA_ARCH_LIST="3.5;3.7;5.0;5.2;6.0+PTX;6.1+PTX;7.0+PTX;7.5+PTX"
21+
;;
22+
cu100)
23+
export CUDA_HOME=/usr/local/cuda-10.0/
24+
export TORCH_CUDA_ARCH_LIST="3.5;3.7;5.0;5.2;6.0+PTX;6.1+PTX;7.0+PTX;7.5+PTX"
25+
;;
26+
cu92)
27+
export CUDA_HOME=/usr/local/cuda-9.2/
28+
export TORCH_CUDA_ARCH_LIST="3.5;3.7;5.0;5.2;6.0+PTX;6.1+PTX;7.0+PTX"
29+
;;
30+
cpu)
31+
unset FORCE_CUDA
32+
export CUDA_VISIBLE_DEVICES=
33+
;;
34+
*)
35+
echo "Unrecognized CU_VERSION=$CU_VERSION"
36+
exit 1
37+
;;
38+
esac
39+
}
40+
41+
setup_wheel_python() {
42+
case "$PYTHON_VERSION" in
43+
3.6) python_abi=cp36-cp36m ;;
44+
3.7) python_abi=cp37-cp37m ;;
45+
3.8) python_abi=cp38-cp38 ;;
46+
*)
47+
echo "Unrecognized PYTHON_VERSION=$PYTHON_VERSION"
48+
exit 1
49+
;;
50+
esac
51+
export PATH="/opt/python/$python_abi/bin:$PATH"
52+
}

docs/notes/changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Change Log
22

3+
### Releases
4+
See release log at
5+
[https://github.com/facebookresearch/detectron2/releases](https://github.com/facebookresearch/detectron2/releases)
36

4-
### Notable Changes:
7+
### Notable Backward Incompatible Changes:
58

69
* 2019-11-11: `detectron2.data.detection_utils.read_image` transposes images with exif information.
710
* 2019-10-10: initial release.

setup.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def get_version():
2020
version_line = [l.strip() for l in init_py if l.startswith("__version__")][0]
2121
version = version_line.split("=")[-1].strip().strip("'\"")
2222

23-
# Used by CI to build nightly packages. Users should never use it.
24-
# To build a nightly wheel, run:
25-
# FORCE_CUDA=1 BUILD_NIGHTLY=1 TORCH_CUDA_ARCH_LIST=All python setup.py bdist_wheel
23+
# The following is used to build release packages.
24+
# Users should never use it.
25+
suffix = os.getenv("D2_VERSION_SUFFIX", "")
26+
version = version + suffix
2627
if os.getenv("BUILD_NIGHTLY", "0") == "1":
2728
from datetime import datetime
2829

@@ -52,7 +53,9 @@ def get_extensions():
5253
extra_compile_args = {"cxx": []}
5354
define_macros = []
5455

55-
if (torch.cuda.is_available() and CUDA_HOME is not None) or os.getenv("FORCE_CUDA", "0") == "1":
56+
if (
57+
torch.cuda.is_available() and CUDA_HOME is not None and os.path.isdir(CUDA_HOME)
58+
) or os.getenv("FORCE_CUDA", "0") == "1":
5659
extension = CUDAExtension
5760
sources += source_cuda
5861
define_macros += [("WITH_CUDA", None)]
@@ -95,18 +98,20 @@ def get_model_zoo_configs() -> List[str]:
9598
path.dirname(path.realpath(__file__)), "detectron2", "model_zoo", "configs"
9699
)
97100
# Symlink the config directory inside package to have a cleaner pip install.
98-
if path.exists(destination):
99-
# Remove stale symlink/directory from a previous build.
101+
102+
# Remove stale symlink/directory from a previous build.
103+
if path.exists(source_configs_dir):
100104
if path.islink(destination):
101105
os.unlink(destination)
102-
else:
106+
elif path.isdir(destination):
103107
shutil.rmtree(destination)
104108

105-
try:
106-
os.symlink(source_configs_dir, destination)
107-
except OSError:
108-
# Fall back to copying if symlink fails: ex. on Windows.
109-
shutil.copytree(source_configs_dir, destination)
109+
if not path.exists(destination):
110+
try:
111+
os.symlink(source_configs_dir, destination)
112+
except OSError:
113+
# Fall back to copying if symlink fails: ex. on Windows.
114+
shutil.copytree(source_configs_dir, destination)
110115

111116
config_paths = glob.glob("configs/**/*.yaml", recursive=True)
112117
return config_paths
@@ -124,7 +129,7 @@ def get_model_zoo_configs() -> List[str]:
124129
python_requires=">=3.6",
125130
install_requires=[
126131
"termcolor>=1.1",
127-
"Pillow==6.2.2", # torchvision currently does not work with Pillow 7
132+
"Pillow", # you can also use pillow-simd for better performance
128133
"yacs>=0.1.6",
129134
"tabulate",
130135
"cloudpickle",

0 commit comments

Comments
 (0)