Skip to content

Commit

Permalink
keep order in list of checkpoints when loading model that doesn't hav…
Browse files Browse the repository at this point in the history
…e a checksum
  • Loading branch information
AUTOMATIC1111 committed Aug 30, 2023
1 parent 9e7de49 commit 503bd3f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion modules/sd_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
checkpoints_loaded = collections.OrderedDict()


def replace_key(d, key, new_key, value):
keys = list(d.keys())

d[new_key] = value

if key not in keys:
return d

index = keys.index(key)
keys[index] = new_key

new_d = {k: d[k] for k in keys}

d.clear()
d.update(new_d)
return d


class CheckpointInfo:
def __init__(self, filename):
self.filename = filename
Expand Down Expand Up @@ -91,9 +109,11 @@ def calculate_shorthash(self):
if self.shorthash not in self.ids:
self.ids += [self.shorthash, self.sha256, f'{self.name} [{self.shorthash}]', f'{self.name_for_extra} [{self.shorthash}]']

checkpoints_list.pop(self.title, None)
old_title = self.title
self.title = f'{self.name} [{self.shorthash}]'
self.short_title = f'{self.name_for_extra} [{self.shorthash}]'

replace_key(checkpoints_list, old_title, self.title, self)
self.register()

return self.shorthash
Expand Down

0 comments on commit 503bd3f

Please sign in to comment.