Commit 454d05b
authored
refactor: model manager v3 (#8607)
* feat(mm): add UnknownModelConfig
* refactor(ui): move model categorisation-ish logic to central location, simplify model manager models list
* refactor(ui)refactor(ui): more cleanup of model categories
* refactor(ui): remove unused excludeSubmodels
I can't remember what this was for and don't see any reference to it.
Maybe it's just remnants from a previous implementation?
* feat(nodes): add unknown as model base
* chore(ui): typegen
* feat(ui): add unknown model base support in ui
* feat(ui): allow changing model type in MM, fix up base and variant selects
* feat(mm): omit model description instead of making it "base type filename model"
* feat(app): add setting to allow unknown models
* feat(ui): allow changing model format in MM
* feat(app): add the installed model config to install complete events
* chore(ui): typegen
* feat(ui): toast warning when installed model is unidentified
* docs: update config docstrings
* chore(ui): typegen
* tests(mm): fix test for MM, leave the UnknownModelConfig class in the list of configs
* tidy(ui): prefer types from zod schemas for model attrs
* chore(ui): lint
* fix(ui): wrong translation string
* feat(mm): normalized model storage
Store models in a flat directory structure. Each model is in a dir named
its unique key (a UUID). Inside that dir is either the model file or the
model dir.
* feat(mm): add migration to flat model storage
* fix(mm): normalized multi-file/diffusers model installation no worky
now worky
* refactor: port MM probes to new api
- Add concept of match certainty to new probe
- Port CLIP Embed models to new API
- Fiddle with stuff
* feat(mm): port TIs to new API
* tidy(mm): remove unused probes
* feat(mm): port spandrel to new API
* fix(mm): parsing for spandrel
* fix(mm): loader for clip embed
* fix(mm): tis use existing weight_files method
* feat(mm): port vae to new API
* fix(mm): vae class inheritance and config_path
* tidy(mm): patcher types and import paths
* feat(mm): better errors when invalid model config found in db
* feat(mm): port t5 to new API
* feat(mm): make config_path optional
* refactor(mm): simplify model classification process
Previously, we had a multi-phase strategy to identify models from their
files on disk:
1. Run each model config classes' `matches()` method on the files. It
checks if the model could possibly be an identified as the candidate
model type. This was intended to be a quick check. Break on the first
match.
2. If we have a match, run the config class's `parse()` method. It
derive some additional model config attrs from the model files. This was
intended to encapsulate heavier operations that may require loading the
model into memory.
3. Derive the common model config attrs, like name, description,
calculate the hash, etc. Some of these are also heavier operations.
This strategy has some issues:
- It is not clear how the pieces fit together. There is some
back-and-forth between different methods and the config base class. It
is hard to trace the flow of logic until you fully wrap your head around
the system and therefore difficult to add a model architecture to the
probe.
- The assumption that we could do quick, lightweight checks before
heavier checks is incorrect. We often _must_ load the model state dict
in the `matches()` method. So there is no practical perf benefit to
splitting up the responsibility of `matches()` and `parse()`.
- Sometimes we need to do the same checks in `matches()` and `parse()`.
In these cases, splitting the logic is has a negative perf impact
because we are doing the same work twice.
- As we introduce the concept of an "unknown" model config (i.e. a model
that we cannot identify, but still record in the db; see #8582), we will
_always_ run _all_ the checks for every model. Therefore we need not try
to defer heavier checks or resource-intensive ops like hashing. We are
going to do them anyways.
- There are situations where a model may match multiple configs. One
known case are SD pipeline models with merged LoRAs. In the old probe
API, we relied on the implicit order of checks to know that if a model
matched for pipeline _and_ LoRA, we prefer the pipeline match. But, in
the new API, we do not have this implicit ordering of checks. To resolve
this in a resilient way, we need to get all matches up front, then use
tie-breaker logic to figure out which should win (or add "differential
diagnosis" logic to the matchers).
- Field overrides weren't handled well by this strategy. They were only
applied at the very end, if a model matched successfully. This means we
cannot tell the system "Hey, this model is type X with base Y. Trust me
bro.". We cannot override the match logic. As we move towards letting
users correct mis-identified models (see #8582), this is a requirement.
We can simplify the process significantly and better support "unknown"
models.
Firstly, model config classes now have a single `from_model_on_disk()`
method that attempts to construct an instance of the class from the
model files. This replaces the `matches()` and `parse()` methods.
If we fail to create the config instance, a special exception is raised
that indicates why we think the files cannot be identified as the given
model config class.
Next, the flow for model identification is a bit simpler:
- Derive all the common fields up-front (name, desc, hash, etc).
- Merge in overrides.
- Call `from_model_on_disk()` for every config class, passing in the
fields. Overrides are handled in this method.
- Record the results for each config class and choose the best one.
The identification logic is a bit more verbose, with the special
exceptions and handling of overrides, but it is very clear what is
happening.
The one downside I can think of for this strategy is we do need to check
every model type, instead of stopping at the first match. It's a bit
less efficient. In practice, however, this isn't a hot code path, and
the improved clarity is worth far more than perf optimizations that the
end user will likely never notice.
* refactor(mm): remove unused methods in config.py
* refactor(mm): add model config parsing utils
* fix(mm): abstractmethod bork
* tidy(mm): clarify that model id utils are private
* fix(mm): fall back to UnknownModelConfig correctly
* feat(mm): port CLIPVisionDiffusersConfig to new api
* feat(mm): port SigLIPDiffusersConfig to new api
* feat(mm): make match helpers more succint
* feat(mm): port flux redux to new api
* feat(mm): port ip adapter to new api
* tidy(mm): skip optimistic override handling for now
* refactor(mm): continue iterating on config
* feat(mm): port flux "control lora" and t2i adapter to new api
* tidy(ui): use Extract to get model config types
* fix(mm): t2i base determination
* feat(mm): port cnet to new api
* refactor(mm): add config validation utils, make it all consistent and clean
* feat(mm): wip port of main models to new api
* feat(mm): wip port of main models to new api
* feat(mm): wip port of main models to new api
* docs(mm): add todos
* tidy(mm): removed unused model merge class
* feat(mm): wip port main models to new api
* tidy(mm): clean up model heuristic utils
* tidy(mm): clean up ModelOnDisk caching
* tidy(mm): flux lora format util
* refactor(mm): make config classes narrow
Simpler logic to identify, less complexity to add new model, fewer
useless attrs that do not relate to the model arch, etc
* refactor(mm): diffusers loras
w
* feat(mm): consistent naming for all model config classes
* fix(mm): tag generation & scattered probe fixes
* tidy(mm): consistent class names
* refactor(mm): split configs into separate files
* docs(mm): add comments for identification utils
* chore(ui): typegen
* refactor(mm): remove legacy probe, new configs dir structure, update imports
* fix(mm): inverted condition
* docs(mm): update docsstrings in factory.py
* docs(mm): document flux variant attr
* feat(mm): add helper method for legacy configs
* feat(mm): satisfy type checker in flux denoise
* docs(mm): remove extraneous comment
* fix(mm): ensure unknown model configs get unknown attrs
* fix(mm): t5 identification
* fix(mm): sdxl ip adapter identification
* feat(mm): more flexible config matching utils
* fix(mm): clip vision identification
* feat(mm): add sanity checks before probing paths
* docs(mm): add reminder for self for field migrations
* feat(mm): clearer naming for main config class hierarchy
* feat(mm): fix clip vision starter model bases, add ref to actual models
* feat(mm): add model config schema migration logic
* fix(mm): duplicate import
* refactor(mm): split big migration into 3
Split the big migration that did all of these things into 3:
- Migration 22: Remove unique contraint on base/name/type in models
table
- Migration 23: Migrate configs to v6.8.0 schemas
- Migration 24: Normalize file storage
* fix(mm): pop base/type/format when creating unknown model config
* fix(db): migration 22 insert only real cols
* fix(db): migration 23 fall back to unknown model when config change fails
* feat(db): run migrations 23 and 24
* fix(mm): false negative on flux lora
* fix(mm): vae checkpoint probe checking for dir instead of file
* fix(mm): ModelOnDisk skips dirs when looking for weights
Previously a path w/ any of the known weights suffixes would be seen as
a weights file, even if it was a directory. We now check to ensure the
candidate path is actually a file before adding it to the list of
weights.
* feat(mm): add method to get main model defaults from a base
* feat(mm): do not log when multiple non-unknown model matches
* refactor(mm): continued iteration on model identifcation
* tests(mm): refactor model identification tests
Overhaul of model identification (probing) tests. Previously we didn't
test the correctness of probing except in a few narrow cases - now we
do.
See tests/model_identification/README.md for a detailed overview of the
new test setup. It includes instructions for adding a new test case. In
brief:
- Download the model you want to add as a test case
- Run a script against it to generate the test model files
- Fill in the expected model type/format/base/etc in the generated test
metadata JSON file
Included test cases:
- All starter models
- A handful of other models that I had installed
- Models present in the previous test cases as smoke tests, now also
tested for correctness
* fix(mm): omit type/format/base when creating unknown config instance
* feat(mm): use ValueError for model id sanity checks
* feat(mm): add flag for updating models to allow class changes
* tests(mm): fix remaining MM tests
* feat: allow users to edit models freely
* feat(ui): add warning for model settings edit
* tests(mm): flux state dict tests
* tidy: remove unused file
* fix(mm): lora state dict loading in model id
* feat(ui): use translation string for model edit warning
* docs(db): update version numbers in migration comments
* chore: bump version to v6.9.0a1
* docs: update model id readme
* tests(mm): attempt to fix windows model id tests
* fix(mm): issue with deleting single file models
* feat(mm): just delete the dir w/ rmtree when deleting model
* tests(mm): windows CI issue
* fix(ui): typegen schema sync
* fix(mm): fixes for migration 23
- Handle CLIP Embed and Main SD models missing variant field
- Handle errors when calling the discriminator function, previously only
handled ValidationError but it could be a ValueError or something else
- Better logging for config migration
* chore: bump version to v6.9.0a2
* chore: bump version to v6.9.0a31 parent a7e1f06 commit 454d05b
File tree
548 files changed
+19532
-14038
lines changed- invokeai
- app
- api/routers
- invocations
- services
- config
- events
- model_install
- model_load
- model_manager
- model_records
- model_relationships
- util
- backend
- flux
- controlnet
- ip_adapter
- redux
- model_manager
- configs
- load
- model_loaders
- util
- patches/lora_conversions
- quantization/scripts
- util
- frontend/web
- public/locales
- src
- app/store/middleware/listenerMiddleware/listeners
- features
- controlLayers
- components
- konva
- CanvasEntity
- CanvasTool
- store
- lora/components
- metadata
- modelManagerV2
- subpanels
- ModelManagerPanel
- ModelPanel
- Fields
- nodes
- types
- util/graph
- generation
- parameters
- components
- Advanced
- store
- types
- util
- queue/store
- settingsAccordions/components/GenerationSettingsAccordion
- system/store
- ui/layouts
- services
- api
- hooks
- events
- version
- scripts
- tests
- app/services
- model_install
- model_records
- backend
- ip_adapter
- model_manager
- util
- patches/lora_conversions
- model_identification
- stripped_models
- 01b5565e-133c-4e9b-afdf-c8b028fc3560
- 027d8059-e7f8-46c3-9aa7-90a0ad5cccbe
- 11431812-384a-4058-98c4-ac34c30e11be
- 125e8a78-7aac-4d3e-8931-029d6eda192d
- 176cba5d-d418-4857-879b-08ed0413bc38
- 19fd1a40-c5b7-4734-bd3a-6e0e948cce0b
- 1d41bd0e-4368-4d43-af3f-b47c51cc4edc
- 21494f81-f438-42ad-b09f-884c779cac8f
- 27fe3253-cc5d-4102-9ddf-b042a097ec97
- 2f12a739-975d-4f77-b3b4-4964745b2a71
- video_processor
- 3a07d4a4-ce40-4681-b6b7-58fde1512ead
- 3b9cac59-c72d-4878-82e6-fb54e1bd5984
- 3f82689a-6e7d-49f1-ac81-ccd71df6b6e3
- 405596fb-15d6-46c6-86af-01ec91d3b184
- 433ef525-af19-4165-bbff-36ec39e9b188
- 44c29320-b55e-43f0-9b62-be903b05ee58
- 4c222a9b-5e72-4518-a876-cdc4e1b2db79
- 4d1c4d22-4a0a-48b5-b5ad-e854c9c9f539
- 4ef93267-0302-4318-b3c6-018ab320ca86
- scheduler
- text_encoder_2
- text_encoder
- tokenizer_2
- tokenizer
- unet
- vae
- 4f7a0a7f-c823-494d-94d4-dbbec6ea6ef6
- 55d98551-43b3-4849-8d30-2a5df0e3cdaa
- 572b86e1-c399-4709-a056-fad09bb010f3
- feature_extractor
- safety_checker
- scheduler
- text_encoder
- tokenizer
- unet
- vae
- 58149188-b9be-4ff4-a335-8f371eaec231
- 5a5fe5e4-5776-43e9-a062-530080b2ead1
- scheduler
- text_encoder_2
- text_encoder_3
- text_encoder
- tokenizer_2
- tokenizer_3
- tokenizer
- transformer
- vae
- 64e4d697-589b-4928-957a-1b1493ee9733
- 6da2ebf9-2e22-4b5f-8966-ec99527e676c
- scheduler
- text_encoder
- tokenizer
- transformer
- vae
- 72ca4c91-9da9-48c5-9bfe-b7e1fe788849
- 76729c9d-709a-4b3d-90a6-5d7d55d3598c
- 78197983-663b-4743-84c4-aeb05fab3252
- 7891e249-19e1-418a-8fed-2dd3f9961c82
- 7dc33d7f-d27b-45fb-975f-0f477cbfa95f
- feature_extractor
- safety_checker
- scheduler
- text_encoder
- tokenizer
- unet
- vae
- 7f9cce60-6e9f-4ec0-b95e-2f37e87edf45
- 7f9e4d17-5bc0-4e5b-9c59-d694d46c5b20
- 81cba86d-2ccd-49c2-9ea2-e7fd4f41dd7a
- 8226d565-63c7-487e-8e20-82a76e41e792
- 881652b6-86e8-4df5-b7c4-fea6315f420f
- 8ac85545-34a7-4914-aecf-dfea9045abda
- 8d5cccf5-3ad3-494d-979a-80c853a0fdc3
- 8e8a1892-a19c-433f-a13d-b502e62a814a
- scheduler
- text_encoder_2
- tokenizer_2
- unet
- vae_1_0
- vae
- 8efd665b-7a0d-42cf-9abc-a4dab6a72aeb
- scheduler
- text_encoder_2
- text_encoder_3
- text_encoder
- tokenizer_2
- tokenizer_3
- tokenizer
- transformer
- vae
- 96a698ac-33e8-401f-bada-69cc24e00a3e
- 98b11b23-4cd5-482c-aeb7-e32d6724ebde
- text_encoder
- tokenizer
- 9bfad30b-db21-4e08-9794-3779799c5233
- a18131fb-28b7-4cfa-8606-738442155501
- aaa59ad7-3bc0-49d9-a3c5-416d12435796
- b8cb086d-76c9-4991-a4e9-d672557968ea
- ba7e72a2-ec20-4eea-8689-49ef49d91dc1
- bd4bc034-4b83-4512-8070-f89e9bfe0b84
- bff52078-4c99-457c-9306-09b95596560e
- c03aa7c6-e2d6-4085-ae1e-b43918f024ff
- c10a0b53-9b83-45b5-b4ea-ffaa512f4df2
- cb703a01-b4a0-4952-9cab-a75688021ff2
- ccb30d3a-df46-49ea-9b33-6f842ad06940
- cce6c39d-72e3-47fd-a5c3-ff175532227a
- ce740d0e-0501-4114-b3a6-21983dff16ae
- d38f780f-0150-4bb1-8172-f0ee61ca0d08
- d79ca174-bb19-4793-8fb6-5b66e5584301
- d9c874a9-9d8a-46d3-b7d3-4a2529f71529
- dad77dcb-9e55-4bb1-9739-9dd01f9eb232
- text_encoder_2
- tokenizer_2
- dc79db49-7f38-4f54-b4f1-e7c521ded481
- video_processor
- de909c6f-3141-4f5f-b19c-fcc7f2fae9a5
- defcb480-75d9-41b0-9812-f1608c068a5c
- e37a3321-7b9c-46fd-9a58-32456fef0cff
- e9e6d524-2182-4edd-880b-d3173a911bee
- ec75ae24-6f50-4a35-be1b-2a2063bcad69
- f75f55ca-c530-4353-beba-c9e10b155aa7
- fb2f9ddd-ca78-4bc6-97d4-1d2245d1d635
- fb970a52-8f62-4912-b02f-b72b40054130
- fd5eb853-a50e-490c-ad9e-e2c74a513154
- text_encoder_2
- tokenizer_2
- ff775f86-a9f6-4a4b-88b0-9343a2f49b6e
- test_model_probe
- sd-1/main/dreamshaper-8-inpainting
- scheduler
- unet
- stripped_models
- Hard Edge Detection (canny)
- IP Adapter SD1
- Juggernaut XL v9
- text_encoder_2
- text_encoder
- unet
- vae
- Lineart
- Segmentation Map
- clip-vit-large-patch14
- dreamshaper-8/vae
- siglip-so400m-patch14-384
- text_encoder
- vae
- sd-vae-ft-mse
- sdxl-vae
- taesdxl-fp16
- taesdxl
- taesd
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
548 files changed
+19532
-14038
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
297 | 300 | | |
298 | 301 | | |
299 | 302 | | |
300 | | - | |
301 | 303 | | |
302 | | - | |
303 | | - | |
| 304 | + | |
304 | 305 | | |
305 | 306 | | |
306 | 307 | | |
| |||
743 | 744 | | |
744 | 745 | | |
745 | 746 | | |
746 | | - | |
747 | | - | |
748 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
749 | 759 | | |
750 | 760 | | |
751 | 761 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
| |||
182 | 180 | | |
183 | 181 | | |
184 | 182 | | |
185 | | - | |
186 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
187 | 186 | | |
188 | | - | |
| 187 | + | |
189 | 188 | | |
190 | 189 | | |
191 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
| 236 | + | |
236 | 237 | | |
237 | 238 | | |
238 | 239 | | |
| |||
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
280 | | - | |
| 281 | + | |
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 19 | + | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
| |||
68 | 65 | | |
69 | 66 | | |
70 | 67 | | |
71 | | - | |
| 68 | + | |
72 | 69 | | |
73 | 70 | | |
74 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| |||
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
90 | | - | |
| 88 | + | |
91 | 89 | | |
92 | 90 | | |
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
97 | | - | |
| 95 | + | |
98 | 96 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
| 27 | + | |
29 | 28 | | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
0 commit comments