Run this model with HF Jobs
Run Synthyra/ESM2-650M on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Synthyra/ESM2-650M. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Synthyra/ESM2-650M on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Synthyra/ESM2-650M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Synthyra/ESM2-650M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="Synthyra/ESM2-650M", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForMaskedLM model = AutoModelForMaskedLM.from_pretrained("Synthyra/ESM2-650M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151---library_name: transformerstags: []---# NOTEThe GitHub with the implementation and requirements.txt can be found [here](https://github.com/Synthyra/FastPLMs.git)# FastESMFastESM is a Huggingface compatible plug in version of ESM2 rewritten with a newer PyTorch attention implementation.Load any ESM2 models into a FastEsm model to dramatically speed up training and inference without **ANY** cost in performance.## Attention backend defaults`sdpa` is the default attention backend for FastESM.To enable Flex Attention, set `attn_backend="flex"` on the config before model initialization/loading.For throughput and memory efficiency, `torch.compile(...)` is heavily recommended, especially when using Flex Attention.Outputting attention maps (or the contact prediction head) is not natively possible with the optimized attention backends (including Flex Attention). You can still pass ```output_attentions``` to have attention calculated manually and returned.Various other optimizations also make the base implementation slightly different than the one in transformers.## Use with 🤗 transformers### Supported models```pythonmodel_dict = {# Synthyra/ESM2-8M'ESM2-8M': 'facebook/esm2_t6_8M_UR50D',# Synthyra/ESM2-35M'ESM2-35M': 'facebook/esm2_t12_35M_UR50D',# Synthyra/ESM2-150M'ESM2-150M': 'facebook/esm2_t30_150M_UR50D',# Synthyra/ESM2-650M'ESM2-650M': 'facebook/esm2_t33_650M_UR50D',# Synthyra/ESM2-3B'ESM2-3B': 'facebook/esm2_t36_3B_UR50D',}```### For working with embeddings```pythonimport torchfrom transformers import AutoModel, AutoTokenizermodel_path = 'Synthyra/ESM2-8M'model = AutoModel.from_pretrained(model_path, dtype=torch.float16, trust_remote_code=True).eval()tokenizer = model.tokenizersequences = ['MPRTEIN', 'MSEQWENCE']tokenized = tokenizer(sequences, padding=True, return_tensors='pt')with torch.no_grad():embeddings = model(**tokenized).last_hidden_stateprint(embeddings.shape) # (2, 11, 1280)```### For working with sequence logits```pythonimport torchfrom transformers import AutoModelForMaskedLM, AutoTokenizermodel = AutoModelForMaskedLM.from_pretrained(model_path, dtype=torch.float16, trust_remote_code=True).eval()with torch.no_grad():logits = model(**tokenized).logitsprint(logits.shape) # (2, 11, 33)```### For working with attention maps```pythonimport torchfrom transformers import AutoModel, AutoTokenizermodel = AutoModel.from_pretrained(model_path, dtype=torch.float16, trust_remote_code=True).eval()with torch.no_grad():attentions = model(**tokenized, output_attentions).attentions # tuples of (batch_size, num_heads, seq_len, seq_len)print(attentions[-1].shape) # (2, 20, 11, 11)```### Contact predictionBecause we can output attentions using the naive attention implementation, the contact prediction is also supported```pythonwith torch.no_grad():contact_map = model.predict_contacts(**tokenized).squeeze().cpu().numpy() # (seq_len, seq_len)```## Embed entire datasets with no new codeTo embed a list of protein sequences **fast**, just call embed_dataset. Sequences are sorted to reduce padding tokens, so the initial progress bar estimation is usually much longer than the actual time it will take.Example:```pythonembedding_dict = model.embed_dataset(sequences=['MALWMRLLPLLALLALWGPDPAAA', ... # list of protein sequences],tokenizer=model.tokenizer,batch_size=2, # adjust for your GPU memorymax_len=512, # adjust for your needsfull_embeddings=False, # if True, no pooling is performedembed_dtype=torch.float32, # cast to what dtype you wantpooling_types=['mean', 'cls'], # more than one pooling type will be concatenated togethernum_workers=0, # if you have many cpu cores, we find that num_workers = 4 is fast for large datasetssql=False, # if True, embeddings will be stored in SQLite databasesql_db_path='embeddings.db',save=True, # if True, embeddings will be saved as a .pth filesave_path='embeddings.pth',)# embedding_dict is a dictionary mapping sequences to their embeddings as tensors for .pth or numpy arrays for sql``````model.embed_dataset()Args:sequences: List of protein sequencesbatch_size: Batch size for processingmax_len: Maximum sequence lengthfull_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 processsql: Whether to store embeddings in SQLite database - will be stored in float32sql_db_path: Path to SQLite databaseReturns:Dictionary mapping sequences to embeddings, or None if sql=TrueNote:- 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```### CitationIf you use any of this implementation or work please cite it (as well as the [ESM2](https://www.science.org/doi/10.1126/science.ade2574) paper).```@misc {FastPLMs,author = { Hallee, Logan and Bichara, David and Gleghorn, Jason P.},title = { FastPLMs: Fast, efficient, protien language model inference from Huggingface AutoModel.},year = {2024},url = { https://huggingface.co/Synthyra/ESMplusplus_small },DOI = { 10.57967/hf/3726 },publisher = { Hugging Face }}```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151---library_name: transformerstags: []---# NOTEThe GitHub with the implementation and requirements.txt can be found [here](https://github.com/Synthyra/FastPLMs.git)# FastESMFastESM is a Huggingface compatible plug in version of ESM2 rewritten with a newer PyTorch attention implementation.Load any ESM2 models into a FastEsm model to dramatically speed up training and inference without **ANY** cost in performance.## Attention backend defaults`sdpa` is the default attention backend for FastESM.To enable Flex Attention, set `attn_backend="flex"` on the config before model initialization/loading.For throughput and memory efficiency, `torch.compile(...)` is heavily recommended, especially when using Flex Attention.Outputting attention maps (or the contact prediction head) is not natively possible with the optimized attention backends (including Flex Attention). You can still pass ```output_attentions``` to have attention calculated manually and returned.Various other optimizations also make the base implementation slightly different than the one in transformers.## Use with 🤗 transformers### Supported models```pythonmodel_dict = {# Synthyra/ESM2-8M'ESM2-8M': 'facebook/esm2_t6_8M_UR50D',# Synthyra/ESM2-35M'ESM2-35M': 'facebook/esm2_t12_35M_UR50D',# Synthyra/ESM2-150M'ESM2-150M': 'facebook/esm2_t30_150M_UR50D',# Synthyra/ESM2-650M'ESM2-650M': 'facebook/esm2_t33_650M_UR50D',# Synthyra/ESM2-3B'ESM2-3B': 'facebook/esm2_t36_3B_UR50D',}```### For working with embeddings```pythonimport torchfrom transformers import AutoModel, AutoTokenizermodel_path = 'Synthyra/ESM2-8M'model = AutoModel.from_pretrained(model_path, dtype=torch.float16, trust_remote_code=True).eval()tokenizer = model.tokenizersequences = ['MPRTEIN', 'MSEQWENCE']tokenized = tokenizer(sequences, padding=True, return_tensors='pt')with torch.no_grad():embeddings = model(**tokenized).last_hidden_stateprint(embeddings.shape) # (2, 11, 1280)```### For working with sequence logits```pythonimport torchfrom transformers import AutoModelForMaskedLM, AutoTokenizermodel = AutoModelForMaskedLM.from_pretrained(model_path, dtype=torch.float16, trust_remote_code=True).eval()with torch.no_grad():logits = model(**tokenized).logitsprint(logits.shape) # (2, 11, 33)```### For working with attention maps```pythonimport torchfrom transformers import AutoModel, AutoTokenizermodel = AutoModel.from_pretrained(model_path, dtype=torch.float16, trust_remote_code=True).eval()with torch.no_grad():attentions = model(**tokenized, output_attentions).attentions # tuples of (batch_size, num_heads, seq_len, seq_len)print(attentions[-1].shape) # (2, 20, 11, 11)```### Contact predictionBecause we can output attentions using the naive attention implementation, the contact prediction is also supported```pythonwith torch.no_grad():contact_map = model.predict_contacts(**tokenized).squeeze().cpu().numpy() # (seq_len, seq_len)```## Embed entire datasets with no new codeTo embed a list of protein sequences **fast**, just call embed_dataset. Sequences are sorted to reduce padding tokens, so the initial progress bar estimation is usually much longer than the actual time it will take.Example:```pythonembedding_dict = model.embed_dataset(sequences=['MALWMRLLPLLALLALWGPDPAAA', ... # list of protein sequences],tokenizer=model.tokenizer,batch_size=2, # adjust for your GPU memorymax_len=512, # adjust for your needsfull_embeddings=False, # if True, no pooling is performedembed_dtype=torch.float32, # cast to what dtype you wantpooling_types=['mean', 'cls'], # more than one pooling type will be concatenated togethernum_workers=0, # if you have many cpu cores, we find that num_workers = 4 is fast for large datasetssql=False, # if True, embeddings will be stored in SQLite databasesql_db_path='embeddings.db',save=True, # if True, embeddings will be saved as a .pth filesave_path='embeddings.pth',)# embedding_dict is a dictionary mapping sequences to their embeddings as tensors for .pth or numpy arrays for sql``````model.embed_dataset()Args:sequences: List of protein sequencesbatch_size: Batch size for processingmax_len: Maximum sequence lengthfull_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 processsql: Whether to store embeddings in SQLite database - will be stored in float32sql_db_path: Path to SQLite databaseReturns:Dictionary mapping sequences to embeddings, or None if sql=TrueNote:- 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```### CitationIf you use any of this implementation or work please cite it (as well as the [ESM2](https://www.science.org/doi/10.1126/science.ade2574) paper).```@misc {FastPLMs,author = { Hallee, Logan and Bichara, David and Gleghorn, Jason P.},title = { FastPLMs: Fast, efficient, protien language model inference from Huggingface AutoModel.},year = {2024},url = { https://huggingface.co/Synthyra/ESMplusplus_small },DOI = { 10.57967/hf/3726 },publisher = { Hugging Face }}```
README.md+150-150