Skip to content

Commit e938c18

Browse files
authored
Merge pull request #534 from aqlaboratory/pl_upgrades
Update openfold to use pytorch 2 and other updated dependencies
2 parents 815a042 + c587b06 commit e938c18

14 files changed

+123
-112
lines changed

Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu18.04
1+
FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04
22

33
# metainformation
4-
LABEL org.opencontainers.image.version = "1.0.0"
5-
LABEL org.opencontainers.image.authors = "Gustaf Ahdritz"
4+
LABEL org.opencontainers.image.version = "2.0.0"
5+
LABEL org.opencontainers.image.authors = "OpenFold Team"
66
LABEL org.opencontainers.image.source = "https://github.com/aqlaboratory/openfold"
77
LABEL org.opencontainers.image.licenses = "Apache License 2.0"
8-
LABEL org.opencontainers.image.base.name="docker.io/nvidia/cuda:10.2-cudnn8-runtime-ubuntu18.04"
8+
LABEL org.opencontainers.image.base.name="docker.io/nvidia/cuda:12.4.1-devel-ubuntu22.04"
9+
10+
RUN apt-get update && apt-get install -y wget
911

1012
RUN apt-key del 7fa2af80
11-
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
12-
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
13+
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
14+
RUN dpkg -i cuda-keyring_1.0-1_all.deb
15+
16+
RUN apt-get install -y libxml2 cuda-minimal-build-12-1 libcusparse-dev-12-1 libcublas-dev-12-1 libcusolver-dev-12-1 git
1317

14-
RUN apt-get update && apt-get install -y wget libxml2 cuda-minimal-build-11-3 libcusparse-dev-11-3 libcublas-dev-11-3 libcusolver-dev-11-3 git
1518
RUN wget -P /tmp \
1619
"https://github.com/conda-forge/miniforge/releases/download/23.3.1-1/Miniforge3-Linux-x86_64.sh" \
1720
&& bash /tmp/Miniforge3-Linux-x86_64.sh -b -p /opt/conda \

docs/source/Inference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ python3 run_pretrained_openfold.py \
6262
$TEMPLATE_MMCIF_DIR
6363
--output_dir $OUTPUT_DIR \
6464
--config_preset model_1_ptm \
65-
--uniref90_database_path $BASE_DATA_DIR/uniref90 \
65+
--uniref90_database_path $BASE_DATA_DIR/uniref90/uniref90.fasta \
6666
--mgnify_database_path $BASE_DATA_DIR/mgnify/mgy_clusters_2018_12.fa \
6767
--pdb70_database_path $BASE_DATA_DIR/pdb70 \
6868
--uniclust30_database_path $BASE_DATA_DIR/uniclust30/uniclust30_2018_08/uniclust30_2018_08 \

docs/source/Installation.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ In this guide, we will OpenFold and its dependencies.
44

55
**Pre-requisites**
66

7-
This package is currently supported for CUDA 11 and Pytorch 1.12. All dependencies are listed in the [`environment.yml`](https://github.com/aqlaboratory/openfold/blob/main/environment.yml). To install OpenFold for CUDA 12, please refer to the [Environment specific modifications](#Environment-specific-modifications) section.
7+
This package is currently supported for CUDA 12 and Pytorch 2. All dependencies are listed in the [`environment.yml`](https://github.com/aqlaboratory/openfold/blob/main/environment.yml).
88

99
At this time, only Linux systems are supported.
1010

@@ -53,12 +53,6 @@ Certain tests perform equivalence comparisons with the AlphaFold implementation.
5353

5454
## Environment specific modifications
5555

56-
### CUDA 12
57-
To use OpenFold on CUDA 12 environment rather than a CUDA 11 environment.
58-
In step 1, use the branch [`pl_upgrades`](https://github.com/aqlaboratory/openfold/tree/pl_upgrades) rather than the main branch, i.e. replace the command in step 1 with `git clone -b pl_upgrades https://github.com/aqlaboratory/openfold.git`
59-
and follow the rest of the steps of [Installation Guide](#Installation)
60-
61-
6256
### MPI
6357
To use OpenFold with MPI support, you will need to add the package [`mpi4py`](https://pypi.org/project/mpi4py/). This can be done with pip in your OpenFold environment, e.g. `$ pip install mpi4py`.
6458

@@ -71,4 +65,4 @@ If you don't have access to `aws` on your system, you can use a different downlo
7165

7266
### Docker setup
7367

74-
A [`Dockerfile`] is provided to build an OpenFold Docker image. Additional notes for setting up a docker container for OpenFold and running inference can be found [here](original_readme.md#building-and-using-the-docker-container).
68+
A [`Dockerfile`](https://github.com/aqlaboratory/openfold/blob/main/Dockerfile) is provided to build an OpenFold Docker image. Additional notes for setting up a docker container for OpenFold and running inference can be found [here](original_readme.md#building-and-using-the-docker-container).

environment.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,38 @@ channels:
33
- conda-forge
44
- bioconda
55
- pytorch
6+
- nvidia
67
dependencies:
7-
- python=3.9
8-
- libgcc=7.2
8+
- cuda
9+
- gcc=12.4
10+
- python=3.10
911
- setuptools=59.5.0
1012
- pip
11-
- openmm=7.7
13+
- openmm
1214
- pdbfixer
1315
- pytorch-lightning
1416
- biopython
1517
- numpy
1618
- pandas
17-
- PyYAML==5.4.1
19+
- PyYAML
1820
- requests
19-
- scipy==1.7
20-
- tqdm==4.62.2
21-
- typing-extensions==4.0
21+
- scipy
22+
- tqdm
23+
- typing-extensions
2224
- wandb
2325
- modelcif==0.7
2426
- awscli
2527
- ml-collections
2628
- aria2
27-
- mkl=2024.0
29+
- mkl
2830
- git
29-
- bioconda::hmmer==3.3.2
30-
- bioconda::hhsuite==3.3.0
31-
- bioconda::kalign2==2.04
32-
- bioconda::mmseqs2
33-
- pytorch::pytorch=1.12.*
31+
- bioconda::hmmer
32+
- bioconda::hhsuite
33+
- bioconda::kalign2
34+
- pytorch::pytorch=2.5
35+
- pytorch::pytorch-cuda=12.4
3436
- pip:
35-
- deepspeed==0.12.4
37+
- deepspeed==0.14.5
3638
- dm-tree==0.1.6
3739
- git+https://github.com/NVIDIA/dllogger.git
38-
- git+https://github.com/Dao-AILab/flash-attention.git@5b838a8
40+
- flash-attn

notebooks/OpenFold.ipynb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "view-in-github",
7+
"colab_type": "text"
8+
},
9+
"source": [
10+
"<a href=\"https://colab.research.google.com/github/aqlaboratory/OpenFold/blob/main/notebooks/OpenFold.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
11+
]
12+
},
313
{
414
"cell_type": "markdown",
515
"metadata": {
@@ -107,11 +117,11 @@
107117
"\n",
108118
"python_version = f\"{version_info.major}.{version_info.minor}\"\n",
109119
"\n",
110-
"\n",
111-
"os.system(\"wget -qnc https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh\")\n",
112-
"os.system(\"bash Mambaforge-Linux-x86_64.sh -bfp /usr/local\")\n",
120+
"os.system(\"wget -qnc https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh\")\n",
121+
"os.system(\"bash Miniforge3-Linux-x86_64.sh -bfp /usr/local\")\n",
122+
"os.environ[\"PATH\"] = \"/usr/local/bin:\" + os.environ[\"PATH\"]\n",
113123
"os.system(\"mamba config --set auto_update_conda false\")\n",
114-
"os.system(f\"mamba install -y -c conda-forge -c bioconda kalign2=2.04 hhsuite=3.3.0 openmm=7.7.0 python={python_version} pdbfixer biopython=1.83\")\n",
124+
"os.system(f\"mamba install -y -c conda-forge -c bioconda kalign2=2.04 hhsuite=3.3.0 openmm=8.2.0 python={python_version} pdbfixer biopython=1.83\")\n",
115125
"os.system(\"pip install -q torch ml_collections py3Dmol modelcif\")\n",
116126
"\n",
117127
"try:\n",
@@ -127,7 +137,7 @@
127137
"\n",
128138
" %shell mkdir -p /content/openfold/openfold/resources\n",
129139
"\n",
130-
" commit = \"3bec3e9b2d1e8bdb83887899102eff7d42dc2ba9\"\n",
140+
" commit = \"1ffd197489aa5f35a5fbce1f00d7dd49bce1bd2f\"\n",
131141
" os.system(f\"pip install -q git+https://github.com/aqlaboratory/openfold.git@{commit}\")\n",
132142
"\n",
133143
" os.system(f\"cp -f -p /content/stereo_chemical_props.txt /usr/local/lib/python{python_version}/site-packages/openfold/resources/\")\n",
@@ -893,8 +903,7 @@
893903
"metadata": {
894904
"colab": {
895905
"provenance": [],
896-
"gpuType": "T4",
897-
"toc_visible": true
906+
"gpuType": "T4"
898907
},
899908
"kernelspec": {
900909
"display_name": "Python 3",

openfold/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def model_config(
660660
},
661661
"relax": {
662662
"max_iterations": 0, # no max
663-
"tolerance": 2.39,
663+
"tolerance": 10.0,
664664
"stiffness": 10.0,
665665
"max_outer_iterations": 20,
666666
"exclude_residues": [],

openfold/model/primitives.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
fa_is_installed = importlib.util.find_spec("flash_attn") is not None
2929
if fa_is_installed:
3030
from flash_attn.bert_padding import unpad_input
31-
from flash_attn.flash_attn_interface import flash_attn_unpadded_kvpacked_func
31+
from flash_attn.flash_attn_interface import flash_attn_varlen_kvpacked_func
3232

3333
import torch
3434
import torch.nn as nn
@@ -808,10 +808,10 @@ def _flash_attn(q, k, v, kv_mask):
808808
# [B_flat, N, 2 * H * C]
809809
kv = kv.reshape(*kv.shape[:-3], -1)
810810

811-
kv_unpad, _, kv_cu_seqlens, kv_max_s = unpad_input(kv, kv_mask)
811+
kv_unpad, _, kv_cu_seqlens, kv_max_s, _ = unpad_input(kv, kv_mask)
812812
kv_unpad = kv_unpad.reshape(-1, *kv_shape[-3:])
813813

814-
out = flash_attn_unpadded_kvpacked_func(
814+
out = flash_attn_varlen_kvpacked_func(
815815
q,
816816
kv_unpad,
817817
q_cu_seqlens,

openfold/np/relax/amber_minimize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from openmm.app.internal.pdbstructure import PdbStructure
3535

3636
ENERGY = unit.kilocalories_per_mole
37+
FORCE = unit.kilojoules_per_mole / unit.nanometer
3738
LENGTH = unit.angstroms
3839

3940

@@ -439,7 +440,7 @@ def _run_one_iteration(
439440
exclude_residues = exclude_residues or []
440441

441442
# Assign physical dimensions.
442-
tolerance = tolerance * ENERGY
443+
tolerance = tolerance * FORCE
443444
stiffness = stiffness * ENERGY / (LENGTH ** 2)
444445

445446
start = time.perf_counter()

openfold/utils/superimposition.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def _superimpose_np(reference, coords):
3535

3636

3737
def _superimpose_single(reference, coords):
38-
reference_np = reference.detach().to(torch.float).cpu().numpy()
39-
coords_np = coords.detach().to(torch.float).cpu().numpy()
40-
superimposed, rmsd = _superimpose_np(reference_np, coords_np)
41-
return coords.new_tensor(superimposed), coords.new_tensor(rmsd)
38+
reference_np = reference.detach().to(torch.float).cpu().numpy()
39+
coords_np = coords.detach().to(torch.float).cpu().numpy()
40+
superimposed, rmsd = _superimpose_np(reference_np, coords_np)
41+
return coords.new_tensor(superimposed), coords.new_tensor(rmsd)
4242

4343

4444
def superimpose(reference, coords, mask):

scripts/install_third_party_dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ gunzip -c tests/test_data/sample_feats.pickle.gz > tests/test_data/sample_feats.
1414
python setup.py install
1515

1616
echo "Download CUTLASS, required for Deepspeed Evoformer attention kernel"
17-
git clone https://github.com/NVIDIA/cutlass --depth 1
17+
git clone https://github.com/NVIDIA/cutlass --branch v3.6.0 --depth 1
1818
conda env config vars set CUTLASS_PATH=$PWD/cutlass
1919

2020
# This setting is used to fix a worker assignment issue during data loading

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
]
3030

3131
extra_cuda_flags = [
32-
'-std=c++14',
32+
'-std=c++17',
3333
'-maxrregcount=50',
3434
'-U__CUDA_NO_HALF_OPERATORS__',
3535
'-U__CUDA_NO_HALF_CONVERSIONS__',
@@ -52,9 +52,9 @@ def get_cuda_bare_metal_version(cuda_dir):
5252
return raw_output, bare_metal_major, bare_metal_minor
5353

5454
compute_capabilities = set([
55-
(3, 7), # K80, e.g.
5655
(5, 2), # Titan X
5756
(6, 1), # GeForce 1000-series
57+
(9, 0), # Hopper
5858
])
5959

6060
compute_capabilities.add((7, 0))
@@ -113,7 +113,7 @@ def get_cuda_bare_metal_version(cuda_dir):
113113

114114
setup(
115115
name='openfold',
116-
version='2.0.0',
116+
version='2.2.0',
117117
description='A PyTorch reimplementation of DeepMind\'s AlphaFold 2',
118118
author='OpenFold Team',
119119
author_email='jennifer.wei@omsf.io',
@@ -130,7 +130,7 @@ def get_cuda_bare_metal_version(cuda_dir):
130130
classifiers=[
131131
'License :: OSI Approved :: Apache Software License',
132132
'Operating System :: POSIX :: Linux',
133-
'Programming Language :: Python :: 3.9,'
133+
'Programming Language :: Python :: 3.10,'
134134
'Topic :: Scientific/Engineering :: Artificial Intelligence',
135135
],
136136
)

tests/test_deepspeed_evo_attention.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ def test_compare_model(self):
306306
batch["residx_atom37_to_atom14"] = batch[
307307
"residx_atom37_to_atom14"
308308
].long()
309-
# print(batch["target_feat"].shape)
310309
batch["target_feat"] = torch.nn.functional.one_hot(batch["aatype"], consts.msa_logits - 1).to(torch.float32)
311310
batch["template_all_atom_mask"] = batch["template_all_atom_masks"]
312311
batch.update(
@@ -316,8 +315,9 @@ def test_compare_model(self):
316315
# Move the recycling dimension to the end
317316
move_dim = lambda t: t.permute(*range(len(t.shape))[1:], 0)
318317
batch = tensor_tree_map(move_dim, batch)
319-
with torch.no_grad():
320-
with torch.cuda.amp.autocast(dtype=torch.bfloat16):
318+
# Restrict this test to use only torch.float32 precision due to instability with torch.bfloat16
319+
# https://github.com/aqlaboratory/openfold/issues/532
320+
with torch.no_grad(), torch.cuda.amp.autocast(dtype=torch.float32):
321321
model = compare_utils.get_global_pretrained_openfold()
322322
model.globals.use_deepspeed_evo_attention = False
323323
out_repro = model(batch)

tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,4 @@ def run_alphafold(batch):
202202
out_repro = out_repro["sm"]["positions"][-1]
203203
out_repro = out_repro.squeeze(0)
204204

205-
self.assertTrue(torch.max(torch.abs(out_gt - out_repro)) < 1e-3)
205+
compare_utils.assert_mean_abs_diff_small(out_gt, out_repro, 1e-3)

0 commit comments

Comments
 (0)