From 19d4eba866ea809a593bbcfe019730c405481378 Mon Sep 17 00:00:00 2001
From: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
Date: Wed, 7 Sep 2022 20:24:11 +0800
Subject: [PATCH] [Refactor] Update Github Action CI and CircleCI (#512)

* [CI] Update Github Action CI and CircleCI

* clear outdated commands in CI

* clear outdated commands in CI

* add '-r' when installing packages from txt

* update

* update circleci

* fix mismatch conflicts

* update

* install system dependencies

* update

* set env

* fix ut

* update cuda version on Windows

* update push action
---
 .circleci/scripts/get_mmcv_var.sh             |  19 --
 .circleci/test.yml                            |  66 +++---
 .github/workflows/build.yml                   | 221 ------------------
 .github/workflows/lint.yml                    |   2 +-
 .github/workflows/merge_stage_test.yml        |  92 ++++----
 .github/workflows/pr_stage_test.yml           |  76 +++---
 .github/workflows/scripts/get_mmcv_var.sh     |  19 --
 .../test_utils/test_dl_utils/test_get_env.py  |   2 +-
 8 files changed, 106 insertions(+), 391 deletions(-)
 delete mode 100755 .circleci/scripts/get_mmcv_var.sh
 delete mode 100644 .github/workflows/build.yml
 delete mode 100755 .github/workflows/scripts/get_mmcv_var.sh

diff --git a/.circleci/scripts/get_mmcv_var.sh b/.circleci/scripts/get_mmcv_var.sh
deleted file mode 100755
index 552ff871..00000000
--- a/.circleci/scripts/get_mmcv_var.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-
-TORCH=$1
-CUDA=$2
-
-# 10.2 -> cu102
-MMCV_CUDA="cu`echo ${CUDA} | tr -d '.'`"
-
-# MMCV only provides pre-compiled packages for torch 1.x.0
-# which works for any subversions of torch 1.x.
-# We force the torch version to be 1.x.0 to ease package searching
-# and avoid unnecessary rebuild during MMCV's installation.
-TORCH_VER_ARR=(${TORCH//./ })
-TORCH_VER_ARR[2]=0
-printf -v MMCV_TORCH "%s." "${TORCH_VER_ARR[@]}"
-MMCV_TORCH=${MMCV_TORCH%?}  # Remove the last dot
-
-echo "export MMCV_CUDA=${MMCV_CUDA}" >> $BASH_ENV
-echo "export MMCV_TORCH=${MMCV_TORCH}" >> $BASH_ENV
diff --git a/.circleci/test.yml b/.circleci/test.yml
index a3694f93..7302a187 100644
--- a/.circleci/test.yml
+++ b/.circleci/test.yml
@@ -42,18 +42,17 @@ jobs:
       - run:
           name: Upgrade pip
           command: |
-            python -V
-            python -m pip install pip --upgrade
-            python -m pip --version
+            pip install pip --upgrade
+            pip --version
       - run:
-          name: Install mmengine dependencies
-          command: python -m pip install -r requirements.txt
+          name: Build MMEngine from source
+          command: pip install -e . -v
       - run:
-          name: Build and install
-          command: python -m pip install -e .
+          name: Install unit tests dependencies
+          command: pip install -r requirements/tests.txt
       - run:
           name: Run unit tests
-          command: python -m pytest tests/test_config tests/test_registry tests/test_fileio tests/test_logging tests/test_utils --ignore=tests/test_utils/test_dl_utils
+          command: pytest tests/test_config tests/test_registry tests/test_fileio tests/test_logging tests/test_utils --ignore=tests/test_utils/test_dl_utils
 
   build_cpu:
     parameters:
@@ -70,11 +69,6 @@ jobs:
     resource_class: large
     steps:
       - checkout
-      - run:
-          name: Get MMCV_TORCH as environment variables
-          command: |
-            . .circleci/scripts/get_mmcv_var.sh << parameters.torch >>
-            source $BASH_ENV
       - run:
           name: Install Libraries
           command: |
@@ -83,28 +77,26 @@ jobs:
       - run:
           name: Configure Python & pip
           command: |
-            python -m pip install --upgrade pip
-            python -m pip install wheel
+            pip install --upgrade pip
+            pip install wheel
       - run:
           name: Install PyTorch
-          command: |
-            python -V
-            python -m pip install torch==<< parameters.torch >>+cpu torchvision==<< parameters.torchvision >>+cpu -f https://download.pytorch.org/whl/torch_stable.html
+          command: pip install torch==<< parameters.torch >>+cpu torchvision==<< parameters.torchvision >>+cpu -f https://download.pytorch.org/whl/torch_stable.html
       - run:
-          name: Install MMEngine dependencies
-          # python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html
-          command: |
-            python -m pip install -r requirements.txt
+          name: Build MMEngine from source
+          command: pip install -e . -v
       - run:
-          name: Build and install
+          name: Install unit tests dependencies
           command: |
-            python -m pip install -e .
+            pip install -r requirements/tests.txt
+            pip install openmim
+            mim install 'mmcv>=2.0.0rc1'
       - run:
           name: Run unittests
           command: |
-            python -m coverage run --branch --source mmengine -m pytest tests/
-            python -m coverage xml
-            python -m coverage report -m
+            coverage run --branch --source mmengine -m pytest tests/
+            coverage xml
+            coverage report -m
 
   build_cuda:
     parameters:
@@ -122,25 +114,21 @@ jobs:
     resource_class: gpu.nvidia.small
     steps:
       - checkout
-      - run:
-          name: Get MMCV_TORCH and MMCV_CUDA as environment variables
-          command: |
-            . .circleci/scripts/get_mmcv_var.sh << parameters.torch >> << parameters.cuda >>
-            source $BASH_ENV
       - run:
           name: Build Docker image
           command: |
             docker build .circleci/docker -t mmengine:gpu --build-arg PYTORCH=<< parameters.torch >> --build-arg CUDA=<< parameters.cuda >> --build-arg CUDNN=<< parameters.cudnn >>
             docker run --gpus all -t -d -v /home/circleci/project:/mmengine -w /mmengine --name mmengine mmengine:gpu
       - run:
-          name: Install mmengine dependencies
-          # docker exec mmengine pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/${MMCV_CUDA}/torch${MMCV_TORCH}/index.html
+          name: Build MMEngine from source
           command: |
-            docker exec mmengine pip install -r requirements.txt
+            docker exec mmengine pip install -e . -v
       - run:
-          name: Build and install
+          name: Install unit tests dependencies
           command: |
-            docker exec mmengine pip install -e .
+            docker exec mmengine pip install -r requirements/tests.txt
+            docker exec mmengine pip install openmim
+            docker exec mmengine mim install 'mmcv>=2.0.0rc1'
       - run:
           name: Run unittests
           command: |
@@ -180,8 +168,8 @@ workflows:
             - lint
       - build_cpu:
           name: maximum_version_cpu
-          torch: 1.9.0
-          torchvision: 0.10.0
+          torch: 1.12.1
+          torchvision: 0.13.1
           python: 3.9.0
           requires:
             - minimum_version_cpu
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
deleted file mode 100644
index ac6ca166..00000000
--- a/.github/workflows/build.yml
+++ /dev/null
@@ -1,221 +0,0 @@
-name: build
-
-on:
-  push:
-    paths-ignore:
-      - ".dev_scripts/**"
-      - ".github/**.md"
-      - "demo/**"
-      - "docker/**"
-      - "tools/**"
-      - "README.md"
-      - "README_zh-CN.md"
-
-  pull_request:
-    paths-ignore:
-      - ".dev_scripts/**"
-      - ".github/**.md"
-      - "demo/**"
-      - "docker/**"
-      - "docs/**"
-      - "docs_zh-CN/**"
-      - "tools/**"
-      - "README.md"
-      - "README_zh-CN.md"
-
-concurrency:
-  group: ${{ github.workflow }}-${{ github.ref }}
-  cancel-in-progress: true
-
-jobs:
-  build_cpu:
-    runs-on: ubuntu-18.04
-    strategy:
-      matrix:
-        python-version: [3.7]
-        torch: [1.5.1, 1.6.0, 1.7.0, 1.8.0, 1.9.0]
-        include:
-          - torch: 1.5.1
-            torchvision: 0.6.1
-            mmcv: 1.5.0
-          - torch: 1.6.0
-            torchvision: 0.7.0
-            mmcv: 1.6.0
-          - torch: 1.7.0
-            torchvision: 0.8.1
-            mmcv: 1.7.0
-          - torch: 1.8.0
-            torchvision: 0.9.0
-            mmcv: 1.8.0
-          - torch: 1.9.0
-            torchvision: 0.10.0
-            mmcv: 1.9.0
-    steps:
-      - uses: actions/checkout@v2
-      - name: Set up Python ${{ matrix.python-version }}
-        uses: actions/setup-python@v2
-        with:
-          python-version: ${{ matrix.python-version }}
-      - name: Install Pillow
-        run: pip install Pillow==6.2.2
-        if: ${{matrix.torchvision == '0.4.2'}}
-      - name: Install PyTorch
-        run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
-      - name: Install MMCV
-        run: |
-          pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${{matrix.mmcv}}/index.html
-          python -c 'import mmcv; print(mmcv.__version__)'
-      - name: Install unittest dependencies
-        run: |
-          pip install -r requirements/tests.txt -r requirements/optional.txt
-          pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
-          pip install git+https://github.com/cocodataset/panopticapi.git
-      - name: Build and install
-        run: rm -rf .eggs && pip install -e .
-      - name: Run unittests and generate coverage report
-        run: |
-          coverage run --branch --source mmengine -m pytest tests/
-          coverage xml
-          coverage report -m
-
-  build_cuda101:
-    runs-on: ubuntu-18.04
-    container:
-      image: pytorch/pytorch:1.6.0-cuda10.1-cudnn7-devel
-
-    strategy:
-      matrix:
-        python-version: [3.7]
-        torch: [1.5.1+cu101, 1.6.0+cu101, 1.7.0+cu101, 1.8.0+cu101]
-        include:
-          - torch: 1.5.1+cu101
-            torch_version: torch1.5.1
-            torchvision: 0.6.1+cu101
-            mmcv: 1.5.0
-          - torch: 1.6.0+cu101
-            torch_version: torch1.6.0
-            torchvision: 0.7.0+cu101
-            mmcv: 1.6.0
-          - torch: 1.7.0+cu101
-            torch_version: torch1.7.0
-            torchvision: 0.8.1+cu101
-            mmcv: 1.7.0
-          - torch: 1.8.0+cu101
-            torch_version: torch1.8.0
-            torchvision: 0.9.0+cu101
-            mmcv: 1.8.0
-
-    steps:
-      - uses: actions/checkout@v2
-      - name: Set up Python ${{ matrix.python-version }}
-        uses: actions/setup-python@v2
-        with:
-          python-version: ${{ matrix.python-version }}
-      - name: Install system dependencies
-        run: |
-          apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6 python${{matrix.python-version}}-dev
-          apt-get clean
-          rm -rf /var/lib/apt/lists/*
-      - name: Install Pillow
-        run: python -m pip install Pillow==6.2.2
-        if: ${{matrix.torchvision < 0.5}}
-      - name: Install PyTorch
-        run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
-      - name: Install dependencies for compiling onnx when python=3.9
-        run: python -m pip install protobuf && apt-get install libprotobuf-dev protobuf-compiler
-        if: ${{matrix.python-version == '3.9'}}
-      - name: Install mmengine dependencies
-        run: |
-          python -V
-
-      - name: Build and install
-        run: |
-          rm -rf .eggs
-          python setup.py check -m -s
-          TORCH_CUDA_ARCH_LIST=7.0 pip install .
-      - name: Run unittests and generate coverage report
-        run: |
-          coverage run --branch --source mmengine -m pytest tests/
-          coverage xml
-          coverage report -m
-      - name: Upload coverage to Codecov
-        uses: codecov/codecov-action@v1.0.10
-        with:
-          file: ./coverage.xml
-          flags: unittests
-          env_vars: OS,PYTHON
-          name: codecov-umbrella
-          fail_ci_if_error: false
-
-  build_cuda102:
-    runs-on: ubuntu-18.04
-    container:
-      image: pytorch/pytorch:1.9.0-cuda10.2-cudnn7-devel
-
-    strategy:
-      matrix:
-        python-version: [3.6, 3.7, 3.8, 3.9]
-        torch: [1.9.0+cu102]
-        include:
-          - torch: 1.9.0+cu102
-            torch_version: torch1.9.0
-            torchvision: 0.10.0+cu102
-            mmcv: 1.9.0
-
-    steps:
-      - uses: actions/checkout@v2
-      - name: Set up Python ${{ matrix.python-version }}
-        uses: actions/setup-python@v2
-        with:
-          python-version: ${{ matrix.python-version }}
-      # Add ppa source repo for python3.9.
-      - name: Add python3.9 source
-        run: |
-          apt-get update && apt-get install -y software-properties-common
-          add-apt-repository -y ppa:deadsnakes/ppa
-        if: ${{matrix.python-version == '3.9'}}
-      # Install python-dev for some packages which require libpython3.Xm.
-      # Github's setup-python cannot install python3.9-dev, so we have to use apt install.
-      # Set DEBIAN_FRONTEND=noninteractive to avoid some interactions.
-      - name: Install python-dev
-        run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python${{matrix.python-version}}-dev
-      - name: Install system dependencies
-        run: |
-          apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6
-          apt-get clean
-          rm -rf /var/lib/apt/lists/*
-      - name: Install Pillow
-        run: python -m pip install Pillow==6.2.2
-        if: ${{matrix.torchvision < 0.5}}
-      - name: Install PyTorch
-        run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
-      - name: Install dependencies for compiling onnx when python=3.9
-        run: python -m pip install protobuf && apt-get update && apt-get -y install libprotobuf-dev protobuf-compiler cmake
-        if: ${{matrix.python-version == '3.9'}}
-      - name: Install mmengine dependencies
-        run: |
-          python -V
-          python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch${{matrix.mmcv}}/index.html
-          python -m pip install pycocotools
-          python -m pip install -r requirements/tests.txt -r requirements/optional.txt
-          python -m pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
-          python -m pip install git+https://github.com/cocodataset/panopticapi.git
-          python -c 'import mmcv; print(mmcv.__version__)'
-      - name: Build and install
-        run: |
-          rm -rf .eggs
-          python setup.py check -m -s
-          TORCH_CUDA_ARCH_LIST=7.0 pip install .
-      - name: Run unittests and generate coverage report
-        run: |
-          coverage run --branch --source mmengine -m pytest tests/
-          coverage xml
-          coverage report -m
-      - name: Upload coverage to Codecov
-        uses: codecov/codecov-action@v2
-        with:
-          files: ./coverage.xml
-          flags: unittests
-          env_vars: OS,PYTHON
-          name: codecov-umbrella
-          fail_ci_if_error: false
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 0914063e..075baad9 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -24,4 +24,4 @@ jobs:
       - name: Check docstring coverage
         run: |
           pip install interrogate
-          interrogate -v --ignore-init-method --ignore-magic --ignore-module --ignore-nested-functions --ignore-regex "__repr__" --fail-under 95 mmengine
+          interrogate -v --ignore-init-method --ignore-magic --ignore-module --ignore-nested-functions --ignore-regex "__repr__" --fail-under 80 mmengine
diff --git a/.github/workflows/merge_stage_test.yml b/.github/workflows/merge_stage_test.yml
index 8aa60f56..918d446f 100644
--- a/.github/workflows/merge_stage_test.yml
+++ b/.github/workflows/merge_stage_test.yml
@@ -5,6 +5,13 @@ on:
     paths-ignore:
       - ".github/**.md"
       - "docker/**"
+      - "docs/**"
+      - "README.md"
+      - "README_zh-CN.md"
+      - "CONTRIBUTING.md"
+      - "CONTRIBUTING_zh-CN.md"
+      - ".pre-commit-config.yaml"
+      - ".pre-commit-config-zh-cn.yaml"
     branches:
       - main
 
@@ -28,20 +35,17 @@ jobs:
         uses: actions/setup-python@v2
         with:
           python-version: ${{ matrix.python-version }}
-      - name: Get MMCV_TORCH as the environment variable
-        run: . .github/workflows/scripts/get_mmcv_var.sh ${{matrix.torch}}
-        shell: bash
       - name: Upgrade pip
         run: pip install pip --upgrade
       - name: Install PyTorch
         run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
-      # - name: Install MMCV
-      #   run: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html
-      - name: Install other dependencies
+      - name: Build MMEngine from source
+        run: pip install -e . -v
+      - name: Install unit tests dependencies
         run: |
           pip install -r requirements/tests.txt
-      - name: Build and install
-        run: rm -rf .eggs && pip install -e .
+          pip install openmim
+          mim install 'mmcv>=2.0.0rc1'
       - name: Run unittests and generate coverage report
         run: |
           coverage run --branch --source mmengine -m pytest tests/
@@ -77,18 +81,15 @@ jobs:
           python-version: ${{ matrix.python-version }}
       - name: Upgrade pip
         run: pip install pip --upgrade
-      - name: Get MMCV_TORCH as the environment variable
-        run: . .github/workflows/scripts/get_mmcv_var.sh ${{matrix.torch}}
-        shell: bash
       - name: Install PyTorch
         run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
-      # - name: Install MMCV
-      #   run: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html
-      - name: Install other dependencies
+      - name: Build MMEngine from source
+        run: pip install -e . -v
+      - name: Install unit tests dependencies
         run: |
-          pip install -r requirements/tests.txt -r requirements/optional.txt
-      - name: Build and install
-        run: rm -rf .eggs && pip install -e .
+          pip install -r requirements/tests.txt
+          pip install openmim
+          mim install 'mmcv>=2.0.0rc1'
       - name: Run unittests and generate coverage report
         run: |
           coverage run --branch --source mmengine -m pytest tests/
@@ -109,6 +110,8 @@ jobs:
     runs-on: ubuntu-18.04
     container:
       image: pytorch/pytorch:1.8.1-cuda10.2-cudnn7-devel
+    env:
+      MKL_THREADING_LAYER: GNU
     strategy:
       matrix:
         python-version: [3.7]
@@ -122,31 +125,25 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
       - name: Upgrade pip
-        run: python -m pip install pip --upgrade
+        run: pip install pip --upgrade
       - name: Fetch GPG keys
         run: |
           apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
           apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
-      - name: Get MMCV_TORCH and MMCV_CUDA as environment variables
-        run: . .github/workflows/scripts/get_mmcv_var.sh ${{matrix.torch}} ${{matrix.cuda}}
-        shell: bash
-      - name: Install Python-dev
-        run: apt-get update && apt-get install -y python${{matrix.python-version}}-dev
-        if: ${{matrix.python-version != 3.9}}
       - name: Install system dependencies
+        run: apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6
+      - name: Build MMEngine from source
+        run: pip install -e . -v
+      - name: Install unit tests dependencies
         run: |
-          apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6
-      - name: Install dependencies for compiling onnx when python=3.9
-        run: python -m pip install protobuf && apt-get update && apt-get -y install libprotobuf-dev protobuf-compiler cmake
-        if: ${{matrix.python-version == '3.9'}}
-      - name: Install mmengine dependencies
-        # python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/${MMCV_CUDA}/torch${MMCV_TORCH}/index.html
-        run: |
-          python -m pip install -r requirements/tests.txt
-      - name: Build and install
+          pip install -r requirements/tests.txt
+          pip install openmim
+          mim install 'mmcv>=2.0.0rc1'
+      - name: Run unittests and generate coverage report
         run: |
-          python setup.py check -m -s
-          TORCH_CUDA_ARCH_LIST=7.0 python -m pip install -e .
+          coverage run --branch --source mmengine -m pytest tests/
+          coverage xml
+          coverage report -m
 
   build_windows:
     runs-on: ${{ matrix.os }}
@@ -154,7 +151,7 @@ jobs:
       matrix:
         os: [windows-2022]
         python: [3.7]
-        platform: [cpu, cu102]
+        platform: [cpu, cu111]
     steps:
       - uses: actions/checkout@v2
       - name: Set up Python ${{ matrix.python-version }}
@@ -162,18 +159,15 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
       - name: Upgrade pip
-        run: python -m pip install pip --upgrade
-      - name: Install lmdb
-        run: python -m pip install lmdb
+        run: pip install pip --upgrade
       - name: Install PyTorch
-        run: python -m pip install torch==1.8.1+${{matrix.platform}} torchvision==0.9.1+${{matrix.platform}} -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
-      - name: Install mmengine dependencies
-        # python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8/index.html --only-binary mmcv-full
-        run: |
-          python -m pip install -r requirements/tests.txt
-      - name: Build and install
+        run: pip install torch==1.8.1+${{matrix.platform}} torchvision==0.9.1+${{matrix.platform}} -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
+      - name: Build MMEngine from source
+        run: pip install -e . -v
+      - name: Install unit tests dependencies
         run: |
-          python -m pip install -e .
-      - name: Run unittests and generate coverage report
-        run: |
-          pytest tests/
+          pip install -r requirements/tests.txt
+          pip install openmim
+          mim install 'mmcv>=2.0.0rc1'
+      - name: Run unittests
+        run: pytest tests/
diff --git a/.github/workflows/pr_stage_test.yml b/.github/workflows/pr_stage_test.yml
index 034903c1..9a1cb2cb 100644
--- a/.github/workflows/pr_stage_test.yml
+++ b/.github/workflows/pr_stage_test.yml
@@ -6,9 +6,12 @@ on:
       - ".github/**.md"
       - "docker/**"
       - "docs/**"
-      - "docs_zh-CN/**"
       - "README.md"
       - "README_zh-CN.md"
+      - "CONTRIBUTING.md"
+      - "CONTRIBUTING_zh-CN.md"
+      - ".pre-commit-config.yaml"
+      - ".pre-commit-config-zh-cn.yaml"
 
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref }}
@@ -31,18 +34,15 @@ jobs:
           python-version: ${{ matrix.python-version }}
       - name: Upgrade pip
         run: pip install pip --upgrade
-      # - name: Get MMCV_TORCH as the environment variable
-      #   run: . .github/workflows/scripts/get_mmcv_var.sh ${{matrix.torch}}
-        shell: bash
       - name: Install PyTorch
         run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
-      # - name: Install MMCV
-      #   run: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html
-      - name: Install other dependencies
+      - name: Build MMEngine from source
+        run: pip install -e . -v
+      - name: Install unit tests dependencies
         run: |
           pip install -r requirements/tests.txt
-      - name: Build and install
-        run: rm -rf .eggs && pip install -e .
+          pip install openmim
+          mim install 'mmcv>=2.0.0rc1'
       - name: Run unittests and generate coverage report
         run: |
           coverage run --branch --source mmengine -m pytest tests/
@@ -62,6 +62,8 @@ jobs:
     runs-on: ubuntu-18.04
     container:
       image: pytorch/pytorch:1.8.1-cuda10.2-cudnn7-devel
+    env:
+      MKL_THREADING_LAYER: GNU
     strategy:
       matrix:
         python-version: [3.7]
@@ -72,32 +74,25 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
       - name: Upgrade pip
-        run: python -m pip install pip --upgrade
+        run: pip install pip --upgrade
       - name: Fetch GPG keys
         run: |
           apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
           apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
-      # - name: Get MMCV_TORCH and MMCV_CUDA as environment variables
-      #   run: . .github/workflows/scripts/get_mmcv_var.sh ${{matrix.torch}} ${{matrix.cuda}}
-        shell: bash
-      - name: Install Python-dev
-        run: apt-get update && apt-get install -y python${{matrix.python-version}}-dev
-        if: ${{matrix.python-version != 3.9}}
       - name: Install system dependencies
+        run: apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6
+      - name: Build MMEngine from source
+        run: pip install -e . -v
+      - name: Install unit tests dependencies
         run: |
-          apt-get update
-          apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev
-      - name: Install dependencies for compiling onnx when python=3.9
-        run: python -m pip install protobuf && apt-get update && apt-get -y install libprotobuf-dev protobuf-compiler cmake
-        if: ${{matrix.python-version == '3.9'}}
-      - name: Install mmengine dependencies
-        # python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/${MMCV_CUDA}/torch${MMCV_TORCH}/index.html
-        run: |
-          python -m pip install -r requirements/tests.txt
-      - name: Build and install
+          pip install -r requirements/tests.txt
+          pip install openmim
+          mim install 'mmcv>=2.0.0rc1'
+      - name: Run unittests and generate coverage report
         run: |
-          python setup.py check -m -s
-          TORCH_CUDA_ARCH_LIST=7.0 python -m pip install -e .
+          coverage run --branch --source mmengine -m pytest tests/
+          coverage xml
+          coverage report -m
 
   build_windows:
     runs-on: ${{ matrix.os }}
@@ -105,7 +100,7 @@ jobs:
       matrix:
         os: [windows-2022]
         python: [3.7]
-        platform: [cpu, cu102]
+        platform: [cpu, cu111]
     steps:
       - uses: actions/checkout@v2
       - name: Set up Python ${{ matrix.python-version }}
@@ -113,18 +108,15 @@ jobs:
         with:
           python-version: ${{ matrix.python-version }}
       - name: Upgrade pip
-        run: python -m pip install pip --upgrade
-      - name: Install lmdb
-        run: python -m pip install lmdb
+        run: pip install pip --upgrade
       - name: Install PyTorch
-        run: python -m pip install torch==1.8.1+${{matrix.platform}} torchvision==0.9.1+${{matrix.platform}} -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
-      - name: Install mmengine dependencies
-        # python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8/index.html --only-binary mmcv-full
-        run: |
-          python -m pip install -r requirements/tests.txt
-      - name: Build and install
+        run: pip install torch==1.8.1+${{matrix.platform}} torchvision==0.9.1+${{matrix.platform}} -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
+      - name: Build MMEngine from source
+        run: pip install -e .
+      - name: Install unit tests dependencies
         run: |
-          python -m pip install -e .
-      - name: Run unittests and generate coverage report
-        run: |
-          pytest tests/
+          pip install -r requirements/tests.txt
+          pip install openmim
+          mim install 'mmcv>=2.0.0rc1'
+      - name: Run unittests
+        run: pytest tests/
diff --git a/.github/workflows/scripts/get_mmcv_var.sh b/.github/workflows/scripts/get_mmcv_var.sh
deleted file mode 100755
index 67604fec..00000000
--- a/.github/workflows/scripts/get_mmcv_var.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-
-TORCH=$1
-CUDA=$2
-
-# 10.2 -> cu102
-MMCV_CUDA="cu`echo ${CUDA} | tr -d '.'`"
-
-# MMCV only provides pre-compiled packages for torch 1.x.0
-# which works for any subversions of torch 1.x.
-# We force the torch version to be 1.x.0 to ease package searching
-# and avoid unnecessary rebuild during MMCV's installation.
-TORCH_VER_ARR=(${TORCH//./ })
-TORCH_VER_ARR[2]=0
-printf -v MMCV_TORCH "%s." "${TORCH_VER_ARR[@]}"
-MMCV_TORCH=${MMCV_TORCH%?}  # Remove the last dot
-
-echo "MMCV_CUDA=${MMCV_CUDA}" >> $GITHUB_ENV
-echo "MMCV_TORCH=${MMCV_TORCH}" >> $GITHUB_ENV
diff --git a/tests/test_utils/test_dl_utils/test_get_env.py b/tests/test_utils/test_dl_utils/test_get_env.py
index 23139b79..e7f26261 100644
--- a/tests/test_utils/test_dl_utils/test_get_env.py
+++ b/tests/test_utils/test_dl_utils/test_get_env.py
@@ -13,7 +13,7 @@ class TestCollectEnv(TestCase):
 
     def test_get_cuda_home(self):
         CUDA_HOME = _get_cuda_home()
-        if torch.cuda.is_available():
+        if torch.version.cuda is not None:
             self.assertIsNotNone(CUDA_HOME)
         else:
             self.assertIsNone(CUDA_HOME)
-- 
GitLab