本家様 https://github.com/facebookresearch/esm
pipyhttps://pypi.org/project/fair-esm/
Evolutionary Scale Modeling (esm): Pretrained language models for proteins
This repository contains code and pre-trained weights for Transformer protein language models from Facebook AI Research,
including our state-of-the-art ESM-2 and ESMFold, as well as MSA Transformer, ESM-1v for predicting variant effects and ESM-IF1 for inverse folding.
Transformer protein language models were introduced in the preprint of the paper "Biological structure and function emerge from scaling unsupervised learning to 250 million protein sequences" (Rives et al., 2019).
(deepL様翻訳)
このリポジトリには、Facebook AI ResearchによるTransformerタンパク質言語モデルのコードと事前学習済み重みが含まれています。
これには、最先端のESM-2やESMFoldに加え、MSA Transformer、変異効果を予測するESM-1v、および逆フォールディングを行うESM-IF1が含まれます。
Transformerタンパク質言語モデルは、論文「Biological structure and function emerge from scaling unsupervised learning to 250 million protein sequences」(Rives et al., 2019)のプレプリントで初めて紹介されました。インストール環境はこんな感じ
[root@r9 ~]# cat /etc/redhat-release
Rocky Linux release 9.7 (Blue Onyx)
[root@r9 ~]# cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX Open Kernel Module for x86_64 595.58.03 Release Build (dvs-builder@U22-I3-AM25-28-3) Tue Mar 17 19:55:10 UTC 2026
GCC version: gcc version 11.5.0 20240719 (Red Hat 11.5.0-11) (GCC)
[root@r9 ~]# nvidia-smi -L
GPU 0: NVIDIA RTX PRO 2000 Blackwell (UUID: GPU-40660e37-0d35-d4f4-294a-eee3fe83049e)
[root@r9 ~]#blackwellですが、このESMは3年前から更新していない(今時点 2026)、なので基本blackwellで動かすにはいろいろ修正が必要です。
そしてこの修正が正しいのか微妙。なので3年前のGPU、adaとかampereのご利用をお勧めします
ここではcrYOLOのようにpyenv/anacondaの環境を拵えて、その上でESM実行環境を用意していきます
git clone https://github.com/yyuu/pyenv.git /apps/pyenv
export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
pyenv install miniforge3-26.1.1-3
source /apps/pyenv/versions/miniforge3-26.1.1-3/etc/profile.d/conda.sh
conda update conda
(既に環境があるなら)
source /apps/pyenv/versions/miniforge3-26.1.1-3/etc/profile.d/conda.shあとcuda-toolkit環境も用意します。conda仮想実行環境に含めてもいいのですが、/usr/local に設置しました
[root@r9 ~]# dnf localinstall /Public/cuda/cuda-repo-rhel9-12-8-local-12.8.1_570.124.06-1.x86_64.rpm -y
[root@r9 ~]# dnf install cuda-toolkit-12-8 -y
[root@r9 ~]# dnf remove cuda-repo-rhel9-12-8-local-12.8.1_570.124.06-1.x86_64 -y
[root@r9 ~]# vi /apps/modulefiles/cuda/12.8
#%Module1.0
set cuda /usr/local/cuda-12.8
setenv CUDA_HOME $cuda
setenv CUDA_PATH $cuda
prepend-path PATH $cuda/bin
prepend-path LD_LIBRARY_PATH $cuda/lib64
prepend-path MANPATH $cuda/share/man
prepend-path LIBRARY_PATH $cuda/lib64
prepend-path CPATH $cuda/include
[root@r9 ~]# module use /apps/modulefiles/
[root@r9 ~]# module load cuda/12.8
[root@r9 ~]# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Fri_Feb_21_20:23:50_PST_2025
Cuda compilation tools, release 12.8, V12.8.93
Build cuda_12.8.r12.8/compiler.35583870_0
[root@r9 ~]#次に
Githubに「python <= 3.9 and pytorch」とあるので、condaでpython 3.9の環境を作り、そこに移り、pytorchを入れます
[root@r9 ~]# conda create -n ESM python=3.9 numpy matplotlib biotite pip -y
[root@r9 ~]# conda activate ESM
(ESM) [root@r9 ~]# conda list
:
matplotlib 3.9.4 py39hf3d152e_0 conda-forge
matplotlib-base 3.9.4 py39h16632d1_0 conda-forge
munkres 1.1.4 pyhd8ed1ab_1 conda-forge
ncurses 6.6 hdb14827_0 conda-forge
numpy 2.0.2 py39h9cb892a_1 conda-forge
:
python 3.9.23 hc30ae73_0_cpython conda-forge
:
(ESM) [root@r9 ~]#ここで pytorchはhttps://pytorch.org/get-started/locally/
を拝見したが、最新のpytorch-2.11はpython3.10以降の様子.
アーカイブをみるとhttps://download.pytorch.org/whl/torch/
python3.9向けには torch 2.7.0/torch 2.8.0 で cuda128向けがある。
使っているGPUはblackwellなので cuda-12.8 以降が前提. ここでは cuda-12.8 を使います
(ESM) [root@r9 ~]# pip install "https://download-r2.pytorch.org/whl/cu128/torch-2.7.0+cu128-cp39-cp39-manylinux_2_28_x86_64.whl"
(ESM) [root@r9 ~]# conda list
:
matplotlib 3.9.4 py39hf3d152e_0 conda-forge
matplotlib-base 3.9.4 py39h16632d1_0 conda-forge
mpmath 1.3.0 pypi_0 pypi
munkres 1.1.4 pyhd8ed1ab_1 conda-forge
ncurses 6.6 hdb14827_0 conda-forge
networkx 3.2.1 pypi_0 pypi
numpy 2.0.2 py39h9cb892a_1 conda-forge
:
python 3.9.23 hc30ae73_0_cpython conda-forge
:
torch 2.7.0+cu128 pypi_0 pypi
:
(ESM) [root@r9 ~]#
(テスト)
(ESM) [root@r9 ~]# python
Python 3.9.23 | packaged by conda-forge | (main, Jun 4 2025, 17:57:12)
[GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import torch
>>> print(torch.cuda.is_available())
True
>>> print(torch.cuda.get_device_name())
NVIDIA RTX PRO 2000 Blackwell
>>>
>>> quit();
(ESM) [root@r9 ~]#これで下準備は完了
っで
(ESM) [root@r9 ~]# pip install fair-esm[esmfold]
(ESM) [root@r9 ~]# conda list
:
deepspeed 0.5.9 pypi_0 pypi
:
fair-esm 2.0.0 pypi_0 pypi
:
(ESM) [root@r9 ~]# pip install 'dllogger @ git+https://github.com/NVIDIA/dllogger.git'
(ESM) [root@r9 ~]# conda list
:
dllogger 1.1.0 pypi_0 pypi
:
(ESM) [root@r9 ~]#ドキュメントとかでは次は「pip install 'openfold @ git+https://github.com/aqlaboratory/openfold.git@4b41059694619831a7db195b7e0988fc4ff3a307'
」となるのですが、
buildが上手くいかない.
なのでソースを取ってきてソースに修正を加えます
(ESM) [root@r9 ~]# git clone https://github.com/aqlaboratory/openfold.git
(ESM) [root@r9 ~]# cd openfold
(ESM) [root@r9 openfold]# git checkout 4b41059694619831a7db195b7e0988fc4ff3a307そしてちょいと修正します
|
その上で
(ESM) [root@r9 openfold]# which nvcc <-- nvcc にPATHが通っている事
/usr/local/cuda-12.8/bin/nvcc
(ESM) [root@r9 openfold]# pip install . --no-build-isolation --no-use-pep517
(ESM) [root@r9 openfold]# pip uninstall -y deepspeed
(ESM) [root@r9 openfold]# pip install --no-build-isolation deepspeed
:
deepspeed 0.19.0 pypi_0 pypi
:
(ESM) [root@r9 openfold]#あと一部openfoldで修正箇所があります
deepspeedが 0.5.9 --> 0.19.0 に変更になったためです
|
ここでテストを実施します
(ESM) [root@r9 openfold]# python -c "import openfold; print('OK')"
OK
(ESM) [root@r9 openfold]# python -c "from openfold.utils.kernel.attention_core import attention_core; print('CUDA kernel OK')"
CUDA kernel OK
(ESM) [root@r9 openfold]# conda deactivate
[root@r9 ~]#っで一応完成っぽい
EnvironmentModules
[root@r9 ~]# vi /apps/modulefiles/ESM
#%Module
module load cuda/12.8
set root /apps/pyenv/versions/miniforge3-26.1.1-3/envs/ESM
prepend-path PATH $root/bin
prepend-path LD_LIBRARY_PATH $root/lib
[root@r9 ~]#使い方としては module load されて、自分のホームディレクトリに落とした git 内で使うといった感じがいいのかも
最近は、自分でconda環境を用意してそこで運用という前提が多いかな
[saber@r9 ~]$ git clone https://github.com/facebookresearch/esm ESM
[saber@r9 ~]$ cd ESM/
[saber@r9 ESM]$ ls -lF
total 84
-rw-r--r-- 1 saber saber 268 May 12 23:44 CODE_OF_CONDUCT.rst
-rw-r--r-- 1 saber saber 1253 May 12 23:44 CONTRIBUTING.md
-rw-r--r-- 1 saber saber 888 May 12 23:44 environment.yml
drwxr-xr-x 5 saber saber 4096 May 12 23:44 esm/
drwxr-xr-x 7 saber saber 4096 May 12 23:44 examples/
-rw-r--r-- 1 saber saber 1271 May 12 23:44 hubconf.py
-rw-r--r-- 1 saber saber 1088 May 12 23:44 LICENSE
-rw-r--r-- 1 saber saber 132 May 12 23:44 pyproject.toml
-rw-r--r-- 1 saber saber 46320 May 12 23:44 README.md
drwxr-xr-x 3 saber saber 98 May 12 23:44 scripts/
-rw-r--r-- 1 saber saber 1514 May 12 23:44 setup.py
drwxr-xr-x 2 saber saber 173 May 12 23:44 tests/
[saber@r9 ESM]$っでテスト
[saber@r9 ESM]$ module load ESM
Loading ESM
Loading requirement: cuda/12.8
[saber@r9 ESM]$
[saber@r9 ESM]$ which python
/apps/pyenv/versions/miniforge3-26.1.1-3/envs/ESM/bin/python
[saber@r9 ESM]$ python -V
Python 3.9.23
[saber@r9 ESM]$ python
Python 3.9.23 | packaged by conda-forge | (main, Jun 4 2025, 17:57:12)
[GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import torch
>>> import esm
>>>
>>> model, alphabet = esm.pretrained.esm2_t33_650M_UR50D()
Downloading: "https://dl.fbaipublicfiles.com/fair-esm/models/esm2_t33_650M_UR50D.pt" to /home/saber/.cache/torch/hub/checkpoints/esm2_t33_650M_UR50D.pt
Downloading: "https://dl.fbaipublicfiles.com/fair-esm/regression/esm2_t33_650M_UR50D-contact-regression.pt" to /home/saber/.cache/torch/hub/checkpoints/esm2_t33_650M_UR50D-contact-regression.pt
>>>
>>> batch_converter = alphabet.get_batch_converter()
>>> model.eval()
ESM2(
(embed_tokens): Embedding(33, 1280, padding_idx=1)
(layers): ModuleList(
(0-32): 33 x TransformerLayer(
(self_attn): MultiheadAttention(
(k_proj): Linear(in_features=1280, out_features=1280, bias=True)
(v_proj): Linear(in_features=1280, out_features=1280, bias=True)
(q_proj): Linear(in_features=1280, out_features=1280, bias=True)
(out_proj): Linear(in_features=1280, out_features=1280, bias=True)
(rot_emb): RotaryEmbedding()
)
(self_attn_layer_norm): LayerNorm((1280,), eps=1e-05, elementwise_affine=True)
(fc1): Linear(in_features=1280, out_features=5120, bias=True)
(fc2): Linear(in_features=5120, out_features=1280, bias=True)
(final_layer_norm): LayerNorm((1280,), eps=1e-05, elementwise_affine=True)
)
)
(contact_head): ContactPredictionHead(
(regression): Linear(in_features=660, out_features=1, bias=True)
(activation): Sigmoid()
)
(emb_layer_norm_after): LayerNorm((1280,), eps=1e-05, elementwise_affine=True)
(lm_head): RobertaLMHead(
(dense): Linear(in_features=1280, out_features=1280, bias=True)
(layer_norm): LayerNorm((1280,), eps=1e-05, elementwise_affine=True)
)
)
>>>
>>>
>>> data = [
... ("protein1", "MKTVRQERLKSIVRILERSKEPVSGAQLAEELSVSRQVIVQDIAYLRSLGYNIVATPRGYVLAGG"),
... ("protein2", "KALTARQQEVFDLIRDHISQTGMPPTRAEIAQRLGFRSPNAAEEHLKALARKGVIEIVSGASRGIRLLQEE"),
... ("protein2 with mask","KALTARQQEVFDLIRD<mask>ISQTGMPPTRAEIAQRLGFRSPNAAEEHLKALARKGVIEIVSGASRGIRLLQEE"),
... ("protein3", "K A <mask> I S Q"),
... ]
>>>
>>>
>>> batch_labels, batch_strs, batch_tokens = batch_converter(data)
>>> batch_lens = (batch_tokens != alphabet.padding_idx).sum(1)
>>>
>>> with torch.no_grad():
... results = model(batch_tokens, repr_layers=[33], return_contacts=True)
...
>>> token_representations = results["representations"][33]
>>>
>>> sequence_representations = []
>>> for i, tokens_len in enumerate(batch_lens):
... sequence_representations.append(token_representations[i, 1 : tokens_len - 1].mean(0))
...
>>>
>>> import matplotlib.pyplot as plt
>>> for (_, seq), tokens_len, attention_contacts in zip(data, batch_lens, results["contacts"]):
... plt.matshow(attention_contacts[: tokens_len, : tokens_len])
... plt.title(seq)
... plt.show()ここで画面が表示されます. 画面を閉じると次の画像が表示されます

っでさらにテスト
ESMFフォールド構造予測
[illya@rockylinux ~]$ python
Python 3.9.15 (main, Nov 4 2022, 16:13:54)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import esm
>>> model = esm.pretrained.esmfold_v1()
Downloading: "https://dl.fbaipublicfiles.com/fair-esm/models/esmfold_3B_v1.pt" to /home/illya/.cache/torch/hub/checkpoints/esmfold_3B_v1.pt
Downloading: "https://dl.fbaipublicfiles.com/fair-esm/models/esm2_t36_3B_UR50D.pt" to /home/illya/.cache/torch/hub/checkpoints/esm2_t36_3B_UR50D.pt
Downloading: "https://dl.fbaipublicfiles.com/fair-esm/regression/esm2_t36_3B_UR50D-contact-regression.pt" to /home/illya/.cache/torch/hub/checkpoints/esm2_t36_3B_UR50D-contact-regression.pt
>>>
>>>
>>>
>>> exit()
[illya@rockylinux ~]$root@ubuntu24:~# grep VERSION_ID /etc/os-release
VERSION_ID="24.04"
root@ubuntu24:~# cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX Open Kernel Module for x86_64 595.71.05 Release Build (dvs-builder@U22-I3-G08-03-1) Fri Apr 24 06:42:30 UTC 2026
GCC version: gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1)
root@ubuntu24:~# nvidia-smi -L
GPU 0: NVIDIA RTX PRO 2000 Blackwell (UUID: GPU-40660e37-0d35-d4f4-294a-eee3fe83049e)
root@ubuntu24:~#git clone https://github.com/yyuu/pyenv.git /apps/pyenv
export PYENV_ROOT=/apps/pyenv
export PATH=$PYENV_ROOT/bin:$PATH
pyenv install miniforge3-26.3.2-1
source /apps/pyenv/versions/miniforge3-26.3.2-1/etc/profile.d/conda.sh
conda update conda
module load cuda/12.9
conda create -n ESM python=3.9 numpy matplotlib biotite pip -y
conda activate ESM
pip install https://download-r2.pytorch.org/whl/cu129/torch-2.8.0%2Bcu129-cp39-cp39-manylinux_2_28_x86_64.whl
pip install fair-esm[esmfold]
pip install 'dllogger @ git+https://github.com/NVIDIA/dllogger.git'
git clone https://github.com/aqlaboratory/openfold.git
cd openfold
git checkout 4b41059694619831a7db195b7e0988fc4ff3a307
vi openfold/utils/seed.py
vi setup.py
pip install . --no-build-isolation --no-use-pep517
pip uninstall -y deepspeed
pip install --no-build-isolation deepspeed
vi /apps/pyenv/versions/miniforge3-26.3.2-1/envs/ESM/lib/python3.9/site-packages/openfold/model/primitives.py