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 1616mm_tensors = [k for k , v in checkpoint .items () if k .startswith ("model.mm_projector" )]
1717
1818# 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 }
2020torch .save (projector , f"{ args .model } /llava.projector" )
2121
2222# remove these tensors from the checkpoint and save it again
2323for name in mm_tensors :
2424 del checkpoint [name ]
2525
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+
2642torch .save (checkpoint , path )
2743
2844print ("Done!" )
You can’t perform that action at this time.
0 commit comments