Skip to content

Commit

Permalink
Add build wheels workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
sumof2primes committed Apr 9, 2023
1 parent 03151a0 commit 4e7538d
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/actions/setup-linux-runner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Set up Linux Runner

inputs:
cuda_version:
description: Cuda version to install
type: string
required: true
python_version:
description: Python version to install
type: string
required: true

runs:
using: composite
steps:
- id: cuda-toolkit
shell: python
run: |
import os
import sys
print(sys.version)
# https://developer.nvidia.com/cuda-toolkit-archive
runfile = {
"118": "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run",
"117": "https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run",
}["${{ inputs.cuda_version }}"]
with open(os.environ['GITHUB_OUTPUT'], "r+") as fp:
fp.write("runfile=" + runfile + "\n")
- name: Install cuda
shell: bash
run: >
yum install wget git prename -y &&
wget -q "${{ steps.cuda-toolkit.outputs.runfile }}" -O installer.run &&
sh ./installer.run --silent --toolkit &&
rm ./installer.run
54 changes: 54 additions & 0 deletions .github/actions/setup-windows-runner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Set up Windows Runner

inputs:
cuda_version:
description: Cuda version to install
type: string
required: true
python_version:
description: Python version to install
type: string
required: true

runs:
using: composite
steps:
- name: Install python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}

- id: cuda-toolkit
shell: python
run: |
import os
import sys
print(sys.version)
# https://developer.nvidia.com/cuda-toolkit-archive
version = {
"118": "11.8.0",
"117": "11.7.1",
}["${{ inputs.cuda_version }}"]
with open(os.environ['GITHUB_OUTPUT'], "r+") as fp:
fp.write("version=" + version + "\n")
- name: Install cuda
uses: okazunori2013/cuda-toolkit@v0.3.3
with:
cuda: ${{ steps.cuda-toolkit.outputs.version }}
method: network

- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1

- name: Configure Pagefile
# windows runners will OOM with many CUDA architectures
# we cheat here with a page file
uses: al-cheb/configure-pagefile-action@v1.3
with:
minimum-size: 8GB

# really unfortunate: https://github.com/ilammy/msvc-dev-cmd#name-conflicts-with-shell-bash
- name: Remove link.exe
shell: bash
run: rm /usr/bin/link
62 changes: 62 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build mmcv wheels

on:
workflow_dispatch:
inputs:
ref:
description: "mmcv branch, tag or SHA to checkout"
type: string
required: true

jobs:
build_wheels:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- windows-2019
python:
- "3.9"
- "3.10"
config:
# https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html
- torch_version: "2.0.0"
cuda_short_version: "118"
arch_list: "7.0 7.5 8.0 8.6 8.9"
publish: true

# https://download.openmmlab.com/mmcv/dist/cu117/torch1.13/index.html
- torch_version: "1.13.1"
cuda_short_version: "117"
arch_list: "7.0 7.5 8.0 8.6"
publish: true

uses: ./.github/workflows/wheels_on_workflow_call.yml
permissions:
contents: write
with:
os: ${{ matrix.os }}
python: ${{ matrix.python }}
torch_version: ${{ matrix.config.torch_version }}
cuda_short_version: ${{ matrix.config.cuda_short_version }}
arch_list: ${{ matrix.config.arch_list }}
publish: ${{ matrix.config.publish}}
ref: ${{ inputs.ref }}

release_wheels:
needs: [build_wheels]
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- id: get-artifact
uses: actions/download-artifact@v3
- id: release
uses: ncipollo/release-action@v1
with:
artifacts: "*/*.whl"
name: "mmcv-full wheels"
tag: ${{ github.run_id }}
commit: ${{ github.sha }}
body: "https://github.com/open-mmlab/mmcv/commit/${{ inputs.ref }}"
133 changes: 133 additions & 0 deletions .github/workflows/wheels_on_workflow_call.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Build mmcv wheels on workflow call

on:
workflow_call:
inputs:
os:
required: true
type: string
python:
required: true
type: string
torch_version:
required: true
type: string
cuda_short_version:
required: true
type: string
arch_list:
required: true
type: string
publish:
required: true
type: boolean
ref:
required: true
type: string

env:
TORCH_CUDA_ARCH_LIST: ${{ inputs.arch_list }}
FORCE_CUDA: 1
MMCV_WITH_OPS: 1
MAX_JOBS: 1 # will crash otherwise
DISTUTILS_USE_SDK: 1 # otherwise distutils will complain on windows about multiple versions of msvc

jobs:
build_wheels:
name: ${{ inputs.os }}-py${{ inputs.python }}-torch${{ inputs.torch_version }}+cu${{ inputs.cuda_short_version }}
runs-on: ${{ inputs.os }}
env:
# alias for the current python version
# windows does not have per version binary, it is just 'python3'
PY: python${{ contains(inputs.os, 'ubuntu') && inputs.python || '3' }}

container: ${{ contains(inputs.os, 'ubuntu') && 'quay.io/pypa/manylinux2014_x86_64' || null }}
timeout-minutes: 360
defaults:
run:
shell: bash
steps:
- name: Recursive checkout
uses: actions/checkout@v3
with:
repository: open-mmlab/mmcv
ref: ${{ inputs.ref }}
submodules: recursive
path: "."
fetch-depth: 0 # for tags

- name: Checkout latest setup.py
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
path: "latest"

- name: Copy latest setup.py
run: |
cp latest/setup.py setup.py
- name: Set short git commit SHA
id: commit
run: |
set -Eeuo pipefail
git config --global --add safe.directory "*"
sha=$(git rev-parse --short HEAD)
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Confirm git commit SHA output
run: echo ${{ steps.commit.outputs.sha }}

- name: Checkout repository
uses: actions/checkout@v3
with:
path: workflows

- if: runner.os == 'Linux'
name: (Linux) Setup Runner
uses: ./workflows/.github/actions/setup-linux-runner
with:
cuda_version: ${{ inputs.cuda_short_version }}
python_version: ${{ inputs.python }}

- if: runner.os == 'Windows'
name: (Windows) Setup Runner
uses: ./workflows/.github/actions/setup-windows-runner
with:
cuda_version: ${{ inputs.cuda_short_version }}
python_version: ${{ inputs.python }}

- name: Define version
id: define
run: |
set -Eeuo pipefail
git config --global --add safe.directory "*"
cp mmcv/version.py .
version=`$PY -c "from version import *; print(__version__)"`
echo "BUILD_VERSION=$version" >> ${GITHUB_ENV}
cat ${GITHUB_ENV}
echo "version=$version" >> $GITHUB_OUTPUT
- name: Setup proper pytorch dependency in "requirements.txt"
run: |
sed -i '/torch/d' ./requirements/optional.txt
echo "torch == ${{ inputs.torch_version }}" >> ./requirements/optional.txt
cat ./requirements/optional.txt
ninja=`$PY -c "import sys; print(sys.exec_prefix + '/bin')"`
echo "$ninja" >> $GITHUB_PATH
- name: Install dependencies
run: $PY -m pip install wheel setuptools -r ./requirements/optional.txt --extra-index-url https://download.pytorch.org/whl/cu${{ inputs.cuda_short_version }}

- name: Build wheel
run: $PY setup.py bdist_wheel -d dist/ -k $PLAT_ARG
env:
PLAT_ARG: ${{ contains(inputs.os, 'ubuntu') && '--plat-name manylinux2014_x86_64' || '' }}

- name: Rename wheel # PEP File name convention
run: |
for f in dist/*.whl; do mv "$f" "$(echo "$f" | sed s/${{ steps.define.outputs.version }}/${{ steps.define.outputs.version }}+git.${{ steps.commit.outputs.sha }}+torch${{ inputs.torch_version }}+cu${{ inputs.cuda_short_version }}/)"; done
- uses: actions/upload-artifact@v3
with:
name: ${{ inputs.os }}-mmcv_full-${{ steps.define.outputs.version }}+git.${{ steps.commit.outputs.sha }}+torch${{ inputs.torch_version }}+cu${{ inputs.cuda_short_version }}-py${{ inputs.python }}
path: dist/*.whl
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# mmcv-builds
## Intro
Community [mmcv](https://github.com/open-mmlab/mmcv) builds with Github Actions

## Support
- Python : 3.9, 3.10
- Package : Python Wheel
- OS compatibility : [manylinux2014_x86_64](https://github.com/pypa/manylinux)
- [CUDA Application Compatibility](https://docs.nvidia.com/deploy/cuda-compatibility/index.html#use-the-right-compat-package) : 11.7 11.8
- [PyTorch](https://pytorch.org/get-started/locally/) : 1.13.1 2.0.0
- [GPU Compute Capability](https://developer.nvidia.com/cuda-gpus) : 7.0 7.5 8.0 8.6 8.9

## Installing mmcv
```bash
pip install --upgrade --ignore-installed NAME.whl
```

## Credits
- https://github.com/open-mmlab/mmcv

0 comments on commit 4e7538d

Please sign in to comment.