🚀 ESM++
ESM++ は、ESMC(ライセンス)を忠実に実装したものです。ESM Pythonパッケージを必要とせずに、バッチ処理と標準的なHuggingface互換性を提供します。小規模バージョンは、ESMCの3億パラメータバージョンに相当します。
🚀 クイックスタート
以前、Huggingfaceの重み共有に関するバグがあり、ESM++のロジットがESMCと異なる原因となっていました。このバグは現在解決されています。
✨ 主な機能
- ESM++は、ESM Pythonパッケージを必要とせずに、バッチ処理とHuggingface互換性を提供します。
- シーケンスとトークンレベルの分類タスクをサポートしています。
- fp32、fp16、bf16の重みをサポートしています。
- 🤗 peftを使用した微調整が可能です。
- 注意マップを返すオプションがあります。
💻 使用例
基本的な使用法
from transformers import AutoModelForMaskedLM
model = AutoModelForMaskedLM.from_pretrained('Synthyra/ESMplusplus_small', trust_remote_code=True)
tokenizer = model.tokenizer
sequences = ['MPRTEIN', 'MSEQWENCE']
tokenized = tokenizer(sequences, padding=True, return_tensors='pt')
output = model(**tokenized)
print(output.logits.shape)
print(output.last_hidden_state.shape)
print(output.loss)
高度な使用法
シーケンス分類タスク
from transformers import AutoModelForSequenceClassification, AutoModelForTokenClassification
model = AutoModelForSequenceClassification.from_pretrained('Synthyra/ESMplusplus_small', num_labels=2, trust_remote_code=True)
logits = model(**tokenized).logits
print(logits.shape)
データセットの埋め込み
embedding_dict = model.embed_dataset(
sequences=[
'MALWMRLLPLLALLALWGPDPAAA', ...
],
tokenizer=model.tokenizer,
batch_size=2,
max_len=512,
full_embeddings=False,
embed_dtype=torch.float32,
pooling_types=['mean', 'cls'],
num_workers=0,
sql=False,
sql_db_path='embeddings.db',
save=True,
save_path='embeddings.pth',
)
model.embed_dataset()
Args:
sequences: List of protein sequences
batch_size: Batch size for processing
max_len: Maximum sequence length
full_embeddings: Whether to return full residue-wise (True) embeddings or pooled (False)
pooling_type: Type of pooling ('mean' or 'cls')
num_workers: Number of workers for data loading, 0 for the main process
sql: Whether to store embeddings in SQLite database - will be stored in float32
sql_db_path: Path to SQLite database
Returns:
Dictionary mapping sequences to embeddings, or None if sql=True
Note:
- If sql=True, embeddings can only be stored in float32
- sql is ideal if you need to stream a very large dataset for training in real-time
- save=True is ideal if you can store the entire embedding dictionary in RAM
- sql will be used if it is True and save is True or False
- If your sql database or .pth file is already present, they will be scanned first for already embedded sequences
- Sequences will be truncated to max_len and sorted by length in descending order for faster processing
🤗 peftを使用した微調整
model = AutoModelForSequenceClassification.from_pretrained('Synthyra/ESMplusplus_small', num_labels=2, trust_remote_code=True)
target_modules = ["layernorm_qkv.1", "out_proj", "query", "key", "value", "dense"]
lora_config = LoraConfig(
r=8,
lora_alpha=16,
lora_dropout=0.01,
bias="none",
target_modules=target_modules,
)
model = get_peft_model(model, lora_config)
for param in model.classifier.parameters():
param.requires_grad = True
注意マップの返却
output = model(**tokenized, output_attentions=True)
att = output.attentions
len(att)
📚 ドキュメント
浮動小数点精度と実装の比較
fp32の重みとfp16またはbf16の最後の隠れ層の状態の差を測定しました。fp16はfp32の出力に近いことがわかったので、fp16での読み込みをおすすめします。
- Average MSE FP32 vs. FP16: 0.00000003
- Average MSE FP32 vs. BF16: 0.00000140
また、1000のランダムなシーケンスに対するESM++とESMC(どちらもbfloat16)の出力の差を測定し、ESMパッケージとの互換性を確認しました。
- Average MSE of last hidden state: 7.74e-10
.transformersの代わりにESMパッケージから重みを読み込むには、.from_pretrained(...)を.from_pretrained_esm('esmc_300m')に置き換えます。
モデルプローブ
以前の論文と同様に、さまざまなPLMと標準データセットに線形プロービング技術を適用し、プールされた隠れ層の状態と重要な特性の間の内在的な相関を評価します。ESMC(したがってESM++)は非常に良好な性能を示します。

推論速度
さまざまなESMモデルとそれらのH100でのスループットを調べました。ESMCとESM++の間で効率的なバッチ処理を追加することで、スループットが大幅に向上します。バッチサイズが1の場合でも、ESM++はESMCよりも高速です。ESM++ smallは、長いシーケンスではESM2-35Mよりもさらに高速です!LinuxマシンでPyTorch > 2.5を使用すると、最も大きなメリットが得られます。

引用
この実装や成果を使用する場合は、(ESM Cのプレプリントとともに)引用してください。
@misc {ESMPlusPlus,
author = { Hallee, L. and Bichara, D. and Gleghorn, J, P. },
title = { ESMPlusPlus },
year = 2024,
url = { https://huggingface.co/Synthyra/ESMplusplus_small },
doi = { 10.57967/hf/3725 },
publisher = { Hugging Face }
}