Skip to content

Commit 03a24ef

Browse files
committed
upload dockerfile, workflow and update readme
1 parent 4afdd47 commit 03a24ef

File tree

6 files changed

+252
-8
lines changed

6 files changed

+252
-8
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
import argparse
4+
import os
5+
import subprocess
6+
from packaging import version
7+
from functools import cmp_to_key
8+
9+
10+
WHEEL_TEXT_ROOT_URL = 'https://github.com/hpcaitech/public_assets/tree/main/colossalai/torch_build/torch_wheels'
11+
RAW_TEXT_FILE_PREFIX = 'https://raw.githubusercontent.com/hpcaitech/public_assets/main/colossalai/torch_build/torch_wheels'
12+
CUDA_HOME = os.environ['CUDA_HOME']
13+
14+
15+
def parse_args():
16+
parser = argparse.ArgumentParser()
17+
parser.add_argument('--torch_version', type=str)
18+
return parser.parse_args()
19+
20+
def get_cuda_bare_metal_version():
21+
raw_output = subprocess.check_output([CUDA_HOME + "/bin/nvcc", "-V"], universal_newlines=True)
22+
output = raw_output.split()
23+
release_idx = output.index("release") + 1
24+
release = output[release_idx].split(".")
25+
bare_metal_major = release[0]
26+
bare_metal_minor = release[1][0]
27+
28+
return bare_metal_major, bare_metal_minor
29+
30+
def all_wheel_info():
31+
page_text = requests.get(WHEEL_TEXT_ROOT_URL).text
32+
soup = BeautifulSoup(page_text)
33+
34+
all_a_links = soup.find_all('a')
35+
36+
wheel_info = dict()
37+
38+
for a_link in all_a_links:
39+
if 'cuda' in a_link.text and '.txt' in a_link.text:
40+
filename = a_link.text
41+
torch_version, cuda_version = filename.rstrip('.txt').split('-')
42+
cuda_version = cuda_version.lstrip('cuda')
43+
if float(cuda_version) < 11.1:
44+
continue
45+
if torch_version not in wheel_info:
46+
wheel_info[torch_version] = dict()
47+
wheel_info[torch_version][cuda_version] = dict()
48+
49+
file_text = requests.get(f'{RAW_TEXT_FILE_PREFIX}/{filename}').text
50+
lines = file_text.strip().split('\n')
51+
52+
for line in lines:
53+
parts = line.split('\t')
54+
method, url, python_version = parts[:3]
55+
if float(python_version) < 3.8 or method == "conda":
56+
continue
57+
wheel_info[torch_version][cuda_version][python_version] = dict(url=url)
58+
return wheel_info
59+
60+
def build_colossalai(wheel_info):
61+
cuda_version_major, cuda_version_minor = get_cuda_bare_metal_version()
62+
cuda_version_on_host = f'{cuda_version_major}.{cuda_version_minor}'
63+
64+
for torch_version, cuda_versioned_wheel_info in wheel_info.items():
65+
for cuda_version, python_versioned_wheel_info in cuda_versioned_wheel_info.items():
66+
if cuda_version_on_host == cuda_version:
67+
for python_version, wheel_info in python_versioned_wheel_info.items():
68+
url = wheel_info['url']
69+
filename = url.split('/')[-1].replace('%2B', '+')
70+
cmd = f'bash ./build_fastfold_wheel.sh {url} {filename} {cuda_version} {python_version}'
71+
os.system(cmd)
72+
73+
def main():
74+
args = parse_args()
75+
wheel_info = all_wheel_info()
76+
77+
# filter wheels on condition
78+
all_torch_versions = list(wheel_info.keys())
79+
def _compare_version(a, b):
80+
if version.parse(a) > version.parse(b):
81+
return 1
82+
else:
83+
return -1
84+
85+
all_torch_versions.sort(key=cmp_to_key(_compare_version))
86+
87+
if args.torch_version != 'all':
88+
torch_versions = args.torch_version.split(',')
89+
# only keep the torch versions specified
90+
for key in all_torch_versions:
91+
if key not in torch_versions:
92+
wheel_info.pop(key)
93+
94+
build_colossalai(wheel_info)
95+
96+
if __name__ == '__main__':
97+
main()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
url=${1}
4+
filename=${2}
5+
cuda_version=${3}
6+
python_version=${4}
7+
8+
git reset --hard HEAD
9+
mkdir -p ./all_dist
10+
source activate base
11+
conda create -n $python_version -y python=$python_version
12+
source activate $python_version
13+
14+
wget -nc -q -O ./$filename $url
15+
pip install ./$filename
16+
pip install numpy
17+
18+
python setup.py bdist_wheel
19+
mv ./dist/* ./all_dist
20+
python setup.py clean
21+
conda deactivate
22+
conda env remove -n $python_version
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Release bdist wheel
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
torch_version:
7+
type: string
8+
description: torch version, separated by comma
9+
required: true
10+
default: "all"
11+
cuda_version:
12+
type: string
13+
description: cuda version, separated by comma
14+
required: true
15+
github_ref:
16+
type: string
17+
description: Branch or Tag
18+
default: 'main'
19+
required: true
20+
21+
jobs:
22+
matrix_preparation:
23+
name: Prepare Container List
24+
runs-on: ubuntu-latest
25+
outputs:
26+
matrix: ${{ steps.set-matrix.outputs.matrix }}
27+
steps:
28+
- id: set-matrix
29+
env:
30+
TORCH_VERSIONS: ${{ inputs.torch_version }}
31+
CUDA_VERSIONS: ${{ inputs.cuda_version }}
32+
run: |
33+
echo $TORCH_VERSIONS
34+
echo $CUDA_VERSIONS
35+
IFS=','
36+
DOCKER_IMAGE=()
37+
for cv in $CUDA_VERSIONS
38+
do
39+
DOCKER_IMAGE+=("\"hpcaitech/cuda-conda:${cv}\"")
40+
done
41+
container=$( IFS=',' ; echo "${DOCKER_IMAGE[*]}" )
42+
container="[${container}]"
43+
echo "$container"
44+
echo "::set-output name=matrix::{\"container\":$(echo "$container")}"
45+
build:
46+
name: Release bdist wheels
47+
needs: matrix_preparation
48+
if: github.repository == 'hpcaitech/FastFold' && contains(fromJson('["FrankLeeeee", "feifeibear", "Shenggan", "Gy-Lu"]'), github.actor)
49+
runs-on: [self-hosted, gpu]
50+
strategy:
51+
fail-fast: false
52+
matrix: ${{fromJson(needs.matrix_preparation.outputs.matrix)}}
53+
container:
54+
image: ${{ matrix.container }}
55+
options: --gpus all --rm
56+
steps:
57+
- uses: actions/checkout@v2
58+
with:
59+
fetch-depth: 0
60+
- name: Copy scripts and checkout
61+
run: |
62+
cp -r ./.github/workflows/* ./
63+
ln -s /github/home/pip_wheels ./pip_wheels
64+
git checkout $git_ref
65+
env:
66+
git_ref: ${{ github.event.inputs.github_ref }}
67+
- name: Build bdist wheel
68+
run: |
69+
pip install beautifulsoup4 requests packaging
70+
python ./build_fastfold_wheel.py --torch_version $TORCH_VERSIONS
71+
env:
72+
TORCH_VERSIONS: ${{ inputs.torch_version }}
73+
- name: 🚀 Deploy
74+
uses: garygrossgarten/github-action-scp@release
75+
with:
76+
local: all_dist
77+
remote: ${{ secrets.PRIVATE_PYPI_DIR }}
78+
host: ${{ secrets.PRIVATE_PYPI_HOST }}
79+
username: ${{ secrets.PRIVATE_PYPI_USER }}
80+
password: ${{ secrets.PRIVATE_PYPI_PASSWD }}

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,48 @@ FastFold provides a **high-performance implementation of Evoformer** with the fo
2121

2222
## Installation
2323

24-
You will need Python 3.8 or later and [NVIDIA CUDA](https://developer.nvidia.com/cuda-downloads) 11.1 or above when you are installing from source.
24+
To install and use FastFold, you will need:
25+
+ Python 3.8 or later
26+
+ [NVIDIA CUDA](https://developer.nvidia.com/cuda-downloads) 11.1 or above
27+
+ PyTorch 1.10 or above
28+
29+
For now, You can install FastFold:
30+
### Using Conda (Recommended)
31+
32+
We highly recommend installing an Anaconda or Miniconda environment and install PyTorch with conda.
33+
Lines below would create a new conda environment called "fastfold":
2534

2635
```shell
2736
git clone https://github.com/hpcaitech/FastFold
2837
cd FastFold
29-
```
30-
We highly recommend installing an Anaconda or Miniconda environment and install PyTorch with conda:
31-
32-
```shell
3338
conda env create --name=fastfold -f environment.yml
3439
conda activate fastfold
3540
bash scripts/patch_openmm.sh
41+
python setup.py install
3642
```
3743

38-
You can get the FastFold source and install it with setuptools:
44+
### Using PyPi
45+
You can download FastFold with pre-built CUDA extensions.
3946

4047
```shell
41-
python setup.py install
48+
pip install fastfold -f https://release.colossalai.org/fastfold
49+
```
50+
51+
## Use Docker
52+
53+
### Build On Your Own
54+
Run the following command to build a docker image from Dockerfile provided.
55+
56+
> Building FastFold from scratch requires GPU support, you need to use Nvidia Docker Runtime as the default when doing `docker build`. More details can be found [here](https://stackoverflow.com/questions/59691207/docker-build-with-nvidia-runtime).
57+
58+
```shell
59+
cd ColossalAI
60+
docker build -t fastfold ./docker
61+
```
62+
63+
Run the following command to start the docker container in interactive mode.
64+
```shell
65+
docker run -ti --gpus all --rm --ipc=host fastfold bash
4266
```
4367

4468
## Usage

docker/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM hpcaitech/cuda-conda:11.3
2+
3+
4+
# install dependency
5+
RUN yum install -y patch
6+
7+
RUN conda install pytorch==1.10.0 torchvision torchaudio cudatoolkit=11.3 -c pytorch \
8+
&& conda install setuptools=59.5.0 openmm=7.5.1 pdbfixer -c conda-forge \
9+
&& conda install hmmer==3.3.2 hhsuite=3.3.0 kalign2=2.04 -c bioconda
10+
11+
RUN pip install biopython==1.79 dm-tree==0.1.6 ml-collections==0.1.0 numpy==1.21.2 \
12+
PyYAML==5.4.1 requests==2.26.0 scipy==1.7.1 tqdm==4.62.2 typing-extensions==3.10.0.2 einops
13+
14+
RUN pip install colossalai==0.1.8+torch1.10cu11.3 -f https://release.colossalai.org
15+
16+
17+
# prepare environment
18+
Run git clone https://github.com/hpcaitech/FastFold.git\
19+
&& cd ./FastFold \
20+
&& /bin/bash scripts/patch_openmm.sh \
21+
&& python setup.py install

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def cuda_ext_helper(name, sources, extra_cuda_flags):
129129

130130
setup(
131131
name='fastfold',
132-
version='0.1.0-beta',
132+
version='0.1.0',
133133
packages=find_packages(exclude=(
134134
'assets',
135135
'benchmark',

0 commit comments

Comments
 (0)