lhallee commited on
Commit
8fcb589
·
verified ·
1 Parent(s): 0d6b8d3

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +164 -199
README.md CHANGED
@@ -1,199 +1,164 @@
1
- ---
2
- library_name: transformers
3
- tags: []
4
- ---
5
-
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
11
-
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # NOTE
7
+ The GitHub with the implementation and requirements.txt can be found [here](https://github.com/Synthyra/FastPLMs.git)
8
+
9
+ # Profluent-E1
10
+ [Profluent-E1](https://github.com/Synthyra/ESMplusplus) is a faithful implementation of Profluent's models [E1](https://www.profluent.bio/showcase/e1) ([license](https://github.com/Profluent-AI/E1/tree/main?tab=License-1-ov-file)) that integrates Huggingface AutoModel compatability and nice embedding functionality built in.
11
+
12
+
13
+ ## Use with 🤗 transformers
14
+ ### Supported models
15
+ ```python
16
+ model_dict = {
17
+ # Synthyra/Profluent-E1_150M
18
+ 'Profluent-E1-150M': 'Profluent-Bio/E1-150m',
19
+ # Synthyra/Profluent-E1_150M
20
+ 'Profluent-E1-300M': 'Profluent-Bio/E1-300m',
21
+ # Synthyra/Profluent-E1_150M
22
+ 'Profluent-E1-600M': 'Profluent-Bio/E1-600m',
23
+ }
24
+ ```
25
+
26
+ ```python
27
+ import torch
28
+ from transformers import AutoModelForMaskedLM
29
+
30
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
31
+ model = AutoModelForMaskedLM.from_pretrained('Synthyra/Profluent-E1-150M', trust_remote_code=True, dtype=torch.bfloat16).eval().to(device)
32
+
33
+ sequences = ['MPRTEIN', 'MSEQWENCE']
34
+ batch = model.prep_tokens.get_batch_kwargs(sequences, device=device)
35
+
36
+ output = model(**batch) # get all hidden states with output_hidden_states=True
37
+ print(output.logits.shape) # language modeling logits, (batch_size, seq_len, vocab_size), (2, 11, 34)
38
+ print(output.last_hidden_state.shape) # last hidden state of the model, (batch_size, seq_len, hidden_size), (2, 11, 768)
39
+ print(output.loss) # language modeling loss if you passed labels
40
+ #print(output.hidden_states) # all hidden states if you passed output_hidden_states=True (in tuple)
41
+ #print(outout.attentions) # all attention matrices if you passed output_attentions=True (in tuple)
42
+ ```
43
+
44
+ Our E1 implementation also supports sequence and token level classification tasks like ESM2. Simply pass the number of labels during initialization.
45
+
46
+ ```python
47
+ from transformers import AutoModelForSequenceClassification, AutoModelForTokenClassification
48
+
49
+ model = AutoModelForSequenceClassification.from_pretrained('Synthyra/Profluent-E1-150M', num_labels=2, trust_remote_code=True)
50
+ logits = model(**batch, labels=labels).logits
51
+ print(logits.shape) # (batch_size, num_labels), (2, 2)
52
+ ```
53
+
54
+ E1 weights were trained in bf16 and are in bf16 by default. You can load them in the precision of your choosing by leveraging the dtype parameter:
55
+ ```python
56
+ import torch
57
+ model = AutoModelForMaskedLM.from_pretrained('Synthyra/ESMplusplus_small', trust_remote_code=True, dtype=torch.float) # fp32
58
+ ```
59
+
60
+ ## Embed entire datasets with no new code
61
+ To 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.
62
+
63
+ Example:
64
+ ```python
65
+ embedding_dict = model.embed_dataset(
66
+ sequences=[
67
+ 'MALWMRLLPLLALLALWGPDPAAA', ... # list of protein sequences
68
+ ],
69
+ batch_size=2, # adjust for your GPU memory
70
+ max_len=512, # adjust for your needs
71
+ full_embeddings=False, # if True, no pooling is performed
72
+ embed_dtype=torch.float32, # cast to what dtype you want
73
+ pooling_types=['mean', 'cls'], # more than one pooling type will be concatenated together
74
+ sql=False, # if True, embeddings will be stored in SQLite database
75
+ sql_db_path='embeddings.db',
76
+ save=True, # if True, embeddings will be saved as a .pth file
77
+ save_path='embeddings.pth',
78
+ )
79
+ # embedding_dict is a dictionary mapping sequences to their embeddings as tensors for .pth or numpy arrays for sql
80
+ ```
81
+
82
+ ```
83
+ model.embed_dataset()
84
+ Args:
85
+ sequences: List of protein sequences
86
+ batch_size: Batch size for processing
87
+ max_len: Maximum sequence length
88
+ full_embeddings: Whether to return full residue-wise (True) embeddings or pooled (False)
89
+ pooling_type: Type of pooling ('mean' or 'cls')
90
+ sql: Whether to store embeddings in SQLite database - will be stored in float32
91
+ sql_db_path: Path to SQLite database
92
+
93
+ Returns:
94
+ Dictionary mapping sequences to embeddings, or None if sql=True
95
+
96
+ Note:
97
+ - If sql=True, embeddings can only be stored in float32
98
+ - sql is ideal if you need to stream a very large dataset for training in real-time
99
+ - save=True is ideal if you can store the entire embedding dictionary in RAM
100
+ - sql will be used if it is True and save is True or False
101
+ - If your sql database or .pth file is already present, they will be scanned first for already embedded sequences
102
+ - Sequences will be truncated to max_len and sorted by length in descending order for faster processing
103
+ ```
104
+
105
+ ## Fine-tuning with 🤗 peft
106
+ ```python
107
+ model = AutoModelForSequenceClassification.from_pretrained('Synthyra/Profluent-E1-150M', num_labels=2, trust_remote_code=True)
108
+ # these modules handle E1 attention layers
109
+ target_modules = ["q_proj", "k_proj", "v_proj", "o_proj"]
110
+
111
+ lora_config = LoraConfig(
112
+ r=8, # choose lora parameters to your liking
113
+ lora_alpha=16,
114
+ lora_dropout=0.01,
115
+ bias="none",
116
+ target_modules=target_modules,
117
+ )
118
+
119
+ # Apply LoRA to the model
120
+ model = get_peft_model(model, lora_config)
121
+
122
+ # Unfreeze the classifier head
123
+ for param in model.classifier.parameters():
124
+ param.requires_grad = True
125
+ ```
126
+
127
+ For a more thourough example of fine-tuning, check out our example script [here](https://github.com/Synthyra/FastPLMs/blob/main/fine_tuning_example.py).
128
+
129
+
130
+ ## Returning attention maps
131
+ Usually F.scaled_dot_product_attention is used for the attention calculations, which is much faster than native PyTorch. However, it cannot return attention maps.
132
+ ESM++ has the option to ```output_attentions```, which will calculate attention manually. This is much slower, so do not use unless you need the attention maps.
133
+
134
+ ```python
135
+ output = model(**tokenized, output_attentions=True)
136
+ att = output.attentions
137
+ len(att) # 30, one for each layer, size (batch_size, num_heads, seq_len, seq_len) each
138
+ ```
139
+
140
+
141
+ ### Citation
142
+ If you use any of this implementation or work please cite the following DOI and Profluent's paper.
143
+
144
+ ```
145
+ @misc {FastPLMs,
146
+ author = { Hallee, Logan and Bichara, David and Gleghorn, Jason P.},
147
+ title = { FastPLMs: Fast, efficient, protien language model inference from Huggingface AutoModel.},
148
+ year = {2024},
149
+ url = { https://huggingface.co/Synthyra/ESMplusplus_small },
150
+ DOI = { 10.57967/hf/3726 },
151
+ publisher = { Hugging Face }
152
+ }
153
+ ```
154
+
155
+ ```
156
+ @article{Jain_Beazer_Ruffolo_Bhatnagar_Madani_2025, title={E1: Retrieval-Augmented Protein Encoder Models},
157
+ url={https://www.biorxiv.org/content/early/2025/11/13/2025.11.12.688125},
158
+ DOI={10.1101/2025.11.12.688125},
159
+ journal={bioRxiv},
160
+ publisher={Cold Spring Harbor Laboratory},
161
+ author={Jain, Sarthak and Beazer, Joel and Ruffolo, Jeffrey A and Bhatnagar, Aadyot and Madani, Ali},
162
+ year={2025}
163
+ }
164
+ ```