mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2026-02-24 00:34:15 +00:00
Old hash from cache (#16830)
* use not equal when comparing mtime * cache partial hash aka old hash Co-Authored-By: npc-riddlah <84955385+npc-riddlah@users.noreply.github.com> --------- Co-authored-by: npc-riddlah <84955385+npc-riddlah@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,7 @@ from urllib import request
|
||||
import ldm.modules.midas as midas
|
||||
|
||||
from modules import paths, shared, modelloader, devices, script_callbacks, sd_vae, sd_disable_initialization, errors, hashes, sd_models_config, sd_unet, sd_models_xl, cache, extra_networks, processing, lowvram, sd_hijack, patches
|
||||
from modules.hashes import partial_hash_from_cache as model_hash # noqa: F401 for backwards compatibility
|
||||
from modules.timer import Timer
|
||||
from modules.shared import opts
|
||||
import tomesd
|
||||
@@ -87,7 +88,7 @@ class CheckpointInfo:
|
||||
self.name = name
|
||||
self.name_for_extra = os.path.splitext(os.path.basename(filename))[0]
|
||||
self.model_name = os.path.splitext(name.replace("/", "_").replace("\\", "_"))[0]
|
||||
self.hash = model_hash(filename)
|
||||
self.hash = hashes.partial_hash_from_cache(filename)
|
||||
|
||||
self.sha256 = hashes.sha256_from_cache(self.filename, f"checkpoint/{name}")
|
||||
self.shorthash = self.sha256[0:10] if self.sha256 else None
|
||||
@@ -200,21 +201,6 @@ def get_closet_checkpoint_match(search_string):
|
||||
return None
|
||||
|
||||
|
||||
def model_hash(filename):
|
||||
"""old hash that only looks at a small part of the file and is prone to collisions"""
|
||||
|
||||
try:
|
||||
with open(filename, "rb") as file:
|
||||
import hashlib
|
||||
m = hashlib.sha256()
|
||||
|
||||
file.seek(0x100000)
|
||||
m.update(file.read(0x10000))
|
||||
return m.hexdigest()[0:8]
|
||||
except FileNotFoundError:
|
||||
return 'NOFILE'
|
||||
|
||||
|
||||
def select_checkpoint():
|
||||
"""Raises `FileNotFoundError` if no checkpoints are found."""
|
||||
model_checkpoint = shared.opts.sd_model_checkpoint
|
||||
|
||||
Reference in New Issue
Block a user