Convert
HFESM2Exporter
Bases: ModelConnector[BionemoLightningModule, EsmForMaskedLM]
Exporter Connector for converting NeMo ESM-2 Model to HF.
Source code in bionemo/esm2/model/convert.py
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 |
|
config
property
Generate HF Config based on NeMo config.
tokenizer
property
Retrieve Tokenizer from HF.
apply(output_path)
Applies the transformation.
Source code in bionemo/esm2/model/convert.py
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 |
|
convert_state(nemo_module, target)
Convert NeMo state dict to HF style.
Source code in bionemo/esm2/model/convert.py
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 |
|
init(dtype=torch.bfloat16)
Initialize the target model.
Source code in bionemo/esm2/model/convert.py
120 121 122 123 |
|
HFESM2Importer
Bases: ModelConnector[AutoModelForMaskedLM, BionemoLightningModule]
Converts a Hugging Face ESM-2 model to a NeMo ESM-2 model.
Source code in bionemo/esm2/model/convert.py
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 |
|
config
property
Returns the transformed ESM-2 config given the model tag.
tokenizer
property
We just have the one tokenizer for ESM-2.
apply(output_path)
Applies the transformation.
Largely inspired by https://docs.nvidia.com/nemo-framework/user-guide/latest/nemo-2.0/features/hf-integration.html
Source code in bionemo/esm2/model/convert.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
convert_state(source, target)
Converting HF state dict to NeMo state dict.
Source code in bionemo/esm2/model/convert.py
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 |
|
init()
Initialize the converted model.
Source code in bionemo/esm2/model/convert.py
40 41 42 |
|
convert_hf_to_nemo(hf_tag_or_path, output_path, overwrite=True)
Convert a HuggingFace ESM-2 checkpoint to a NeMo ESM-2 checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hf_tag_or_path
|
str
|
Tag or path to the HuggingFace checkpoint. |
required |
output_path
|
str
|
Path to the output NeMo checkpoint. |
required |
overwrite
|
bool
|
Whether to overwrite the output path if it already exists. |
True
|
Source code in bionemo/esm2/model/convert.py
369 370 371 372 373 374 375 376 377 378 379 |
|
convert_nemo_to_hf(nemo_path, output_path, overwrite=True)
Convert a NeMo ESM-2 checkpoint to a HuggingFace checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nemo_path
|
str
|
Path to the NeMo checkpoint. |
required |
output_path
|
str
|
Path to the output HuggingFace checkpoint. |
required |
overwrite
|
bool
|
Whether to overwrite the output path if it already exists. |
True
|
Source code in bionemo/esm2/model/convert.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|