forked from FlagAI-Open/FlagAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: zhaohu xing <[email protected]>
- Loading branch information
Showing
2 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
import os | ||
import torch | ||
|
||
def merge_weight(model_dir): | ||
model_files = os.listdir(model_dir) | ||
checkpoint_merge = {} | ||
print(f"merging the model weight....") | ||
# multi weights files | ||
for file_to_load in model_files: | ||
if "pytorch_model-0" in file_to_load: | ||
checkpoint_to_load = torch.load(os.path.join(model_dir, file_to_load),map_location="cpu") | ||
for k, v in checkpoint_to_load.items(): | ||
checkpoint_merge[k] = v | ||
print(f"{file_to_load} is merged successfully.") | ||
# save all parameters | ||
torch.save( | ||
checkpoint_merge, | ||
os.path.join(model_dir, "pytorch_model.bin")) | ||
print(f"models are merged successfully.") | ||
|
||
|
||
if __name__ == "__main__": | ||
# merge_weight(model_dir="/share/projset/baaishare/baai-mrnd/xingzhaohu/galactica-6.7b-en/") | ||
merge_weight(model_dir="./state_dict/opt-6.7b-en") |