Peft
Evo2LoRA
Bases: LoRA
LoRA adapter specifically for Evo2/Hyena models.
Source code in bionemo/evo2/run/peft.py
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 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 |
|
__call__(model)
Apply LoRA transformations to the model.
Override to avoid fn.walk compatibility issues.
Source code in bionemo/evo2/run/peft.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
__deepcopy__(memo)
Custom deepcopy to handle unpickleable objects.
Source code in bionemo/evo2/run/peft.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
__getstate__()
Prepare object for pickling.
Source code in bionemo/evo2/run/peft.py
267 268 269 270 271 272 273 |
|
__init__(peft_ckpt_path=None, freeze_modules=['encoder', 'embedding'], target_modules=['linear_qkv', 'linear_proj', 'linear_fc1', 'linear_fc2', 'short_filter', 'hyena_filter', 'positional_encoding'], *args, **kwargs)
Initialize the LoRA Adapter for Evo2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
peft_ckpt_path
|
Optional[str]
|
Path to pre-trained LoRA checkpoint. |
None
|
freeze_modules
|
List[str]
|
List of module names to freeze (Evo2-specific defaults). |
['encoder', 'embedding']
|
target_modules
|
List[str]
|
Modules to apply LoRA to (uses Evo2 defaults if None). |
['linear_qkv', 'linear_proj', 'linear_fc1', 'linear_fc2', 'short_filter', 'hyena_filter', 'positional_encoding']
|
*args
|
placeholder. |
()
|
|
**kwargs
|
dim: LoRA rank dimension. alpha: LoRA scaling parameter. dropout: Dropout rate for LoRA layers. dropout_position: Where to apply dropout ('pre' or 'post'). lora_A_init_method: Initialization for A matrix ('xavier', 'uniform', 'normal'). lora_B_init_method: Initialization for B matrix ('zero', 'normal'). |
{}
|
Source code in bionemo/evo2/run/peft.py
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 |
|
__setstate__(state)
Restore object from pickle.
Source code in bionemo/evo2/run/peft.py
275 276 277 |
|
adapter_key_filter(key)
Filter state dict keys to identify adapter parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
State dict key to check |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if key corresponds to an adapter parameter |
Source code in bionemo/evo2/run/peft.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
on_predict_epoch_start(trainer, pl_module)
Event hook.
Apply transformations for prediction if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trainer
|
Trainer
|
The trainer object. |
required |
pl_module
|
LightningModule
|
The LightningModule object. |
required |
Source code in bionemo/evo2/run/peft.py
97 98 99 100 101 102 103 104 105 106 |
|
selective_freeze(m, name=None, prefix=None)
Selectively freeze modules based on freeze_modules list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
Module
|
Module to potentially freeze. |
required |
name
|
Name of the module. |
None
|
|
prefix
|
Prefix for the module name. |
None
|
Returns:
Type | Description |
---|---|
nn.Module: The module (frozen or not). |
Source code in bionemo/evo2/run/peft.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
setup(trainer, pl_module, stage)
Setup callback - properly initialize transform.
Source code in bionemo/evo2/run/peft.py
83 84 85 86 87 88 89 90 91 92 93 94 95 |
|