Weight utils
load_weights_sharded_inplace_nemo2_to_mcore(model, distributed_checkpoint_dir, skip_keys_with_these_prefixes)
Given a megatron module, this function will determine which keys/subsets of weights to load given the
parallel/distributed state. This operates assuming a checkpoint was saved by a nemo2 trainer which places
the module.
prefix on all key names, but we are then going to load directly in to the megatron module
without the module.
prefix. Note that if there are any extra keys that you do not want to search the
checkpoint for, for example if you add new layers/heads onto your module, you need to supply the prefix
path to those keys in your model and they will be ignored. This latter feature is key for flexible fine-tuning
strategies where you load weights partially from other models with partially overlapping structures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
MegatronModelType
|
Megatron model that you want to load weights into. |
required |
distributed_checkpoint_dir
|
str | Path
|
description |
required |
skip_keys_with_these_prefixes
|
Set[str]
|
description |
required |
Source code in bionemo/llm/utils/weight_utils.py
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 |
|
nemo1_to_nemo2_biobert_key_mapping(old_key, new_model_prefix='module', old_model_prefix='model', te_mapping=False)
This function is used to map the keys from the old nemo BERT models to the new BioBERT models
Parameters:
Name | Type | Description | Default |
---|---|---|---|
old_key
|
str
|
old key we want to map to the expected new key name. |
required |
new_model_prefix
|
str
|
The new key for the base weights. If you point this at the core megatron model set it to "". For the regular nemo2 lightning module following standards, set it to "module". Defaults to "module". |
'module'
|
old_model_prefix
|
str
|
The previous saved weight prefix. Defaults to "model" which was the standard in nemo1. |
'model'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
New key name |
Source code in bionemo/llm/utils/weight_utils.py
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 |
|