aboutsummaryrefslogtreecommitdiffstats
path: root/modules/sd_models.py
diff options
context:
space:
mode:
authorevshiron <evshiron@gmail.com>2022-10-29 19:45:29 +0000
committerevshiron <evshiron@gmail.com>2022-10-29 19:45:29 +0000
commit6b719c49b193a7dfeb64aacfdc8437037e07a2d1 (patch)
tree2ec883e44f3f959688ba65a4c5f194470bc7d467 /modules/sd_models.py
parentfddb4883f4a408b3464076465e1b0949ebe0fc30 (diff)
parent35c45df28b303a05d56a13cb56d4046f08cf8c25 (diff)
downloadstable-diffusion-webui-gfx803-6b719c49b193a7dfeb64aacfdc8437037e07a2d1.tar.gz
stable-diffusion-webui-gfx803-6b719c49b193a7dfeb64aacfdc8437037e07a2d1.tar.bz2
stable-diffusion-webui-gfx803-6b719c49b193a7dfeb64aacfdc8437037e07a2d1.zip
Merge branch 'master' into feat/progress-api
Diffstat (limited to 'modules/sd_models.py')
-rw-r--r--modules/sd_models.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/modules/sd_models.py b/modules/sd_models.py
index e697bb72..f86dc3ed 100644
--- a/modules/sd_models.py
+++ b/modules/sd_models.py
@@ -3,6 +3,7 @@ import os.path
import sys
from collections import namedtuple
import torch
+import re
from omegaconf import OmegaConf
from ldm.util import instantiate_from_config
@@ -35,8 +36,10 @@ def setup_model():
list_models()
-def checkpoint_tiles():
- return sorted([x.title for x in checkpoints_list.values()])
+def checkpoint_tiles():
+ convert = lambda name: int(name) if name.isdigit() else name.lower()
+ alphanumeric_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
+ return sorted([x.title for x in checkpoints_list.values()], key = alphanumeric_key)
def list_models():
@@ -170,7 +173,9 @@ def load_model_weights(model, checkpoint_info):
print(f"Global Step: {pl_sd['global_step']}")
sd = get_state_dict_from_checkpoint(pl_sd)
- missing, extra = model.load_state_dict(sd, strict=False)
+ del pl_sd
+ model.load_state_dict(sd, strict=False)
+ del sd
if shared.cmd_opts.opt_channelslast:
model.to(memory_format=torch.channels_last)
@@ -194,9 +199,10 @@ def load_model_weights(model, checkpoint_info):
model.first_stage_model.to(devices.dtype_vae)
- checkpoints_loaded[checkpoint_info] = model.state_dict().copy()
- while len(checkpoints_loaded) > shared.opts.sd_checkpoint_cache:
- checkpoints_loaded.popitem(last=False) # LRU
+ if shared.opts.sd_checkpoint_cache > 0:
+ checkpoints_loaded[checkpoint_info] = model.state_dict().copy()
+ while len(checkpoints_loaded) > shared.opts.sd_checkpoint_cache:
+ checkpoints_loaded.popitem(last=False) # LRU
else:
print(f"Loading weights [{sd_model_hash}] from cache")
checkpoints_loaded.move_to_end(checkpoint_info)