Agent Skillsaipoch/open-science › fair-esm2

fair-esm2

GitHub

使用 Meta ESM-2 模型提取蛋白质嵌入、进行突变效应评分及接触预测。支持本地 GPU 运行与远程计算,适用于下游机器学习任务中的序列表示学习。

resources/skills/fair-esm2/SKILL.md aipoch/open-science

Trigger Scenarios

需要蛋白质序列嵌入向量 评估氨基酸突变对蛋白质的影响 从序列预测蛋白质接触图

Install

npx skills add aipoch/open-science --skill fair-esm2 -g -y
More Options

Non-standard path

npx skills add https://github.com/aipoch/open-science/tree/main/resources/skills/fair-esm2 -g -y

Use without installing

npx skills use aipoch/open-science@fair-esm2

指定 Agent (Claude Code)

npx skills add aipoch/open-science --skill fair-esm2 -a claude-code -g -y

安装 repo 全部 skill

npx skills add aipoch/open-science --all -g -y

预览 repo 内 skill

npx skills add aipoch/open-science --list

SKILL.md

Frontmatter
{
    "name": "fair-esm2",
    "license": "Apache-2.0",
    "category": "biomodels",
    "metadata": {
        "third_party": [
            {
                "kind": "weights",
                "name": "ESM-2",
                "license": "MIT",
                "provider": "Meta AI",
                "terms_url": "https:\/\/github.com\/facebookresearch\/esm\/blob\/main\/LICENSE"
            }
        ],
        "display-name": "ESM-2"
    },
    "description": "Embed proteins with Meta AI's ESM-2 (`fair-esm` package). Use this skill when: (1) Extracting per-residue or per-sequence embeddings for downstream ML, (2) Masked-LM likelihood \/ mutation effect scoring, (3) Contact prediction from a sequence.\n",
    "requirements": [
        "gpu"
    ]
}

fair-esm2 — ESM-2 (Meta AI)

ESM-2 code and weights are MIT (Meta AI, github.com/facebookresearch/esm).

Package disambiguation. pip install fair-esm gives you import esm with esm.pretrained.* (ESM-1/2). Biohub's github.com/Biohub/esm fork (MIT) gives you from esm.models.esmfold2 import ESMFold2InputBuilder — see the esmfold2 skill. Both share the esm namespace but are different libraries. This skill covers fair-esm (the Meta package).

Prerequisites

Requirement Minimum Recommended
Python 3.8+ 3.11
CUDA 11.7+ 12.x
GPU VRAM 8 GB (8M), 16 GB (650M) 24 GB+ (650M / 3B)

How to run

Embeddings

import torch, esm

model, alphabet = esm.pretrained.esm2_t33_650M_UR50D()
model = model.eval().cuda()
bc = alphabet.get_batch_converter()

_, _, toks = bc([("ubq", "MQIFVKTLTGKTITLEVEPSDTIENVK")])
with torch.no_grad():
    out = model(toks.cuda(), repr_layers=[33])
emb = out["representations"][33]      # (1, L+2, 1280) — includes BOS/EOS
seq_emb = emb[0, 1:-1].mean(0)        # per-sequence mean

Masked-LM scoring

with torch.no_grad():
    out = model(toks.cuda(), repr_layers=[33])
logits = out["logits"][0, 1:-1]       # (L, |vocab|)
# WT marginal log-likelihood; for mutation scoring, mask the position and
# compare logit[mut] − logit[wt].

Contact prediction

with torch.no_grad():
    out = model(toks.cuda(), repr_layers=[33], return_contacts=True)
contacts = out["contacts"][0]         # (L, L)

Models

Name Layers Dim Params Use
esm2_t6_8M_UR50D 6 320 8 M Fast smoke / tiny embeddings
esm2_t33_650M_UR50D 33 1280 650 M Default embedding model
esm2_t36_3B_UR50D 36 2560 3 B Best embeddings, 24 GB+

Output format

out["representations"][layer] is (B, L+2, D); slice [ :, 1:-1, : ] to drop BOS/EOS. out["contacts"] (when return_contacts=True) is (B, L, L).

Remote compute

Needs ≥16 GB VRAM (650M model) and either pre-cached .pt checkpoints or egress to dl.fbaipublicfiles.com. Read compute_details({provider, mode:'read'}) for an environment with fair-esm and a torch-hub weight cache, then:

c = host.compute.create(provider)
job = c.submitJob(
    intent="ESM-2 650M embeddings for 200 sequences — 1×GPU, ~2 min",
    inputs=[
        {"src": "seqs.fasta", "dstFilename": "seqs.fasta"},
        {"src": "embed_esm2.py", "dstFilename": "embed_esm2.py"},
    ],
    command="python3 embed_esm2.py",
    environment=...,   # env name from compute_details
    outputs=["embeddings.pt"],
    timeoutSeconds=1800,
)
print(job.job_id)   # cell ends here — kernel never blocks on compute

Retain the exact returned job_id. Query that saved ID with the non-blocking c.attachJob(job_id).status() or .result() when its state or result is relevant; do not scan Job history. A final .result() read reports whether its follow-up was suppressed or had already been committed; otherwise the app starts the later analysis turn for an unread final result. See the remote-compute-ssh skill for details.

Inside embed_esm2.py, set TORCH_HOME to the provider's torch-hub cache mount (path is in compute_details) so esm.pretrained.* resolves locally.

Troubleshooting

Symptom Cause Fix
ModuleNotFoundError: No module named 'esm.models' You want Biohub's esm fork, not fair-esm See esmfold2 skill; this skill uses esm.pretrained.*
Slow first call Downloading weights via torch.hub Set TORCH_HOME to a cached location

Next: feed embeddings to a classifier. For structure prediction, use esmfold2.

Version History

  • 44394f0 Current 2026-09-11 11:10

Same Skill Collection

resources/skills/alphafold2/SKILL.md
resources/skills/boltz/SKILL.md
resources/skills/borzoi/SKILL.md
resources/skills/chai1/SKILL.md
resources/skills/compute-env-setup/SKILL.md
resources/skills/customize/SKILL.md
resources/skills/diffdock/SKILL.md
resources/skills/env-management/SKILL.md
resources/skills/evo2/SKILL.md
resources/skills/figure-composer/SKILL.md
resources/skills/figure-style/SKILL.md
resources/skills/indication-dossier/SKILL.md
resources/skills/ligandmpnn/SKILL.md
resources/skills/literature-review/SKILL.md
resources/skills/openfold3/SKILL.md
resources/skills/paper-narrative/SKILL.md
resources/skills/proteinmpnn/SKILL.md
resources/skills/remote-compute-ssh/SKILL.md
resources/skills/scgpt/SKILL.md
resources/skills/scvi-tools/SKILL.md
resources/skills/self-awareness/SKILL.md
resources/skills/skill-creator/SKILL.md
resources/skills/solublempnn/SKILL.md
resources/skills/esmfold2/SKILL.md

Metadata

Files
0
Version
44394f0
Hash
6e0f0863
Indexed
2026-09-11 11:10

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-12 07:25
浙ICP备14020137号-1 $お客様$