Fine-Tuning Model
Bases: HelicalBaseFineTuningModel
, HyenaDNA
HyenaDNA fine-tuning model.
This class represents the HyenaDNA fine-tuning model, which is a long-range genomic foundation model pretrained on context lengths of up to 1 million tokens at single nucleotide resolution.
Example
from helical.models.hyena_dna import HyenaDNAFineTuningModel, HyenaDNAConfig
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
input_sequences = ["ACT"*20, "ATG"*20, "ATG"*20, "ACT"*20, "ATT"*20]
labels = [0, 2, 2, 0, 1]
hyena_dna_config = HyenaDNAConfig(batch_size=1, device=device)
hyena_dna_fine_tune = HyenaDNAFineTuningModel(hyena_config=hyena_dna_config, fine_tuning_head="classification", output_size=3)
train_dataset = hyena_dna_fine_tune.process_data(input_sequences)
hyena_dna_fine_tune.train(train_dataset=train_dataset, train_labels=labels)
outputs = hyena_dna_fine_tune.get_outputs(train_dataset)
print(outputs.shape)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hyena_config
|
HyenaDNAConfig
|
The HyenaDNA configs for fine-tuning model, the same configs that would be used to instantiate the standard HyenaDNA model. |
required |
fine_tuning_head
|
Literal['classification', 'regression'] | HelicalBaseFineTuningHead
|
The fine-tuning head that is appended to the model. This can either be a string (options available: "classification", "regression") specifying the task or a custom fine-tuning head inheriting from HelicalBaseFineTuningHead. |
required |
output_size
|
Optional[int]
|
The output size of the fine-tuning head. This is required if a predefined head is selected. |
None
|
Methods:
Name | Description |
---|---|
train |
Fine-tunes the Hyena-DNA model with different head modules. |
get_outputs |
Get the outputs of the fine-tuned model. |
Source code in helical/models/hyena_dna/fine_tuning_model.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
train(train_dataset, train_labels, validation_dataset=None, validation_labels=None, optimizer=optim.AdamW, optimizer_params={'lr': 0.0001}, loss_function=loss.CrossEntropyLoss(), epochs=1, lr_scheduler_params=None, shuffle=True)
Fine-tunes the Hyena-DNA model with different head modules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_dataset
|
HyenaDNADataset
|
A helical Hyena-DNA processed dataset for fine-tuning |
required |
train_labels
|
list[int]
|
The labels for the training data. These should be stored as unique per class integers. |
required |
validation_dataset
|
HyenaDNADataset
|
A helical Hyena-DNA processed dataset for per epoch validation. If this is not specified, no validation will be performed. |
None
|
validation_labels
|
list[int]
|
The labels for the validation data. These should be stored as unique per class integers. |
None
|
optimizer
|
optim
|
The optimizer to be used for training. |
torch.optim.AdamW
|
optimizer_params
|
dict
|
The optimizer parameters to be used for the optimizer specified. This list should NOT include model parameters. e.g. optimizer_params = {'lr': 0.0001} |
{'lr': 0.0001}
|
loss_function
|
loss
|
The loss function to be used. |
torch.nn.CrossEntropyLoss()
|
epochs
|
int
|
The number of epochs to train the model for. |
10
|
lr_scheduler_params
|
dict
|
The learning rate scheduler parameters for the transformers get_scheduler method. The optimizer will be taken from the optimizer input and should not be included in the learning scheduler parameters. If not specified, a constant learning rate will be used. e.g. lr_scheduler_params = { 'name': 'linear', 'num_warmup_steps': 0 }. num_steps will be calculated based on the number of epochs and the length of the training dataset. |
None
|
shuffle
|
bool
|
Whether to shuffle the training data or not. |
True
|
Source code in helical/models/hyena_dna/fine_tuning_model.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
get_outputs(dataset)
Get the outputs of the fine-tuned model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset
|
HyenaDNADataset
|
The input data to get the outputs for. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The outputs of the model |