WIP implementation of unique hash keys for models #4180
Closed
+139
−14
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.
What type of PR is this? (check all applicable)
Have you discussed this change with the InvokeAI team?
Have you updated all relevant documentation?
Description
This is a work in progress that assigns models a unique hash based on their contents. It uses the
imohashmodule (https://pypi.org/project/imohash/) which generates unique fingerprints from very large files rapidly by sampling the beginning, middle and end of the file. The model hashing works both for single files (e.g. checkpoints) and diffusers-style directories. Because the config files in diffusers contain things like local file paths and the diffusers version, these files are not included in the directory hashing algorithm.The model hash is now part of the base config for each model, as returned by
ModelManager.list_models(). You can get a model using its hash by making a newModelManager.get_model_by_hash()call.This code is intended as an intermediate step towards replacing the composite
models.yamlkeys (base/type/name) with the unique hash. Right now the models dictionary is still indexed usingbase/type/name, which allows the same model to go in twice under different names and is sensitive to the user changing the model name or type. However, this PR does the additional step of checking the model hash as a new model is added and raising an exception if a model with the same hash exists.Related Tickets & Documents
QA Instructions, Screenshots, Recordings
You will need to
pip install imohashto test this PR.Added/updated tests?
Will add tests if this WIP advances.