-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_lora_to_weights.py
41 lines (39 loc) · 1.74 KB
/
convert_lora_to_weights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from peft import PeftModel
import argparse
import itertools
import json
import os
import random
import time
from functools import partial
import torch
from chemexam_repo.ChemLLM_Multimodal_Exam.internvl.model.internvl_chat import (InternVisionConfig,
InternVisionModel,
InternVLChatConfig,
InternVLChatModel)
from chemexam_repo.ChemLLM_Multimodal_Exam.internvl.train.dataset import build_transform, dynamic_preprocess
# from internvl.model.internvl_chat import (InternVisionConfig,
# InternVisionModel,
# InternVLChatConfig,
# InternVLChatModel)
# from internvl.train.dataset import build_transform, dynamic_preprocess
from PIL import Image
from torch.utils.data import Dataset
from tqdm import tqdm
from transformers.deepspeed import HfDeepSpeedConfig
from transformers import (AutoConfig, AutoModelForCausalLM, AutoTokenizer,
HfArgumentParser, LlamaConfig, LlamaForCausalLM,
LlamaTokenizer, Trainer, TrainingArguments,
default_data_collator, set_seed)
from accelerate import infer_auto_device_map
import accelerate
import pdb
if __name__ == "__main__":
model = InternVLChatModel.from_pretrained('YOUR MODEL PATH')
print("Loading lora")
#model = PeftModel.from_pretrained(model, 'PROJECTOR')
# pdb.set_trace()
# model.language_model = model.language_model.merge_and_unload()
model.vision_model = model.vision_model.merge_and_unload()
model.save_pretrained('YOUR MERGED MODEL PATH')
# print("Lora model is loaded")