()
| 2 | from flora import FLoRA |
| 3 | |
| 4 | def main(): |
| 5 | pretrained_ckpt = '/path/to/your/pretrained_ckpt/path' |
| 6 | flora_params = dict( |
| 7 | target_keys=['features'], #determine to append flora on the layer which contains target_key |
| 8 | base_name='', #determine the root name of the input model. |
| 9 | #It's useful in the situation that you only want to |
| 10 | #wrap a sub-model into the FLoRA, for example, the image encoder in LLaVA. |
| 11 | #So, base_name='vision_tower' |
| 12 | cls_types=['conv2d'], #determine types to be converted to flora |
| 13 | flora_cfg=dict( |
| 14 | r=[16, 16, 2, 2], |
| 15 | N=4, |
| 16 | scale=4.0, |
| 17 | drop_rate=0.01, |
| 18 | ), |
| 19 | ) |
| 20 | base_model = torchvision.models.convnext_base() |
| 21 | #Note that you should implement a function to load the pretrained parameters for base_model before calling FLoRA() |
| 22 | def load_pretrained_ckpt(base_model, pretrained_ckpt): |
| 23 | #TODO: load your checkpoint |
| 24 | return base_model |
| 25 | base_model = load_pretrained_ckpt(base_model, pretrained_ckpt) |
| 26 | |
| 27 | flora_model = FLoRA( |
| 28 | model=base_model, |
| 29 | **flora_params |
| 30 | )#.cuda() #or any other methods to move the model from cpu to gpu to enable multi-gpu parallel training. |
| 31 | |
| 32 | print(flora_model.model) |
| 33 | |
| 34 | if __name__ == '__main__': |
| 35 | main() |
no test coverage detected