optimize model loader

This commit is contained in:
Vladimir Mandic
2023-03-24 13:48:26 -04:00
parent 44f61ee52c
commit 73135f2c12
6 changed files with 21 additions and 14 deletions
+2 -2
View File
@@ -86,8 +86,8 @@ def cleanup_models():
root_path = script_path
src_path = models_path
dest_path = os.path.join(models_path, "Stable-diffusion")
move_files(src_path, dest_path, ".ckpt")
move_files(src_path, dest_path, ".safetensors")
# move_files(src_path, dest_path, ".ckpt")
# move_files(src_path, dest_path, ".safetensors")
src_path = os.path.join(root_path, "ESRGAN")
dest_path = os.path.join(models_path, "ESRGAN")
move_files(src_path, dest_path)
+11 -8
View File
@@ -239,14 +239,17 @@ def read_metadata_from_safetensors(filename):
def read_state_dict(checkpoint_file):
_, extension = os.path.splitext(checkpoint_file)
with rich.progress.open(checkpoint_file, 'rb') as f:
if extension.lower() == ".safetensors":
buffer = f.read()
pl_sd = safetensors.torch.load(buffer)
else:
buffer = io.BytesIO(f.read())
pl_sd = torch.load(buffer, map_location='cpu')
if 'v1-5-pruned-emaonly.safetensors' in checkpoint_file:
pl_sd = safetensors.torch.load_file(checkpoint_file, device='cpu')
else:
_, extension = os.path.splitext(checkpoint_file)
with rich.progress.open(checkpoint_file, 'rb') as f:
if extension.lower() == ".safetensors":
buffer = f.read()
pl_sd = safetensors.torch.load(buffer)
else:
buffer = io.BytesIO(f.read())
pl_sd = torch.load(buffer, map_location='cpu')
sd = get_state_dict_from_checkpoint(pl_sd)
return sd
+5 -1
View File
@@ -1533,5 +1533,9 @@
"customscript/seed_travel.py/img2img/SSIM min threshold/value": 75,
"customscript/seed_travel.py/img2img/SSIM min threshold/minimum": 0,
"customscript/seed_travel.py/img2img/SSIM min threshold/maximum": 100,
"customscript/seed_travel.py/img2img/SSIM min threshold/step": 1
"customscript/seed_travel.py/img2img/SSIM min threshold/step": 1,
"customscript/seed_travel.py/txt2img/Interpolation curve/visible": true,
"customscript/seed_travel.py/txt2img/Interpolation curve/value": "Linear",
"customscript/seed_travel.py/img2img/Interpolation curve/visible": true,
"customscript/seed_travel.py/img2img/Interpolation curve/value": "Linear"
}