File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 16
16
mm_tensors = [k for k , v in checkpoint .items () if k .startswith ("model.mm_projector" )]
17
17
18
18
# store these tensors in a new dictionary and torch.save them
19
- projector = {name : checkpoint [name ] for name in mm_tensors }
19
+ projector = {name : checkpoint [name ]. float () for name in mm_tensors }
20
20
torch .save (projector , f"{ args .model } /llava.projector" )
21
21
22
22
# remove these tensors from the checkpoint and save it again
23
23
for name in mm_tensors :
24
24
del checkpoint [name ]
25
25
26
+ # BakLLaVA models contain CLIP tensors in it
27
+ clip_tensors = [k for k , v in checkpoint .items () if k .startswith ("model.vision_tower" )]
28
+ if len (clip_tensors ) > 0 :
29
+ clip = {name .replace ("vision_tower.vision_tower." , "" ): checkpoint [name ].float () for name in clip_tensors }
30
+ torch .save (clip , f"{ args .model } /llava.clip" )
31
+
32
+ # remove these tensors
33
+ for name in clip_tensors :
34
+ del checkpoint [name ]
35
+
36
+ # added tokens should be removed to be able to convert Mistral models
37
+ if os .path .exists (f"{ args .model } /added_tokens.json" ):
38
+ with open (f"{ args .model } /added_tokens.json" , "w" ) as f :
39
+ f .write ("{}\n " )
40
+
41
+
26
42
torch .save (checkpoint , path )
27
43
28
44
print ("Done!" )
You can’t perform that action at this time.
0 commit comments