EADST

Merge Safetensors to Bin File

Merge Safetensors to Bin File

from safetensors.torch import load_file
import torch
import os

safetensors_dir = "./your_model_folder_path/"

# get the number of safetensors
number = 0
for root, _, files in os.walk(safetensors_dir):
    for file in files:
        if "-of-" in file:
            number = file.split("-of-")[-1].strip(".safetensors")
            break

# merge safetensors to bin
model_data = {}
for i in range(1, int(number)+1):
    file_path = os.path.join(safetensors_dir, f"model-0000{i}-of-{number}.safetensors")
    data = load_file(file_path)
    model_data.update(data)

# save bin
torch.save(model_data, "./your_model_folder_path/pytorch_model.bin") 
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
站点统计

本站现有博文266篇,共被浏览440563

本站已经建立2019天!

热门文章
文章归档
回到顶部