Skip to content

Instantly share code, notes, and snippets.

@kasima
Created January 5, 2023 15:14
Show Gist options
  • Save kasima/4093ae24bd06839918df2620995403cb to your computer and use it in GitHub Desktop.
Save kasima/4093ae24bd06839918df2620995403cb to your computer and use it in GitHub Desktop.
Convert safetensors to ckpt – not working
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