Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 68 additions & 91 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,55 @@ cpu: &cpu

gpu: &gpu
machine:
image: ubuntu-1604:201903-01
docker_layer_caching: true
image: ubuntu-1604-cuda-10.1:201909-23
resource_class: gpu.small

windows-cpu: &windows_cpu
machine:
resource_class: windows.medium
image: windows-server-2019-vs2019:stable
shell: powershell.exe
machine:
resource_class: windows.medium
image: windows-server-2019-vs2019:stable
shell: powershell.exe

# windows-gpu: &windows_gpu
# machine:
# resource_class: windows.gpu.nvidia.medium
# image: windows-server-2019-nvidia:stable

pytorch_parameters: &pytorch_parameters
parameters:
pytorch_version:
type: string
default: "1.6"
torchvision_version:
type: string
default: "0.7"

environment:
PYTORCH_VERSION: << parameters.pytorch_version >>
TORCHVISION_VERSION: << parameters.torchvision_version >>

# -------------------------------------------------------------------------------------
# Re-usable commands
# -------------------------------------------------------------------------------------
# install_nvidia_driver: &install_nvidia_driver
# - run:
# name: Install nvidia driver
# working_directory: ~/
# command: |
# wget -q 'https://s3.amazonaws.com/ossci-linux/nvidia_driver/NVIDIA-Linux-x86_64-430.40.run'
# sudo /bin/bash ./NVIDIA-Linux-x86_64-430.40.run -s --no-drm
# nvidia-smi

install_python: &install_python
- run:
name: Install Python
working_directory: ~/
command: |
pyenv install 3.6.1
pyenv global 3.6.1
pyenv install -s 3.6.8
pyenv global 3.6.8
python --version
which python
pip install --upgrade pip setuptools==49.6.0

setup_venv: &setup_venv
- run:
Expand All @@ -60,50 +84,23 @@ setup_venv_win: &setup_venv_win
which python
which pip

install_dep: &install_dep
install_linux_dep: &install_linux_dep
- run:
name: Install Dependencies
command: |
pip install --progress-bar off -U 'git+https://github.com/facebookresearch/fvcore'
pip install --progress-bar off opencv-python pytest-xdist
pip install --progress-bar off torch torchvision

install_dep_win: &install_dep_win
- run:
name: Install Dependencies on Windows
command: |
pip install certifi --ignore-installed
pip install numpy
pip install cython
pip install pycocotools>=2.0.2
pip install -U git+https://github.com/facebookresearch/fvcore
pip install opencv-python pytest-xdist
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
pip install --progress-bar off ninja opencv-python-headless pytest-xdist tensorboard pycocotools
pip install --progress-bar off torch==$PYTORCH_VERSION torchvision==$TORCHVISION_VERSION -f https://download.pytorch.org/whl/cu101/torch_stable.html
python -c 'import torch; print("CUDA:", torch.cuda.is_available())'
gcc --version

install_detectron2: &install_detectron2
- run:
name: Install Detectron2
command: |
gcc --version
pip install -U --progress-bar off -e .[dev]
python -m detectron2.utils.collect_env

install_detectron2_win: &install_detectron2_win
- run:
name: Install Detectron2 on Windows
command: |
pip install -U --progress-bar off -e .[dev]
pip install --progress-bar off -e .
python -m detectron2.utils.collect_env

install_nvidia_driver: &install_nvidia_driver
- run:
name: Install nvidia driver
working_directory: ~/
command: |
wget -q 'https://s3.amazonaws.com/ossci-linux/nvidia_driver/NVIDIA-Linux-x86_64-430.40.run'
sudo /bin/bash ./NVIDIA-Linux-x86_64-430.40.run -s --no-drm
nvidia-smi

run_unittests: &run_unittests
- run:
name: Run Unit Tests
Expand All @@ -116,6 +113,7 @@ run_unittests: &run_unittests
jobs:
linux_cpu_tests:
<<: *cpu
<<: *pytorch_parameters

working_directory: ~/detectron2

Expand All @@ -126,92 +124,71 @@ jobs:
# Cache the venv directory that contains dependencies
- restore_cache:
keys:
- cache-key-{{ .Branch }}-ID-20200730
- cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20200907

- <<: *install_dep
- <<: *install_linux_dep

- save_cache:
paths:
- ~/venv
key: cache-key-{{ .Branch }}-ID-20200730
key: cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20200907

- <<: *install_detectron2
- <<: *run_unittests

linux_gpu_tests:
<<: *gpu

parameters:
pytorch_version:
type: string
torchvision_version:
type: string

environment:
PYTORCH_VERSION: << parameters.pytorch_version >>
TORCHVISION_VERSION: << parameters.torchvision_version >>
<<: *pytorch_parameters

working_directory: ~/detectron2

steps:
- checkout
- <<: *install_nvidia_driver

- run:
name: Install nvidia-docker
working_directory: ~/
command: |
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-docker2
# reload the docker daemon configuration
sudo pkill -SIGHUP dockerd
# Cache the directory that contains python and dependencies
- restore_cache:
keys:
- cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20200907

- run:
name: Launch docker
working_directory: ~/detectron2/docker
command: |
nvidia-docker build -t detectron2:v0 -f Dockerfile-circleci --build-arg PYTORCH_VERSION=$PYTORCH_VERSION --build-arg TORCHVISION_VERSION=$TORCHVISION_VERSION .
nvidia-docker run -itd --name d2 detectron2:v0
docker exec -it d2 nvidia-smi
- <<: *install_python
- <<: *install_linux_dep

- run:
name: Build Detectron2
command: |
docker exec -it d2 pip install 'git+https://github.com/facebookresearch/fvcore'
docker cp ~/detectron2 d2:/detectron2
# This will build d2 for the target GPU arch only
# Install with --editable so that pytest can run tests in the source directory
docker exec -it d2 pip install --progress-bar off -e /detectron2
docker exec -it d2 python3 -m detectron2.utils.collect_env
docker exec -it d2 python3 -c 'import torch; assert(torch.cuda.is_available())'
- save_cache:
paths:
- /opt/circleci/.pyenv
key: cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20200907

- run:
name: Run Unit Tests
command: |
docker exec -e CIRCLECI=true -it d2 python3 -m pytest -n 2 -v /detectron2/tests
- <<: *install_detectron2
- <<: *run_unittests

windows_cpu_tests:
<<: *windows_cpu
<<: *pytorch_parameters
steps:
- checkout
- <<: *setup_venv_win

# Cache the env directory that contains dependencies
- restore_cache:
keys:
- cache-key-{{ .Branch }}-ID-20200735
- cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20200907

- <<: *install_dep_win
- run:
name: Install Dependencies
command: |
pip install certifi --ignore-installed # required on windows to workaround some cert issue
pip install numpy cython # required on windows before pycocotools
pip install opencv-python-headless pytest-xdist pycocotools tensorboard
pip install -U git+https://github.com/facebookresearch/fvcore
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

- save_cache:
paths:
- env
key: cache-key-{{ .Branch }}-ID-20200735
key: cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20200907

- <<: *install_detectron2_win
- <<: *install_detectron2
# TODO: unittest fails for now

workflows:
version: 2
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ jobs:

- name: Install dependencies
run: |
brew install ninja
python -m pip install -U pip setuptools==49
python -m pip install opencv-python-headless onnx pytest-xdist
python -m pip install ninja opencv-python-headless onnx pytest-xdist
python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
python -m pip install -U 'git+https://github.com/facebookresearch/fvcore'

Expand Down
8 changes: 4 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ Two possibilities:
you need to either install a different build of PyTorch (or build by yourself)
to match your local CUDA installation, or install a different version of CUDA to match PyTorch.

* PyTorch/torchvision/Detectron2 is not built for the correct GPU architecture (aka. compute compatibility).
* PyTorch/torchvision/Detectron2 is not built for the correct GPU architecture (aka. compute capability).

The compute compatibility included by PyTorch/detectron2/torchvision is available in the "architecture flags" in
The architecture included by PyTorch/detectron2/torchvision is available in the "architecture flags" in
`python -m detectron2.utils.collect_env`. It must include
the compute compatibility of your GPU, which can be found at [developer.nvidia.com/cuda-gpus](https://developer.nvidia.com/cuda-gpus).
the architecture of your GPU, which can be found at [developer.nvidia.com/cuda-gpus](https://developer.nvidia.com/cuda-gpus).

If you're using pre-built PyTorch/detectron2/torchvision, they have included support for most popular GPUs already.
If not supported, you need to build them from source.

When building detectron2/torchvision from source, they detect the GPU device and build for only the device.
This means the compiled code may not work on a different GPU device.
To recompile them for the correct compatiblity, remove all installed/compiled files,
To recompile them for the correct architecture, remove all installed/compiled files,
and rebuild them with the `TORCH_CUDA_ARCH_LIST` environment variable set properly.
For example, `export TORCH_CUDA_ARCH_LIST=6.0,7.0` makes it compile for both P100s and V100s.
</details>
Expand Down
1 change: 0 additions & 1 deletion detectron2/evaluation/coco_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def process(self, inputs, outputs):
for input, output in zip(inputs, outputs):
prediction = {"image_id": input["image_id"]}

# TODO this is ugly
if "instances" in output:
instances = output["instances"].to(self._cpu_device)
prediction["instances"] = instances_to_coco_json(instances, input["image_id"])
Expand Down
8 changes: 8 additions & 0 deletions detectron2/utils/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,11 @@ def collect_env_info():
from detectron2.utils.collect_env import collect_env_info

print(collect_env_info())
if torch.cuda.is_available():
for k in range(torch.cuda.device_count()):
device = f"cuda:{k}"
try:
x = torch.tensor([1, 2.0], dtype=torch.float32)
x = x.to(device)
except Exception:
print(f"Unable to copy tensor to device={device}")
17 changes: 0 additions & 17 deletions docker/Dockerfile-circleci

This file was deleted.