BuccoBruce

grug's pre-prune script for ckpt files that don't want to prune.py...py

Jan 3rd, 2023
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | Source Code | 0 0
  1. import os
  2. from pathlib import Path
  3. import torch
  4. import argparse
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument('--input', '-I', type=str, help='Input file to prune', required = True)
  7. args = parser.parse_args()
  8. model_path = args.input
  9.  
  10. sd = torch.load(model_path, map_location="cpu")
  11. if "state_dict" not in sd:
  12.     pruned_sd = {
  13.         "state_dict": dict(),
  14.     }
  15. else:
  16.     pruned_sd = dict()
  17. for k in sd.keys():
  18.     if k != "optimizer_states":
  19.         if "state_dict" not in sd:
  20.             pruned_sd["state_dict"][k] = sd[k]
  21.         else:
  22.             pruned_sd[k] = sd[k]
  23. torch.save(pruned_sd, "model-pre-pruned.ckpt")
Advertisement
Add Comment
Please, Sign In to add comment