feat(mm): normalized model storage #8584
Draft
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.
Summary
Normalize model file storage to a flat directory structure.
Currently, models were stored in a nested hierarchy of folders like this:
<models_dir>/<base>/<type>/model_name.ext
for single-file models<models_dir>/<base>/<type>/model_name/**.*
for folder modelsThis has approach has a couple associated unpleasantries:
model.safetensors
. How do we work around that? Well, right now, we throw when a candidate model install would clobber an existing file.This PR normalizes/flattens model storage paths, storing each model in its own dir which is named with the model's unique key:
<models_dir>/<key>/file_name.ext
for single-file models<models_dir>/<key>/**.*
for folder modelsThis neatly addressing those unpleasantries:
models_dir
is not something you should fiddle with.This PR includes the simple code change for new model installs and a rather cautious migration to migrate to the new directory structure and update the model records in the DB. It uses SQLite save points and records all file operations, effectively making the DB and FS operations into a single transaction that can be rolled back.
It also removes some now-unused methods in the MM codebase.
Related Issues / Discussions
Numerous issues scattered throughout discord and GH
QA Instructions
First, test the migration with your
models_dir
at the default setting (e.g. nomodels_dir
ininvokeai.yaml
):cp -r /path/to/invokeai/ /path/to/invokeai_backup/
).databases/
andmodels/
dirs I suppose.models/
should have a UUID folder for each model in there.Next, do the same tests, but move
models_dir
to some other location (e.g.mv /path/to/invokeai/models/ /home/username/models/
and updateinvokeai.yaml
accordingly before starting up the app.I've tested both scenarios and tested invalid model configs in the DB. Everything working fine for me. We don't expect any generation issues, because we aren't doing anything that Invoke didn't already do. It already can load models from any location; we are just shuffling files around.
Merge Plan
n/a
Checklist
What's New
copy (if doing a release after this PR)