Otter Pupp
commited on
Commit
•
0d84d06
1
Parent(s):
9b6ab2d
convert to safetensors
Browse files
loras/convert_to_safe.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Got a bunch of .ckpt files to convert?
|
2 |
+
# Here's a handy script to take care of all that for you!
|
3 |
+
# Original .ckpt files are not touched!
|
4 |
+
# Make sure you have enough disk space! You are going to DOUBLE the size of your models folder!
|
5 |
+
#
|
6 |
+
# First, run:
|
7 |
+
# pip install torch torchsde==0.2.5 safetensors==0.2.5
|
8 |
+
#
|
9 |
+
# Place this file in the **SAME DIRECTORY** as all of your .ckpt files, open a command prompt for that folder, and run:
|
10 |
+
# python convert_to_safe.py
|
11 |
+
|
12 |
+
# Original script https://gist.github.com/xrpgame/8f756f99b00b02697edcd5eec5202c59
|
13 |
+
# Edited by @Tumppi066 for use with folders https://github.com/Tumppi066/
|
14 |
+
|
15 |
+
import os
|
16 |
+
import torch
|
17 |
+
from safetensors.torch import save_file
|
18 |
+
|
19 |
+
files = os.listdir()
|
20 |
+
|
21 |
+
# Loop through all files in the folder to find the .ckpt files
|
22 |
+
models = []
|
23 |
+
safeTensors = []
|
24 |
+
for path, subdirs, files in os.walk(os.path.abspath(os.getcwd())):
|
25 |
+
for name in files:
|
26 |
+
if name.lower().endswith('.ckpt'):
|
27 |
+
models.append(os.path.join(path, name))
|
28 |
+
if name.lower().endswith('.safetensors'):
|
29 |
+
safeTensors.append(os.path.join(path, name))
|
30 |
+
|
31 |
+
if len(models) == 0:
|
32 |
+
print('\033[91m> No .ckpt files found in this directory ({}).\033[0m'.format(os.path.abspath(os.getcwd())))
|
33 |
+
input('> Press enter to exit... ')
|
34 |
+
exit()
|
35 |
+
print(f"\n\033[92m> Found {len(models)} .ckpt files to convert.\033[0m")
|
36 |
+
for model in models:
|
37 |
+
print(str(models.index(model)+1) +": "+ model.split("\\")[-1])
|
38 |
+
|
39 |
+
input("> Press enter to continue... ")
|
40 |
+
print("\n")
|
41 |
+
|
42 |
+
for index in range(len(models)):
|
43 |
+
f = models[index]
|
44 |
+
modelName = f.split("\\")[-1] # This is for easy printing (without printing the full path)
|
45 |
+
tensorName = f"{modelName.replace('.ckpt', '')}.safetensors"
|
46 |
+
fn = f"{f.replace('.ckpt', '')}.safetensors"
|
47 |
+
|
48 |
+
if fn in safeTensors:
|
49 |
+
# Print the model name and skip it if it already exists in yellow
|
50 |
+
print(f"\033[33m\n> Skipping {modelName}, as {tensorName} already exists.\033[0m")
|
51 |
+
continue
|
52 |
+
|
53 |
+
print(f'\n> Loading {modelName} ({index+1}/{len(models)})...')
|
54 |
+
|
55 |
+
try:
|
56 |
+
with torch.no_grad():
|
57 |
+
map_location = torch.device('cpu')
|
58 |
+
weights = torch.load(f, map_location=map_location)
|
59 |
+
# keysList = list(weights.keys())
|
60 |
+
# print(keysList)
|
61 |
+
# weights = weights["state_dict"]
|
62 |
+
fn = f"{f.replace('.ckpt', '')}.safetensors"
|
63 |
+
print(f'Saving {tensorName}...')
|
64 |
+
save_file(weights, fn)
|
65 |
+
except Exception as ex:
|
66 |
+
print(f'ERROR converting {modelName}: {ex}')
|
67 |
+
|
68 |
+
print("\n\033[92mDone!\033[0m")
|
69 |
+
input("> Press enter to exit... ")
|
loras/spin-diffusion-v3-128.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:192784f0f94a6f8a9b792927539f5472286a7bb5761d7409bb6a5760595a95a3
|
3 |
+
size 108612336
|
loras/spin-diffusion-v3-256.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:707b26129dd01835e5bb1ac7adbd8d8cb56e67039e9d281eb0c99c1aa541f510
|
3 |
+
size 217140488
|
loras/spin-diffusion-v3-512.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6607b906a3ec851bb59c5307b99fcdabe2652367b1f1f765f975a9bfd92f5b50
|
3 |
+
size 411585984
|