Added optional argument to store model hashes#16829
Added optional argument to store model hashes#16829radiopabm2 wants to merge 3 commits intoAUTOMATIC1111:devfrom radiopabm2:local-hash-store
Conversation
|
nice catch, good PR |
Thank you for fast answer and pr review! |
not WIP, it's very old stuff we forgot about the old hash as it was deprecated for a long time we used to store all hash in cache.json file, but but it became problematic and we switched to using diskcache (basically a sqlite wrapper) |
Thanx for explanation! It seeems you can close this PR now. Will wait new pr will be submitted :) |
|
btw |
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: