mm / scripts /pytorch_to_safe_tensors.py
nruto's picture
Upload 31 files
d0bfdd6 verified
raw
history blame contribute delete
517 Bytes
#! /usr/bin/env python3
from pathlib import Path
import click
import torch
from safetensors.torch import save_file
@click.command()
@click.argument("input_path", type=click.Path(exists=True))
def convert_to_safetensors(input_path):
model = torch.load(input_path)
input_path = Path(input_path)
output_path = input_path.with_suffix(".safetensors")
save_file(model, str(output_path))
click.echo(f"Converted {input_path} to {output_path}")
if __name__ == "__main__":
convert_to_safetensors()