Created
January 5, 2023 15:14
-
-
Save kasima/4093ae24bd06839918df2620995403cb to your computer and use it in GitHub Desktop.
Convert safetensors to ckpt – not working
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
import argparse | |
import torch | |
from safetensors.torch import load_file | |
def save_checkpoint(weights, filename): | |
with open(filename, "wb") as f: | |
torch.save(weights, f) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--safetensors_path", type=str, required=True, help="Path to safetensors file") | |
parser.add_argument( | |
"--output_path", | |
default="converted.ckpt", | |
type=str, | |
required=False, | |
help="Path to output file" | |
) | |
args = parser.parse_args() | |
print("Loading weights from", args.safetensors_path) | |
weights = load_file(args.safetensors_path) | |
print("Saving weights to", args.output_path) | |
save_checkpoint(weights, args.output_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment