Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,22 @@ import gradio as gr
|
|
19 |
from entailment_inference import get_scores
|
20 |
from nle_inference import VideoCaptionDataset, get_nle
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
pretrained_ckpt = "mplugowl7bvideo/"
|
23 |
trained_ckpt = "owl-con/checkpoint-5178/pytorch_model.bin"
|
24 |
|
@@ -42,8 +58,11 @@ peft_config = LoraConfig(
|
|
42 |
)
|
43 |
model = get_peft_model(model, peft_config)
|
44 |
model.print_trainable_parameters()
|
|
|
45 |
with open(trained_ckpt, 'rb') as f:
|
46 |
ckpt = torch.load(f, map_location = torch.device("cpu"))
|
|
|
|
|
47 |
model.load_state_dict(ckpt)
|
48 |
model = model.to("cuda:0").to(torch.bfloat16)
|
49 |
|
|
|
19 |
from entailment_inference import get_scores
|
20 |
from nle_inference import VideoCaptionDataset, get_nle
|
21 |
|
22 |
+
import re
|
23 |
+
|
24 |
+
def modify_keys(state_dict):
|
25 |
+
new_state_dict = defaultdict()
|
26 |
+
|
27 |
+
pattern = re.compile(r'.*language_model.*\.(q_proj|v_proj|k_proj|o_proj|gate_proj|down_proj|up_proj).weight')
|
28 |
+
|
29 |
+
for key, value in state_dict.items():
|
30 |
+
if pattern.match(key):
|
31 |
+
key = key.split('.')
|
32 |
+
key.insert(-1, 'base_layer')
|
33 |
+
key = '.'.join(key)
|
34 |
+
new_state_dict[key] = value
|
35 |
+
|
36 |
+
return new_state_dict
|
37 |
+
|
38 |
pretrained_ckpt = "mplugowl7bvideo/"
|
39 |
trained_ckpt = "owl-con/checkpoint-5178/pytorch_model.bin"
|
40 |
|
|
|
58 |
)
|
59 |
model = get_peft_model(model, peft_config)
|
60 |
model.print_trainable_parameters()
|
61 |
+
|
62 |
with open(trained_ckpt, 'rb') as f:
|
63 |
ckpt = torch.load(f, map_location = torch.device("cpu"))
|
64 |
+
ckpt = modify_keys(ckpt)
|
65 |
+
|
66 |
model.load_state_dict(ckpt)
|
67 |
model = model.to("cuda:0").to(torch.bfloat16)
|
68 |
|