Added optional argument to store model hashes #16829
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
What this PR do?
This PR add support for local hashes storing. It is very usable when using remote models storage, such as S3 mounted through s3fs or using very large models storages. Significantly reduces startup speed but needs to "compile" hashes on first launch.
It is not happens until you provide "--local-hash-path" argument.
In my configuration with local s3 storage on 10Gb\sec network reduces "list SD models" time on startup from 617.0s to 0.4s.
Why it is needed?
When using remote model storages stable-diffusion-webui models files will be fully downloaded on the local system to generate hash. When using large local model storages it will read every model file to generate hash.
Due to this specific behavior, startup time can increase significantly when using remote storage, or just a HUGE local storage, where large amount of big files must be readen to generate hash. This PR reduces startup speed with optional storing models hashes. Also potentially it can preserve model spoof attacks too: hashes generated earlier safer than hashes that updates every launch.
This PR changes:
modules/cmd_args.py:
--local-hash-pathmodules/sd_models.py:
models_hash_pathto store path from commandlinemodel_hash_generatethat generates and reads hash files with given pathmodel_hashfunction to check property models_hash_path is defined and choose what to do: generate now or use stored hashes.Final behaviour:
When launching with
--local-hash-path: on every call ofmodel_hashit will check existing of hash file and given directory. If it is exists - just reads hash. If not - creating dir (if not exists) and file, generating hash and writing it.Without
--local-hash-path: behaviour not changing at all.Checklist: