Instructions to use Synthyra/FastESM2_650 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Synthyra/FastESM2_650 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="Synthyra/FastESM2_650", trust_remote_code=True)# Load model directly from transformers import AutoModelForMaskedLM model = AutoModelForMaskedLM.from_pretrained("Synthyra/FastESM2_650", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload modeling_fastesm.py with huggingface_hub
Browse files- modeling_fastesm.py +5 -1
modeling_fastesm.py
CHANGED
|
@@ -1747,13 +1747,14 @@ class FastEsmModel(FastEsmPreTrainedModel, EmbeddingMixin):
|
|
| 1747 |
)
|
| 1748 |
|
| 1749 |
|
| 1750 |
-
class FastEsmForMaskedLM(FastEsmPreTrainedModel, EmbeddingMixin):
|
| 1751 |
def __init__(self, config, **kwargs):
|
| 1752 |
FastEsmPreTrainedModel.__init__(self, config, **kwargs)
|
| 1753 |
self.esm = FAST_ESM_ENCODER(config, add_pooling_layer=False)
|
| 1754 |
self.lm_head = EsmLMHead(config)
|
| 1755 |
self.loss_fct = nn.CrossEntropyLoss()
|
| 1756 |
self.post_init()
|
|
|
|
| 1757 |
|
| 1758 |
def get_input_embeddings(self):
|
| 1759 |
return self.esm.embeddings.word_embeddings
|
|
@@ -1781,6 +1782,9 @@ class FastEsmForMaskedLM(FastEsmPreTrainedModel, EmbeddingMixin):
|
|
| 1781 |
def predict_contacts(self, input_ids: torch.Tensor, attention_mask: torch.Tensor) -> torch.Tensor:
|
| 1782 |
return self.esm.predict_contacts(input_ids, attention_mask=attention_mask)
|
| 1783 |
|
|
|
|
|
|
|
|
|
|
| 1784 |
def forward(
|
| 1785 |
self,
|
| 1786 |
input_ids: Optional[torch.Tensor] = None,
|
|
|
|
| 1747 |
)
|
| 1748 |
|
| 1749 |
|
| 1750 |
+
class FastEsmForMaskedLM(FastPLMTestTimeTrainingMixin, FastEsmPreTrainedModel, EmbeddingMixin):
|
| 1751 |
def __init__(self, config, **kwargs):
|
| 1752 |
FastEsmPreTrainedModel.__init__(self, config, **kwargs)
|
| 1753 |
self.esm = FAST_ESM_ENCODER(config, add_pooling_layer=False)
|
| 1754 |
self.lm_head = EsmLMHead(config)
|
| 1755 |
self.loss_fct = nn.CrossEntropyLoss()
|
| 1756 |
self.post_init()
|
| 1757 |
+
self.init_ttt({"lora_target_replace_module": "EsmAttention"})
|
| 1758 |
|
| 1759 |
def get_input_embeddings(self):
|
| 1760 |
return self.esm.embeddings.word_embeddings
|
|
|
|
| 1782 |
def predict_contacts(self, input_ids: torch.Tensor, attention_mask: torch.Tensor) -> torch.Tensor:
|
| 1783 |
return self.esm.predict_contacts(input_ids, attention_mask=attention_mask)
|
| 1784 |
|
| 1785 |
+
def _ttt_get_trainable_modules(self) -> list[nn.Module]:
|
| 1786 |
+
return [self.esm]
|
| 1787 |
+
|
| 1788 |
def forward(
|
| 1789 |
self,
|
| 1790 |
input_ids: Optional[torch.Tensor] = None,
|