Instructions to use Synthyra/ESM3_small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Synthyra/ESM3_small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Synthyra/ESM3_small", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Synthyra/ESM3_small", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,159 +1,159 @@
|
|
| 1 |
-
---
|
| 2 |
-
library_name: transformers
|
| 3 |
-
license: mit
|
| 4 |
-
tags:
|
| 5 |
-
- biology
|
| 6 |
-
- protein-language-model
|
| 7 |
-
- esm3
|
| 8 |
-
- multimodal-protein-model
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# FastPLMs ESM3 Small
|
| 12 |
-
|
| 13 |
-
FastPLMs ESM3 Small is a Hugging Face compatible implementation of Biohub's open ESM3 small model. It loads through `AutoModel`, supports sequence-only inference by default, and exposes ESM3's additional tensor tracks directly through normal keyword arguments.
|
| 14 |
-
|
| 15 |
-
This repository includes the Biohub ESM MIT license in `LICENSE`.
|
| 16 |
-
|
| 17 |
-
## Use With Transformers
|
| 18 |
-
|
| 19 |
-
```python
|
| 20 |
-
import torch
|
| 21 |
-
from transformers import AutoModel
|
| 22 |
-
|
| 23 |
-
model = AutoModel.from_pretrained(
|
| 24 |
-
"Synthyra/ESM3_small",
|
| 25 |
-
trust_remote_code=True,
|
| 26 |
-
dtype=torch.bfloat16,
|
| 27 |
-
device_map="cuda",
|
| 28 |
-
).eval()
|
| 29 |
-
|
| 30 |
-
sequences = ["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"]
|
| 31 |
-
tokens = model.tokenize_sequences(sequences, device=model.device)
|
| 32 |
-
|
| 33 |
-
with torch.inference_mode():
|
| 34 |
-
output = model(**tokens)
|
| 35 |
-
|
| 36 |
-
print(output.logits.shape) # sequence logits, (batch_size, seq_len, 64)
|
| 37 |
-
print(output.last_hidden_state.shape) # ESM3 embeddings, (batch_size, seq_len, hidden_size)
|
| 38 |
-
print(output.function_logits.shape) # function logits, (batch_size, seq_len, 8, 260)
|
| 39 |
-
```
|
| 40 |
-
|
| 41 |
-
You can also call sequence inference directly:
|
| 42 |
-
|
| 43 |
-
```python
|
| 44 |
-
output = model.forward_sequence(["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"])
|
| 45 |
-
```
|
| 46 |
-
|
| 47 |
-
Switch between SDPA and Flex Attention after loading:
|
| 48 |
-
|
| 49 |
-
```python
|
| 50 |
-
model.attn_backend = "flex"
|
| 51 |
-
output = model.forward_sequence(["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"])
|
| 52 |
-
model.attn_backend = "sdpa"
|
| 53 |
-
```
|
| 54 |
-
|
| 55 |
-
## Embed Entire Datasets
|
| 56 |
-
|
| 57 |
-
To embed a list of protein sequences, call `embed_dataset`. Sequences are deduplicated, sorted by length, optionally truncated, and embedded in batches.
|
| 58 |
-
|
| 59 |
-
```python
|
| 60 |
-
embedding_dict = model.embed_dataset(
|
| 61 |
-
sequences=[
|
| 62 |
-
"MALWMRLLPLLALLALWGPDPAAA",
|
| 63 |
-
"MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP",
|
| 64 |
-
],
|
| 65 |
-
batch_size=2,
|
| 66 |
-
max_len=512,
|
| 67 |
-
full_embeddings=False,
|
| 68 |
-
embed_dtype=torch.float32,
|
| 69 |
-
pooling_types=["mean", "cls"],
|
| 70 |
-
save=True,
|
| 71 |
-
save_path="esm3_embeddings.pth",
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
# embedding_dict maps sequence strings to pooled tensors.
|
| 75 |
-
print(embedding_dict["MALWMRLLPLLALLALWGPDPAAA"].shape)
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
-
Residue-wise embeddings are available by setting `full_embeddings=True`:
|
| 79 |
-
|
| 80 |
-
```python
|
| 81 |
-
residue_embeddings = model.embed_dataset(
|
| 82 |
-
sequences=["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"],
|
| 83 |
-
batch_size=1,
|
| 84 |
-
max_len=512,
|
| 85 |
-
full_embeddings=True,
|
| 86 |
-
save=False,
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
print(residue_embeddings["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"].shape)
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
FASTA input is also supported:
|
| 93 |
-
|
| 94 |
-
```python
|
| 95 |
-
embedding_dict = model.embed_dataset(
|
| 96 |
-
fasta_path="proteins.fasta",
|
| 97 |
-
batch_size=4,
|
| 98 |
-
pooling_types=["mean"],
|
| 99 |
-
save_path="esm3_fasta_embeddings.pth",
|
| 100 |
-
)
|
| 101 |
-
```
|
| 102 |
-
|
| 103 |
-
`embed_dataset` currently supports pooled `mean`, `cls`, and `max` embeddings, plus unpooled residue embeddings. It supports `.pth` saves; SQLite streaming is not enabled for the ESM3 wrapper yet.
|
| 104 |
-
|
| 105 |
-
## Multimodal Track Arguments
|
| 106 |
-
|
| 107 |
-
The default path is amino acid sequence inference. Additional ESM3 tracks can be supplied directly using the same tensor shapes as Biohub ESM3:
|
| 108 |
-
|
| 109 |
-
```python
|
| 110 |
-
tokens = model.tokenize_sequences(
|
| 111 |
-
["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"],
|
| 112 |
-
device=model.device,
|
| 113 |
-
)
|
| 114 |
-
|
| 115 |
-
function_tokens = tokens["input_ids"].new_zeros((*tokens["input_ids"].shape, 8))
|
| 116 |
-
|
| 117 |
-
with torch.inference_mode():
|
| 118 |
-
output = model(
|
| 119 |
-
**tokens,
|
| 120 |
-
function_tokens=function_tokens,
|
| 121 |
-
)
|
| 122 |
-
|
| 123 |
-
print(output.sequence_logits.shape)
|
| 124 |
-
print(output.function_logits.shape)
|
| 125 |
-
```
|
| 126 |
-
|
| 127 |
-
Accepted track arguments include `sequence_tokens`, `structure_tokens`, `ss8_tokens`, `sasa_tokens`, `function_tokens`, `residue_annotation_tokens`, `average_plddt`, `per_res_plddt`, `structure_coords`, `chain_id`, and `sequence_id`. `input_ids` aliases `sequence_tokens`, and `attention_mask` is converted into `sequence_id` if no explicit `sequence_id` is provided.
|
| 128 |
-
|
| 129 |
-
## Loading Biohub Checkpoints Locally
|
| 130 |
-
|
| 131 |
-
You can build the FastPLMs wrapper from the Biohub checkpoint directly:
|
| 132 |
-
|
| 133 |
-
```python
|
| 134 |
-
from fastplms.esm3.modeling_esm3 import FastESM3Model
|
| 135 |
-
|
| 136 |
-
model = FastESM3Model.from_pretrained_esm("esm3-sm-open-v1", device="cuda")
|
| 137 |
-
```
|
| 138 |
-
|
| 139 |
-
This requires Hugging Face access to the gated `biohub/esm3-sm-open-v1` source repo.
|
| 140 |
-
|
| 141 |
-
## Biohub SDK Compatibility
|
| 142 |
-
|
| 143 |
-
The core forward path is self-contained. Higher-level Biohub SDK workflows are delegated lazily to the official `esm` submodule when available:
|
| 144 |
-
|
| 145 |
-
```python
|
| 146 |
-
# These methods use Biohub SDK dataclasses and generation configs.
|
| 147 |
-
encoded = model.encode(esm_protein)
|
| 148 |
-
decoded = model.decode(encoded)
|
| 149 |
-
generated = model.generate(esm_protein, generation_config)
|
| 150 |
-
```
|
| 151 |
-
|
| 152 |
-
Available delegated methods include `encode`, `decode`, `generate`, `batch_generate`, `logits`, and `forward_and_sample`.
|
| 153 |
-
|
| 154 |
-
## Source
|
| 155 |
-
|
| 156 |
-
- Biohub ESM repository: https://github.com/Biohub/esm
|
| 157 |
-
- Biohub ESM license: https://github.com/Biohub/esm/blob/main/LICENSE.md
|
| 158 |
-
- Paper: https://biohub.ai/papers/esm_protein.pdf
|
| 159 |
-
- Official model source: https://huggingface.co/biohub/esm3-sm-open-v1
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- biology
|
| 6 |
+
- protein-language-model
|
| 7 |
+
- esm3
|
| 8 |
+
- multimodal-protein-model
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# FastPLMs ESM3 Small
|
| 12 |
+
|
| 13 |
+
FastPLMs ESM3 Small is a Hugging Face compatible implementation of Biohub's open ESM3 small model. It loads through `AutoModel`, supports sequence-only inference by default, and exposes ESM3's additional tensor tracks directly through normal keyword arguments.
|
| 14 |
+
|
| 15 |
+
This repository includes the Biohub ESM MIT license in `LICENSE`.
|
| 16 |
+
|
| 17 |
+
## Use With Transformers
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
import torch
|
| 21 |
+
from transformers import AutoModel
|
| 22 |
+
|
| 23 |
+
model = AutoModel.from_pretrained(
|
| 24 |
+
"Synthyra/ESM3_small",
|
| 25 |
+
trust_remote_code=True,
|
| 26 |
+
dtype=torch.bfloat16,
|
| 27 |
+
device_map="cuda",
|
| 28 |
+
).eval()
|
| 29 |
+
|
| 30 |
+
sequences = ["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"]
|
| 31 |
+
tokens = model.tokenize_sequences(sequences, device=model.device)
|
| 32 |
+
|
| 33 |
+
with torch.inference_mode():
|
| 34 |
+
output = model(**tokens)
|
| 35 |
+
|
| 36 |
+
print(output.logits.shape) # sequence logits, (batch_size, seq_len, 64)
|
| 37 |
+
print(output.last_hidden_state.shape) # ESM3 embeddings, (batch_size, seq_len, hidden_size)
|
| 38 |
+
print(output.function_logits.shape) # function logits, (batch_size, seq_len, 8, 260)
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
You can also call sequence inference directly:
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
output = model.forward_sequence(["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"])
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Switch between SDPA and Flex Attention after loading:
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
model.attn_backend = "flex"
|
| 51 |
+
output = model.forward_sequence(["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"])
|
| 52 |
+
model.attn_backend = "sdpa"
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## Embed Entire Datasets
|
| 56 |
+
|
| 57 |
+
To embed a list of protein sequences, call `embed_dataset`. Sequences are deduplicated, sorted by length, optionally truncated, and embedded in batches.
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
embedding_dict = model.embed_dataset(
|
| 61 |
+
sequences=[
|
| 62 |
+
"MALWMRLLPLLALLALWGPDPAAA",
|
| 63 |
+
"MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP",
|
| 64 |
+
],
|
| 65 |
+
batch_size=2,
|
| 66 |
+
max_len=512,
|
| 67 |
+
full_embeddings=False,
|
| 68 |
+
embed_dtype=torch.float32,
|
| 69 |
+
pooling_types=["mean", "cls"],
|
| 70 |
+
save=True,
|
| 71 |
+
save_path="esm3_embeddings.pth",
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
# embedding_dict maps sequence strings to pooled tensors.
|
| 75 |
+
print(embedding_dict["MALWMRLLPLLALLALWGPDPAAA"].shape)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
Residue-wise embeddings are available by setting `full_embeddings=True`:
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
residue_embeddings = model.embed_dataset(
|
| 82 |
+
sequences=["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"],
|
| 83 |
+
batch_size=1,
|
| 84 |
+
max_len=512,
|
| 85 |
+
full_embeddings=True,
|
| 86 |
+
save=False,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
print(residue_embeddings["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"].shape)
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
FASTA input is also supported:
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
embedding_dict = model.embed_dataset(
|
| 96 |
+
fasta_path="proteins.fasta",
|
| 97 |
+
batch_size=4,
|
| 98 |
+
pooling_types=["mean"],
|
| 99 |
+
save_path="esm3_fasta_embeddings.pth",
|
| 100 |
+
)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
`embed_dataset` currently supports pooled `mean`, `cls`, and `max` embeddings, plus unpooled residue embeddings. It supports `.pth` saves; SQLite streaming is not enabled for the ESM3 wrapper yet.
|
| 104 |
+
|
| 105 |
+
## Multimodal Track Arguments
|
| 106 |
+
|
| 107 |
+
The default path is amino acid sequence inference. Additional ESM3 tracks can be supplied directly using the same tensor shapes as Biohub ESM3:
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
tokens = model.tokenize_sequences(
|
| 111 |
+
["MKTAYIAKQRQISFVKSHFSRQDILDLWIYHTQGYFP"],
|
| 112 |
+
device=model.device,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
function_tokens = tokens["input_ids"].new_zeros((*tokens["input_ids"].shape, 8))
|
| 116 |
+
|
| 117 |
+
with torch.inference_mode():
|
| 118 |
+
output = model(
|
| 119 |
+
**tokens,
|
| 120 |
+
function_tokens=function_tokens,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
print(output.sequence_logits.shape)
|
| 124 |
+
print(output.function_logits.shape)
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
Accepted track arguments include `sequence_tokens`, `structure_tokens`, `ss8_tokens`, `sasa_tokens`, `function_tokens`, `residue_annotation_tokens`, `average_plddt`, `per_res_plddt`, `structure_coords`, `chain_id`, and `sequence_id`. `input_ids` aliases `sequence_tokens`, and `attention_mask` is converted into `sequence_id` if no explicit `sequence_id` is provided.
|
| 128 |
+
|
| 129 |
+
## Loading Biohub Checkpoints Locally
|
| 130 |
+
|
| 131 |
+
You can build the FastPLMs wrapper from the Biohub checkpoint directly:
|
| 132 |
+
|
| 133 |
+
```python
|
| 134 |
+
from fastplms.esm3.modeling_esm3 import FastESM3Model
|
| 135 |
+
|
| 136 |
+
model = FastESM3Model.from_pretrained_esm("esm3-sm-open-v1", device="cuda")
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
This requires Hugging Face access to the gated `biohub/esm3-sm-open-v1` source repo.
|
| 140 |
+
|
| 141 |
+
## Biohub SDK Compatibility
|
| 142 |
+
|
| 143 |
+
The core forward path is self-contained. Higher-level Biohub SDK workflows are delegated lazily to the official `esm` submodule when available:
|
| 144 |
+
|
| 145 |
+
```python
|
| 146 |
+
# These methods use Biohub SDK dataclasses and generation configs.
|
| 147 |
+
encoded = model.encode(esm_protein)
|
| 148 |
+
decoded = model.decode(encoded)
|
| 149 |
+
generated = model.generate(esm_protein, generation_config)
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
Available delegated methods include `encode`, `decode`, `generate`, `batch_generate`, `logits`, and `forward_and_sample`.
|
| 153 |
+
|
| 154 |
+
## Source
|
| 155 |
+
|
| 156 |
+
- Biohub ESM repository: https://github.com/Biohub/esm
|
| 157 |
+
- Biohub ESM license: https://github.com/Biohub/esm/blob/main/LICENSE.md
|
| 158 |
+
- Paper: https://biohub.ai/papers/esm_protein.pdf
|
| 159 |
+
- Official model source: https://huggingface.co/biohub/esm3-sm-open-v1
|