diff --git a/.circleci/docker/Dockerfile b/.circleci/docker/Dockerfile new file mode 100644 index 00000000..d9cf8cc7 --- /dev/null +++ b/.circleci/docker/Dockerfile @@ -0,0 +1,11 @@ +ARG PYTORCH="1.8.1" +ARG CUDA="10.2" +ARG CUDNN="7" + +FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel + +# To fix GPG key error when running apt-get update +RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub +RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub + +RUN apt-get update && apt-get install -y ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6 libgl1-mesa-glx diff --git a/.circleci/scripts/get_mmcv_var.sh b/.circleci/scripts/get_mmcv_var.sh new file mode 100755 index 00000000..552ff871 --- /dev/null +++ b/.circleci/scripts/get_mmcv_var.sh @@ -0,0 +1,19 @@ +#!/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 3da9864c..e47816b6 100644 --- a/.circleci/test.yml +++ b/.circleci/test.yml @@ -44,6 +44,11 @@ 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: | @@ -62,7 +67,7 @@ jobs: - run: name: Install mmocr dependencies command: | - python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch<< parameters.torch >>/index.html + python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html python -m pip install mmdet python -m pip install -r requirements.txt - run: @@ -78,54 +83,44 @@ jobs: build_cuda: parameters: - # The python version must match available image tags in - # https://circleci.com/developer/images/image/cimg/python - python: - type: string torch: type: string - torchvision: - type: string cuda: - type: string - default: cu102 + type: enum + enum: ["10.1", "10.2", "11.1"] + cudnn: + type: integer + default: 7 machine: - image: ubuntu-1604-cuda-10.2:202012-01 + image: ubuntu-2004-cuda-11.4:202110-01 + docker_layer_caching: true resource_class: gpu.nvidia.small steps: - checkout - run: - name: Install Libraries + name: Get MMCV_TORCH and MMCV_CUDA as environment variables command: | - sudo apt-get update - sudo apt-get install -y git ninja-build libglib2.0-0 libsm6 libxrender-dev libxext6 libgl1-mesa-glx - pyenv versions + . .circleci/scripts/get_mmcv_var.sh << parameters.torch >> << parameters.cuda >> + source $BASH_ENV - run: - name: Configure Python & pip + name: Build Docker image command: | - pyenv global << parameters.python >> - python -m pip install --upgrade pip - python -m pip install wheel - - run: - name: Install PyTorch - command: | - python -V - python -m pip install torch==<< parameters.torch >>+<< parameters.cuda >> torchvision==<< parameters.torchvision >>+<< parameters.cuda >> -f https://download.pytorch.org/whl/torch_stable.html + docker build .circleci/docker -t mmocr: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:/mmocr -w /mmocr --name mmocr mmocr:gpu - run: name: Install mmocr dependencies command: | - python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/<< parameters.cuda >>/torch<< parameters.torch >>/index.html - python -m pip install mmdet - python -m pip install -r requirements.txt + docker exec mmocr pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/${MMCV_CUDA}/torch${MMCV_TORCH}/index.html + docker exec mmocr pip install mmdet + docker exec mmocr pip install -r requirements.txt - run: name: Build and install command: | - python setup.py check -m -s - TORCH_CUDA_ARCH_LIST=7.0 python -m pip install -e . + docker exec mmocr pip install -e . - run: name: Run unittests command: | - python -m pytest tests/ + docker exec mmocr python -m pytest tests/ workflows: pr_stage_lint: @@ -169,8 +164,9 @@ workflows: - build_cuda: name: mainstream_version_gpu torch: 1.8.1 - torchvision: 0.9.1 - python: 3.8.6 + # Use double quotation mark to explicitly specify its type + # as string instead of number + cuda: "10.2" requires: - hold merge_stage_test: @@ -181,9 +177,9 @@ workflows: - build_cuda: name: minimum_version_gpu torch: 1.6.0 - torchvision: 0.7.0 - python: 3.6.12 - cuda: cu101 + # Use double quotation mark to explicitly specify its type + # as string instead of number + cuda: "10.1" filters: branches: only: diff --git a/.github/workflows/merge_stage_test.yml b/.github/workflows/merge_stage_test.yml index 412830cc..d2d4d111 100644 --- a/.github/workflows/merge_stage_test.yml +++ b/.github/workflows/merge_stage_test.yml @@ -32,15 +32,15 @@ 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 Pillow - run: pip install Pillow - if: ${{matrix.torchvision == '0.4.1'}} - 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.torch}}/index.html + run: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html - name: Install MMDet run: pip install mmdet - name: Install other dependencies @@ -82,13 +82,13 @@ jobs: python-version: ${{ matrix.python-version }} - name: Upgrade pip run: pip install pip --upgrade - - name: Install Pillow - run: pip install Pillow - if: ${{matrix.torchvision == '0.4.1'}} + - 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${{matrix.torch}}/index.html + run: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html - name: Install MMDet run: pip install mmdet - name: Install other dependencies @@ -118,11 +118,9 @@ jobs: strategy: matrix: python-version: [3.7] - torch: [1.8.1+cu102] include: - - torch: 1.8.1+cu102 - torch_version: 1.8.1 - torchvision: 0.9.1+cu102 + - torch: 1.8.1 + cuda: 10.2 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -135,32 +133,22 @@ jobs: 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 - apt-get clean - rm -rf /var/lib/apt/lists/* - apt-get install -y ninja-build - - name: Install Pillow - run: python -m pip install Pillow==6.2.2 - if: ${{matrix.torchvision < 0.5}} - - name: Install soundfile lib - run: apt-get install -y libsndfile1 - - name: Install librosa and soundfile - run: python -m pip install librosa soundfile - - name: Install lmdb - run: python -m pip install lmdb - name: Install mmocr dependencies run: | - python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch${{matrix.torch_version}}/index.html + python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/${MMCV_CUDA}/torch${MMCV_TORCH}}/index.html python -m pip install mmdet python -m pip install -r requirements.txt - name: Build and install run: | - rm -rf .eggs python setup.py check -m -s TORCH_CUDA_ARCH_LIST=7.0 python -m pip install -e . diff --git a/.github/workflows/pr_stage_test.yml b/.github/workflows/pr_stage_test.yml index d44db19d..f4e8afa1 100644 --- a/.github/workflows/pr_stage_test.yml +++ b/.github/workflows/pr_stage_test.yml @@ -20,7 +20,6 @@ jobs: strategy: matrix: python-version: [3.7] - torch: [1.8.1] include: - torch: 1.8.1 torchvision: 0.9.1 @@ -32,13 +31,13 @@ jobs: python-version: ${{ matrix.python-version }} - name: Upgrade pip run: pip install pip --upgrade - - name: Install Pillow - run: pip install Pillow - if: ${{matrix.torchvision == '0.4.1'}} + - 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${{matrix.torch}}/index.html + run: pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch${MMCV_TORCH}/index.html - name: Install MMDet run: pip install mmdet - name: Install other dependencies @@ -67,11 +66,6 @@ jobs: strategy: matrix: python-version: [3.7] - torch: [1.8.1+cu102] - include: - - torch: 1.8.1+cu102 - torch_version: 1.8.1 - torchvision: 0.9.1+cu102 steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -84,6 +78,9 @@ jobs: 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}} @@ -91,24 +88,13 @@ jobs: run: | apt-get update apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev - apt-get clean - - name: Install Pillow - run: python -m pip install Pillow==6.2.2 - if: ${{matrix.torchvision < 0.5}} - - name: Install soundfile lib - run: apt-get install -y libsndfile1 - - name: Install librosa and soundfile - run: python -m pip install librosa soundfile - - name: Install lmdb - run: python -m pip install lmdb - name: Install mmocr dependencies run: | - python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch${{matrix.torch_version}}/index.html + python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/${MMCV_CUDA}/torch${MMCV_TORCH}/index.html python -m pip install mmdet python -m pip install -r requirements.txt - name: Build and install run: | - rm -rf .eggs python setup.py check -m -s TORCH_CUDA_ARCH_LIST=7.0 python -m pip install -e . diff --git a/.github/workflows/scripts/get_mmcv_var.sh b/.github/workflows/scripts/get_mmcv_var.sh new file mode 100755 index 00000000..67604fec --- /dev/null +++ b/.github/workflows/scripts/get_mmcv_var.sh @@ -0,0 +1,19 @@ +#!/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