Finetune token classifier
ClassifierLossReduction
Bases: BERTMLMLossWithReduction
A class for calculating the cross entropy loss of classification output.
This class used for calculating the loss, and for logging the reduced loss across micro batches.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
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 |
|
forward(batch, forward_out)
Calculates the loss within a micro-batch. A micro-batch is a batch of data on a single GPU.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Dict[str, Tensor]
|
A batch of data that gets passed to the original forward inside LitAutoEncoder. |
required |
forward_out
|
Dict[str, Tensor]
|
the output of the forward method inside classification head. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tuple where the loss tensor will be used for backpropagation and the dict will be passed to |
PerTokenLossDict | SameSizeLossDict
|
the reduce method, which currently only works for logging. |
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
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 |
|
reduce(losses_reduced_per_micro_batch)
Works across micro-batches. (data on single gpu).
Note: This currently only works for logging and this loss will not be used for backpropagation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
losses_reduced_per_micro_batch
|
Sequence[SameSizeLossDict]
|
a list of the outputs of forward |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tensor that is the mean of the losses. (used for logging). |
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
ESM2FineTuneTokenConfig
dataclass
Bases: ESM2GenericConfig[ESM2FineTuneTokenModel, ClassifierLossReduction]
, IOMixinWithGettersSetters
ExampleConfig is a dataclass that is used to configure the model.
Timers from ModelParallelConfig are required for megatron forward compatibility.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
get_loss_reduction_class()
The loss function type.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
181 182 183 |
|
ESM2FineTuneTokenModel
Bases: ESM2Model
An ESM2 model that is suitable for fine tuning.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
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 |
|
__init__(config, *args, include_hiddens=False, post_process=True, **kwargs)
Constructor.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
forward(*args, **kwargs)
Inference.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
MegatronConvNetHead
Bases: MegatronModule
A convolutional neural network class for residue-level classification.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
__init__(config)
Constructor.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
97 98 99 100 101 102 103 104 105 106 107 108 |
|
forward(hidden_states)
Inference.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
110 111 112 113 114 115 116 |
|