Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -69,6 +69,31 @@ _ = model.embed_dataset(
|
|
69 |
)
|
70 |
```
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
## Returning attention maps
|
73 |
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.
|
74 |
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.
|
|
|
69 |
)
|
70 |
```
|
71 |
|
72 |
+
## Fine-tuning with 🤗 peft
|
73 |
+
```python
|
74 |
+
model = AutoModelForSequenceClassification.from_pretrained('Synthyra/ESMplusplus_large', num_labels=2, trust_remote_code=True)
|
75 |
+
# these modules handle ESM++ and ESM2 attention layers
|
76 |
+
target_modules = ["layernorm_qkv.1", "out_proj", "query", "key", "value", "dense"]
|
77 |
+
|
78 |
+
lora_config = LoraConfig(
|
79 |
+
r=8, # choose lora parameters to your liking
|
80 |
+
lora_alpha=16,
|
81 |
+
lora_dropout=0.01,
|
82 |
+
bias="none",
|
83 |
+
target_modules=target_modules,
|
84 |
+
)
|
85 |
+
|
86 |
+
# Apply LoRA to the model
|
87 |
+
model = get_peft_model(model, lora_config)
|
88 |
+
|
89 |
+
# Unfreeze the classifier head
|
90 |
+
for param in model.classifier.parameters():
|
91 |
+
param.requires_grad = True
|
92 |
+
```
|
93 |
+
|
94 |
+
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).
|
95 |
+
|
96 |
+
|
97 |
## Returning attention maps
|
98 |
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.
|
99 |
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.
|