diff options
author | Roy Shilkrot <roy.shil@gmail.com> | 2022-10-31 11:45:52 -0400 |
---|---|---|
committer | Roy Shilkrot <roy.shil@gmail.com> | 2022-10-31 11:45:52 -0400 |
commit | 509fd1459bacfe0dcde1e5792ea3e046aa9f4d24 (patch) | |
tree | eaecb0351d6a95e4c29eaebdcb8b304990fd3a91 /modules/sd_models.py | |
parent | bdc90837987ed8919dd611fd01553b0c170ded5c (diff) | |
parent | dc7425a56e7a014cbfa3b3d44ad2321e519fe378 (diff) |
Merge remote-tracking branch 'upstream/master' into roy.add_simple_interrogate_api
Diffstat (limited to 'modules/sd_models.py')
-rw-r--r-- | modules/sd_models.py | 18 |
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)
|