Finetune token regressor
FineTuneSeqLenBioBertConfig
dataclass
Bases: BioBertConfig[MegatronBioBertFineTuneSeqLengthModel, SequenceLengthRMSEPlusBERTMLMLossWithReduction]
, IOMixinWithGettersSetters
BioBert fine-tuning sequence length model configuration.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
get_loss_reduction_class()
Loss function type.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
220 221 222 |
|
LoRAForGeneFormerTokenRegressor
Bases: LoRA
LoRA for Genformer Token Regression.
There are a few tricky things here to get everything to work right:
- Freezing logic for the transformer has to be updated in order to not freeze the new head layers.
- The LoRA adapter logic has to be updated to pull the input/output sizes of the layers to be adapted from the modules that are passed (the previous method was compatible with nn and TE, but not megatrons tensor_parallel modules that are currently used by geneformer). This method contains a suggested refactor to make these methods a little more general and extensible with structural pattern matching as well. We should push this requirement onto NeMo, since we shouldn't duplicate the adapter method.
- There's a ton of assumptions in NeMo about which module is being called and that it inherits specific mixins. This could break the if it is updated from a megatron module to a torch module or something else. Functional calls are generally favored for this reason and some have been made here to avoid updating inheritance throughout the code base.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
__call__(model)
Inference.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
262 263 264 265 266 |
|
input_size_getter(m)
Gets the input size of the supplied model.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
242 243 244 245 246 247 248 249 250 |
|
output_size_getter(m)
Gets the output size of the supplied model.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
252 253 254 255 256 257 258 259 260 |
|
selective_freeze(m, name=None, prefix=None)
Freezes either 'encoder' or 'embedding' parameters of the input model (m
) iff name is one of these.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
268 269 270 271 272 |
|
transform(m, name=None, prefix=None)
Transforms the input model if the name is in the target modules.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
MegatronBioBertFineTuneSeqLengthModel
Bases: MegatronBioBertModel
Megatron model for biobert finetuning with sequence length.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
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 |
|
__init__(config, *args, include_hiddens=False, post_process=True, **kwargs)
Constructor.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
173 174 175 176 177 178 179 180 181 182 183 |
|
forward(*args, **kwargs)
Inference.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
MegatronFineTuneOutput
Bases: BioBertOutput
Inference output type for MegatronBioBertFineTuneSeqLengthModel.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
64 65 66 67 |
|
MegatronRegressionMLPHead
Bases: MegatronModule
A megatron MLP head.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
__init__(config)
Constructor.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
156 157 158 159 160 161 162 163 |
|
forward(hidden_states)
Inference.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
165 166 167 |
|
SequenceLengthRMSEPlusBERTMLMLossWithReduction
Bases: BERTMLMLossWithReduction
Loss function.
Source code in bionemo/geneformer/model/finetune_token_regressor.py
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 |
|
forward(batch, forward_out)
Computes loss of labels
in the batch vs token_logits
in the forward output currently.
In the future this will be extended to handle other loss types like sequence loss if it is present in the forward_out and batch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
SeqLenRmsepBatch
|
The batch of data. Each tensor should be of shape [batch_size, , ], and match the corresponding dimension for that particular key in the batch output. For example, the "labels" and "token_logits" key should have a tensor of shape [batch_size, sequence_length]. |
required |
forward_out
|
Dict[str, Tensor]
|
The forward output from the model. Each tensor should be of shape [batch_size, , ] |
required |
Taken from: https://github.com/NVIDIA/NeMo/blob/main/nemo/collections/nlp/models/language_modeling/megatron_gpt_model.py#L951-L976
Source code in bionemo/geneformer/model/finetune_token_regressor.py
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 |
|