From 9ba16d6d9252fd4d820fd1317a41af6bd9aefd23 Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Wed, 5 Jun 2024 21:00:30 -0700 Subject: [PATCH] add linux and windows cpu tests Summary: Pull Request resolved: https://github.com/facebookresearch/detectron2/pull/5299 add linux and windows cpu tests from circleci Reviewed By: wat3rBro Differential Revision: D58021661 fbshipit-source-id: 768df812f31520d30354db59a6566c9281130884 --- .circleci/config.yml | 271 ------------------ .circleci/import-tests.sh | 16 -- .../actions/install_detectron2_win/action.yml | 15 + .../actions/install_windows_dep/action.yml | 24 ++ .github/actions/run_unittests_win/action.yml | 8 + .github/workflows/workflow.yml | 101 ++++++- 6 files changed, 147 insertions(+), 288 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100755 .circleci/import-tests.sh create mode 100644 .github/actions/install_detectron2_win/action.yml create mode 100644 .github/actions/install_windows_dep/action.yml create mode 100644 .github/actions/run_unittests_win/action.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 9a2148c3c8..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,271 +0,0 @@ -version: 2.1 - -# ------------------------------------------------------------------------------------- -# Environments to run the jobs in -# ------------------------------------------------------------------------------------- -cpu: &cpu - machine: - image: ubuntu-2004:202107-02 - resource_class: medium - -gpu: &gpu - machine: - # NOTE: use a cuda version that's supported by all our pytorch versions - image: ubuntu-1604-cuda-11.1:202012-01 - resource_class: gpu.nvidia.small - -windows-cpu: &windows_cpu - 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 - -version_parameters: &version_parameters - parameters: - pytorch_version: - type: string - torchvision_version: - type: string - pytorch_index: - type: string - # use test wheels index to have access to RC wheels - # https://download.pytorch.org/whl/test/torch_test.html - default: "https://download.pytorch.org/whl/torch_stable.html" - python_version: # NOTE: only affect linux - type: string - default: '3.8.6' - - environment: - PYTORCH_VERSION: << parameters.pytorch_version >> - TORCHVISION_VERSION: << parameters.torchvision_version >> - PYTORCH_INDEX: << parameters.pytorch_index >> - PYTHON_VERSION: << parameters.python_version>> - # point datasets to ~/.torch so it's cached in CI - DETECTRON2_DATASETS: ~/.torch/datasets - -# ------------------------------------------------------------------------------------- -# 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 - -add_ssh_keys: &add_ssh_keys - # https://circleci.com/docs/2.0/add-ssh-key/ - - add_ssh_keys: - fingerprints: - - "e4:13:f2:22:d4:49:e8:e4:57:5a:ac:20:2f:3f:1f:ca" - -install_python: &install_python - - run: - name: Install Python - working_directory: ~/ - command: | - # upgrade pyenv - cd /opt/circleci/.pyenv/plugins/python-build/../.. && git pull && cd - - pyenv install -s $PYTHON_VERSION - pyenv global $PYTHON_VERSION - python --version - which python - pip install --upgrade pip - -setup_venv: &setup_venv - - run: - name: Setup Virtual Env - working_directory: ~/ - command: | - python -m venv ~/venv - echo ". ~/venv/bin/activate" >> $BASH_ENV - . ~/venv/bin/activate - python --version - which python - which pip - pip install --upgrade pip - -setup_venv_win: &setup_venv_win - - run: - name: Setup Virtual Env for Windows - command: | - pip install virtualenv - python -m virtualenv env - .\env\Scripts\activate - python --version - which python - which pip - -install_linux_dep: &install_linux_dep - - run: - name: Install Dependencies - command: | - # disable crash coredump, so unittests fail fast - sudo systemctl stop apport.service - # install from github to get latest; install iopath first since fvcore depends on it - pip install --progress-bar off -U 'git+https://github.com/facebookresearch/iopath' - pip install --progress-bar off -U 'git+https://github.com/facebookresearch/fvcore' - # Don't use pytest-xdist: cuda tests are unstable under multi-process workers. - # Don't use opencv 4.7.0.68: https://github.com/opencv/opencv-python/issues/765 - pip install --progress-bar off ninja opencv-python-headless!=4.7.0.68 pytest tensorboard pycocotools onnx - pip install --progress-bar off torch==$PYTORCH_VERSION -f $PYTORCH_INDEX - if [[ "$TORCHVISION_VERSION" == "master" ]]; then - pip install git+https://github.com/pytorch/vision.git - else - pip install --progress-bar off torchvision==$TORCHVISION_VERSION -f $PYTORCH_INDEX - fi - - python -c 'import torch; print("CUDA:", torch.cuda.is_available())' - gcc --version - -install_detectron2: &install_detectron2 - - run: - name: Install Detectron2 - command: | - # Remove first, in case it's in the CI cache - pip uninstall -y detectron2 - - pip install --progress-bar off -e .[all] - python -m detectron2.utils.collect_env - ./datasets/prepare_for_tests.sh - -run_unittests: &run_unittests - - run: - name: Run Unit Tests - command: | - pytest -sv --durations=15 tests # parallel causes some random failures - -uninstall_tests: &uninstall_tests - - run: - name: Run Tests After Uninstalling - command: | - pip uninstall -y detectron2 - # Remove built binaries - rm -rf build/ detectron2/*.so - # Tests that code is importable without installation - PYTHONPATH=. ./.circleci/import-tests.sh - - -# ------------------------------------------------------------------------------------- -# Jobs to run -# ------------------------------------------------------------------------------------- -jobs: - linux_cpu_tests: - <<: *cpu - <<: *version_parameters - - working_directory: ~/detectron2 - - steps: - - checkout - - # Cache the venv directory that contains python, dependencies, and checkpoints - # Refresh the key when dependencies should be updated (e.g. when pytorch releases) - - restore_cache: - keys: - - cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20210827 - - - <<: *install_python - - <<: *install_linux_dep - - <<: *install_detectron2 - - <<: *run_unittests - - <<: *uninstall_tests - - - save_cache: - paths: - - /opt/circleci/.pyenv - - ~/.torch - key: cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20210827 - - - linux_gpu_tests: - <<: *gpu - <<: *version_parameters - - working_directory: ~/detectron2 - - steps: - - checkout - - - restore_cache: - keys: - - cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20210827 - - - <<: *install_python - - <<: *install_linux_dep - - <<: *install_detectron2 - - <<: *run_unittests - - <<: *uninstall_tests - - - save_cache: - paths: - - /opt/circleci/.pyenv - - ~/.torch - key: cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20210827 - - windows_cpu_build: - <<: *windows_cpu - <<: *version_parameters - steps: - - <<: *add_ssh_keys - - checkout - - <<: *setup_venv_win - - # Cache the env directory that contains dependencies - - restore_cache: - keys: - - cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20210404 - - - 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 onnx - pip install -U git+https://github.com/facebookresearch/iopath - pip install -U git+https://github.com/facebookresearch/fvcore - pip install torch==$env:PYTORCH_VERSION torchvision==$env:TORCHVISION_VERSION -f $env:PYTORCH_INDEX - - - save_cache: - paths: - - env - key: cache-{{ arch }}-<< parameters.pytorch_version >>-{{ .Branch }}-20210404 - - - <<: *install_detectron2 - # TODO: unittest fails for now - -workflows: - version: 2 - regular_test: - jobs: - - linux_cpu_tests: - name: linux_cpu_tests_pytorch1.10 - pytorch_version: '1.10.0+cpu' - torchvision_version: '0.11.1+cpu' - - linux_gpu_tests: - name: linux_gpu_tests_pytorch1.8 - pytorch_version: '1.8.1+cu111' - torchvision_version: '0.9.1+cu111' - - linux_gpu_tests: - name: linux_gpu_tests_pytorch1.9 - pytorch_version: '1.9+cu111' - torchvision_version: '0.10+cu111' - - linux_gpu_tests: - name: linux_gpu_tests_pytorch1.10 - pytorch_version: '1.10+cu111' - torchvision_version: '0.11.1+cu111' - - linux_gpu_tests: - name: linux_gpu_tests_pytorch1.10_python39 - pytorch_version: '1.10+cu111' - torchvision_version: '0.11.1+cu111' - python_version: '3.9.6' - - windows_cpu_build: - pytorch_version: '1.10+cpu' - torchvision_version: '0.11.1+cpu' diff --git a/.circleci/import-tests.sh b/.circleci/import-tests.sh deleted file mode 100755 index 8e8deb6ad6..0000000000 --- a/.circleci/import-tests.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -e -# Copyright (c) Facebook, Inc. and its affiliates. - -# Test that import works without building detectron2. - -# Check that _C is not importable -python -c "from detectron2 import _C" > /dev/null 2>&1 && { - echo "This test should be run without building detectron2." - exit 1 -} - -# Check that other modules are still importable, even when _C is not importable -python -c "from detectron2 import modeling" -python -c "from detectron2 import modeling, data" -python -c "from detectron2 import evaluation, export, checkpoint" -python -c "from detectron2 import utils, engine" diff --git a/.github/actions/install_detectron2_win/action.yml b/.github/actions/install_detectron2_win/action.yml new file mode 100644 index 0000000000..d7f796509a --- /dev/null +++ b/.github/actions/install_detectron2_win/action.yml @@ -0,0 +1,15 @@ +name: "Install Detectron2" +runs: + using: composite + steps: + - name: Install Detectron2 + shell: bash + run: | + # Remove first, in case it's in the CI cache + pip uninstall -y detectron2 + + pip install --progress-bar off -e .[all] + python -m detectron2.utils.collect_env + + # TODO: this command fails because windows does not have wget + # ./datasets/prepare_for_tests.sh diff --git a/.github/actions/install_windows_dep/action.yml b/.github/actions/install_windows_dep/action.yml new file mode 100644 index 0000000000..ca5a224c9a --- /dev/null +++ b/.github/actions/install_windows_dep/action.yml @@ -0,0 +1,24 @@ +name: "Install Dependencies" +inputs: + torch-version: + description: torch version to install + torchvision-version: + description: torch vision version to install, version number or "master" + pytorch-index: + description: where to install torch from + required: false + default: "https://download.pytorch.org/whl/torch_stable.html" + # use test wheels index to have access to RC wheels + # https://download.pytorch.org/whl/test/torch_test.html +runs: + using: composite + steps: + - name: Install Dependencies + shell: bash + run: | + 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 onnx + pip install -U git+https://github.com/facebookresearch/iopath + pip install -U git+https://github.com/facebookresearch/fvcore + pip install torch==${{inputs.torch-version}} torchvision==${{inputs.torchvision-version}} -f ${{inputs.pytorch-index}} diff --git a/.github/actions/run_unittests_win/action.yml b/.github/actions/run_unittests_win/action.yml new file mode 100644 index 0000000000..0f8543a415 --- /dev/null +++ b/.github/actions/run_unittests_win/action.yml @@ -0,0 +1,8 @@ +name: "Run Unit Tests" +runs: + using: composite + steps: + - name: Run Unit Tests + shell: bash + run: | + echo TODO: unittest fails for now diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 18de64fa38..37a2637fc8 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -117,7 +117,7 @@ jobs: path: | ${{ env.pythonLocation }}/lib/python3.8/site-packages ~/.torch - key: ${{ runner.os }}-torch${{ matrix.torch }}-${{ hashFiles('setup.py') }}-20210827 + key: ${{ runner.os }}-torch-gpu${{ matrix.torch }}-${{ hashFiles('setup.py') }}-20210827 - name: Install GPU Dependencies uses: ./.github/actions/install_linux_gpu_dep @@ -140,3 +140,102 @@ jobs: - name: Run Tests After Uninstalling uses: ./.github/actions/uninstall_tests + + linux_cpu_tests: + runs-on: ubuntu-latest + # run on PRs, or commits to facebookresearch (not internal) + if: ${{ github.repository_owner == 'facebookresearch' || github.event_name == 'pull_request' }} + strategy: + fail-fast: false + matrix: + torch: ["1.13.1", "2.2.2"] + include: + - torch: "1.13.1" + torchvision: "0.14.1" + - torch: "2.2.2" + torchvision: "0.17.2" + env: + PYTORCH_INDEX: "https://download.pytorch.org/whl/cu118" + DETECTRON2_DATASETS: ~/.torch/datasets + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Cache dependencies + uses: actions/cache@v2 + id: load-cache + with: + path: | + ${{ env.pythonLocation }}/lib/python3.8/site-packages + ~/.torch + key: ${{ runner.os }}-torch${{ matrix.torch }}-${{ hashFiles('setup.py') }}-20210827 + + - name: Install Dependencies + uses: ./.github/actions/install_linux_dep + if: steps.load-cache.outputs.cache-hit != 'true' + with: + torch-version: ${{matrix.torch}} + torchvision-version: ${{matrix.torchvision}} + pytorch-index: $PYTORCH_INDEX + + - name: Install Detectron2 + uses: ./.github/actions/install_detectron2 + + - name: Run Unit Tests + uses: ./.github/actions/run_unittests + + - name: Run Tests After Uninstalling + uses: ./.github/actions/uninstall_tests + + windows_cpu_tests: + runs-on: windows-latest + # run on PRs, or commits to facebookresearch (not internal) + if: ${{ github.repository_owner == 'facebookresearch' || github.event_name == 'pull_request' }} + strategy: + fail-fast: false + matrix: + torch: ["1.13.1", "2.2.2"] + include: + - torch: "1.13.1" + torchvision: "0.14.1" + - torch: "2.2.2" + torchvision: "0.17.2" + env: + PYTORCH_INDEX: "https://download.pytorch.org/whl/cu118" + DETECTRON2_DATASETS: ~/.torch/datasets + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Cache dependencies + uses: actions/cache@v2 + id: load-cache + with: + path: | + ${{ env.pythonLocation }}\Lib\site-packages + ~\.torch + key: ${{ runner.os }}-torch${{ matrix.torch }}-${{ hashFiles('setup.py') }}-20210404 + + - name: Install Dependencies + uses: ./.github/actions/install_windows_dep + if: steps.load-cache.outputs.cache-hit != 'true' + with: + torch-version: ${{matrix.torch}} + torchvision-version: ${{matrix.torchvision}} + pytorch-index: $PYTORCH_INDEX + + - name: Install Detectron2 + uses: ./.github/actions/install_detectron2_win + + - name: Run Unit Tests + uses: ./.github/actions/run_unittests_win