Commit Graph

5160 Commits

Author SHA1 Message Date
Lincoln Stein
66e2d1b346 add concept of repo variant 2024-02-29 13:16:36 -05:00
psychedelicious
55147fbb7e tests(ui): add parseFieldType.test.ts 2024-02-29 13:16:36 -05:00
psychedelicious
c99e264bde feat(ui): add more types of FieldParseError
Unfortunately you cannot test for both a specific type of error and match its message. Splitting the error classes makes it easier to test expected error conditions.
2024-02-29 13:16:36 -05:00
psychedelicious
62c3687a9a feat(ui): add vitest
- Add vitest.
- Consolidate vite configs into single file (easier to config everything based on env for testing)
2024-02-29 13:16:36 -05:00
psychedelicious
c7f1fad398 feat(ui): workflow schema v3 (WIP)
The changes aim to deduplicate data between workflows and node templates, decoupling workflows from internal implementation details. A good amount of data that was needlessly duplicated from the node template to the workflow is removed.

These changes substantially reduce the file size of workflows (and therefore the images with embedded workflows):

- Default T2I SD1.5 workflow JSON is reduced from 23.7kb (798 lines) to 10.9kb (407 lines).
- Default tiled upscale workflow JSON is reduced from 102.7kb (3341 lines) to 51.9kb (1774 lines).

The trade-off is that we need to reference node templates to get things like the field type and other things. In practice, this is a non-issue, because we need a node template to do anything with a node anyways.

- Field types are not included in the workflow. They are always pulled from the node templates.

The field type is now properly an internal implementation detail and we can change it as needed. Previously this would require a migration for the workflow itself. With the v3 schema, the structure of a field type is an internal implementation detail that we are free to change as we see fit.

- Workflow nodes no long have an `outputs` property and there is no longer such a thing as a `FieldOutputInstance`. These are only on the templates.

These were never referenced at a time when we didn't also have the templates available, and there'd be no reason to do so.

- Node width and height are no longer stored in the node.

These weren't used. Also, per https://reactflow.dev/api-reference/types/node, we shouldn't be programmatically changing these properties. A future enhancement can properly add node resizing.

- `nodeTemplates` slice is merged back into `nodesSlice` as `nodes.templates`. Turns out it's just a hassle having these separate in separate slices.

- Workflow migration logic updated to support the new schema. V1 workflows migrate all the way to v3 now.

- Changes throughout the nodes code to accommodate the above changes.
2024-02-29 13:16:36 -05:00
psychedelicious
0540e6fb0d chore(ui): regen types 2024-02-29 13:16:36 -05:00
psychedelicious
179aa1de63 feat(nodes): add more missing exports to invocation_api
Crawled through a few custom nodes to figure out what I had missed.
2024-02-29 13:16:36 -05:00
psychedelicious
acc50d9bd2 chore(nodes): "SAMPLER_NAME_VALUES" -> "SCHEDULER_NAME_VALUES"
This was named inaccurately.
2024-02-29 13:16:36 -05:00
psychedelicious
54d92cb246 chore(nodes): remove deprecation logic for nodes API 2024-02-29 13:16:36 -05:00
psychedelicious
17ed6cc82f chore(nodes): export model-related objects from invocation_api 2024-02-29 13:16:36 -05:00
psychedelicious
5927ab9c36 chore(backend): rename ModelInfo -> LoadedModelInfo
We have two different classes named `ModelInfo` which might need to be used by API consumers. We need to export both but have to deal with this naming collision.

The `ModelInfo` I've renamed here is the one that is returned when a model is loaded. It's the object least likely to be used by API consumers.
2024-02-29 13:16:36 -05:00
psychedelicious
08636e42af feat(nodes): use LATENT_SCALE_FACTOR in primitives.py, noise.py
- LatentsOutput.build
- NoiseOutput.build
- Noise.width, Noise.height multiple_of
2024-02-29 13:16:36 -05:00
psychedelicious
2d74a39810 feat(nodes): extract LATENT_SCALE_FACTOR to constants.py 2024-02-29 13:16:36 -05:00
psychedelicious
bcc57dc886 feat(nodes): use TemporaryDirectory to handle ephemeral storage in ObjectSerializerDisk
Replace `delete_on_startup: bool` & associated logic with `ephemeral: bool` and `TemporaryDirectory`.

The temp dir is created inside of `output_dir`. For example, if `output_dir` is `invokeai/outputs/tensors/`, then the temp dir might be `invokeai/outputs/tensors/tmpvj35ht7b/`.

The temp dir is cleaned up when the service is stopped, or when it is GC'd if not properly stopped.

In the event of a catastrophic crash where the temp files are not cleaned up, the user can delete the tempdir themselves.

This situation may not occur in normal use, but if you kill the process, python cannot clean up the temp dir itself. This includes running the app in a debugger and killing the debugger process - something I do relatively often.

Tests updated.
2024-02-29 13:16:36 -05:00
psychedelicious
dc003a4bac chore(nodes): update ObjectSerializerForwardCache docstring 2024-02-29 13:16:36 -05:00
psychedelicious
e464804696 chore(nodes): fix pyright ignore 2024-02-29 13:16:36 -05:00
psychedelicious
6b5f01ed3f tidy(nodes): "latents" -> "obj" 2024-02-29 13:16:36 -05:00
psychedelicious
c05c3e5a7b tidy(nodes): do not store unnecessarily store invoker 2024-02-29 13:16:36 -05:00
psychedelicious
d202243c62 feat(nodes): make delete on startup configurable for obj serializer
- The default is to not delete on startup - feels safer.
- The two services using this class _do_ delete on startup.
- The class has "ephemeral" removed from its name.
- Tests & app updated for this change.
2024-02-29 13:16:36 -05:00
psychedelicious
7e04f2bff9 fix(nodes): use metadata/board_id if provided by user, overriding WithMetadata/WithBoard-provided values 2024-02-29 13:16:36 -05:00
psychedelicious
0282f477b6 tidy(nodes): clarify comment 2024-02-29 13:16:36 -05:00
psychedelicious
9983eddc01 Revert "feat(nodes): use LATENT_SCALE_FACTOR const in tensor output builders"
This reverts commit ef18fc546560277302f3886e456da9a47e8edce0.
2024-02-29 13:16:36 -05:00
psychedelicious
b62be80762 feat(nodes): use LATENT_SCALE_FACTOR const in tensor output builders 2024-02-29 13:16:36 -05:00
psychedelicious
62db617b41 tests: fix broken tests 2024-02-29 13:16:36 -05:00
psychedelicious
6905f18c08 tidy(nodes): minor spelling correction 2024-02-29 13:16:36 -05:00
psychedelicious
27d7a1731b feat(nodes): allow _delete_all in obj serializer to be called at any time
`_delete_all` logged how many items it deleted, and had to be called _after_ service start bc it needed access to logger.

Move the logger call to the startup method and return the the deleted stats from `_delete_all`. This lets `_delete_all` be called at any time.
2024-02-29 13:16:36 -05:00
psychedelicious
787510a65b tidy(nodes): remove object serializer on_saved
It's unused.
2024-02-29 13:16:36 -05:00
psychedelicious
d9dc5d58be revert(nodes): revert making tensors/conditioning use item storage
Turns out they are just different enough in purpose that the implementations would be rather unintuitive. I've made a separate ObjectSerializer service to handle tensors and conditioning.

Refined the class a bit too.
2024-02-29 13:16:36 -05:00
psychedelicious
614f0e8086 feat(nodes): support custom exception in ephemeral disk storage 2024-02-29 13:16:36 -05:00
psychedelicious
723009e163 feat(nodes): support custom save and load functions in ItemStorageEphemeralDisk 2024-02-29 13:16:36 -05:00
psychedelicious
abdc87d5fc feat(nodes): create helper function to generate the item ID 2024-02-29 13:16:36 -05:00
psychedelicious
7cb8e29726 feat(nodes): use ItemStorageABC for tensors and conditioning
Turns out `ItemStorageABC` was almost identical to `PickleStorageBase`. Instead of maintaining separate classes, we can use `ItemStorageABC` for both.

There's only one change needed - the `ItemStorageABC.set` method must return the newly stored item's ID. This allows us to let the service handle the responsibility of naming the item, but still create the requisite output objects during node execution.

The naming implementation is improved here. It extracts the name of the generic and appends a UUID to that string when saving items.
2024-02-29 13:16:36 -05:00
psychedelicious
f593959bea tidy(nodes): do not refer to files as latents in PickleStorageTorch (again) 2024-02-29 13:16:36 -05:00
psychedelicious
c7218dc130 feat(nodes): ItemStorageABC typevar no longer bound to pydantic.BaseModel
This bound is totally unnecessary. There's no requirement for any implementation of `ItemStorageABC` to work only on pydantic models.
2024-02-29 13:16:36 -05:00
psychedelicious
ebc3a24d0d fix(nodes): add super init to PickleStorageTorch 2024-02-29 13:16:36 -05:00
psychedelicious
315681b491 tidy(nodes): do not refer to files as latents in PickleStorageTorch 2024-02-29 13:16:36 -05:00
psychedelicious
0c149cbd3b feat(nodes): replace latents service with tensors and conditioning services
- New generic class `PickleStorageBase`, implements the same API as `LatentsStorageBase`, use for storing non-serializable data via pickling
- Implementation `PickleStorageTorch` uses `torch.save` and `torch.load`, same as `LatentsStorageDisk`
- Add `tensors: PickleStorageBase[torch.Tensor]` to `InvocationServices`
- Add `conditioning: PickleStorageBase[ConditioningFieldData]` to `InvocationServices`
- Remove `latents` service and all `LatentsStorage` classes
- Update `InvocationContext` and all usage of old `latents` service to use the new services/context wrapper methods
2024-02-29 13:16:36 -05:00
psychedelicious
3563d4ecf7 tidy(nodes): delete onnx.py
It doesn't work and keeping it updated to prevent the app from starting was getting tedious. Deleted.
2024-02-29 13:16:36 -05:00
psychedelicious
c4ea96dec2 fix(nodes): rearrange fields.py to avoid needing forward refs 2024-02-29 13:16:36 -05:00
psychedelicious
06d0232841 tidy(nodes): remove unnecessary, shadowing class attr declarations 2024-02-29 13:16:36 -05:00
psychedelicious
bb8c71f706 feat(ui): revise graphs to not use LinearUIOutputInvocation
See this comment for context: https://github.com/invoke-ai/InvokeAI/pull/5491#discussion_r1480760629

- Remove this now-unnecessary node from all graphs
- Update graphs' terminal image-outputting nodes' `is_intermediate` and `board` fields appropriately
- Add util function to prepare the `board` field, tidy the utils
- Update `socketInvocationComplete` listener to work correctly with this change

I've manually tested all graph permutations that were changed (I think this is all...) to ensure images go to the gallery as expected:
- ad-hoc upscaling
- t2i w/ sd1.5
- t2i w/ sd1.5 & hrf
- t2i w/ sdxl
- t2i w/ sdxl + refiner
- i2i w/ sd1.5
- i2i w/ sdxl
- i2i w/ sdxl + refiner
- canvas t2i w/ sd1.5
- canvas t2i w/ sdxl
- canvas t2i w/ sdxl + refiner
- canvas i2i w/ sd1.5
- canvas i2i w/ sdxl
- canvas i2i w/ sdxl + refiner
- canvas inpaint w/ sd1.5
- canvas inpaint w/ sdxl
- canvas inpaint w/ sdxl + refiner
- canvas outpaint w/ sd1.5
- canvas outpaint w/ sdxl
- canvas outpaint w/ sdxl + refiner
2024-02-29 13:16:36 -05:00
psychedelicious
c16f77bb23 chore(ui): regen types 2024-02-29 13:16:36 -05:00
psychedelicious
1e4b953ccd feat(nodes): add WithBoard field helper class
This class works the same way as `WithMetadata` - it simply adds a `board` field to the node. The context wrapper function is able to pull the board id from this. This allows image-outputting nodes to get a board field "for free", and have their outputs automatically saved to it.

This is a breaking change for node authors who may have a field called `board`, because it makes `board` a reserved field name. I'll look into how to avoid this - maybe by naming this invoke-managed field `_board` to avoid collisions?

Supporting changes:
- `WithBoard` is added to all image-outputting nodes, giving them the ability to save to board.
- Unused, duplicate `WithMetadata` and `WithWorkflow` classes are deleted from `baseinvocation.py`. The "real" versions are in `fields.py`.
- Remove `LinearUIOutputInvocation`. Now that all nodes that output images also have a `board` field by default, this node is no longer necessary. See comment here for context: https://github.com/invoke-ai/InvokeAI/pull/5491#discussion_r1480760629
- Without `LinearUIOutputInvocation`, the `ImagesInferface.update` method is no longer needed, and removed.

Note: This commit does not bump all node versions. I will ensure that is done correctly before merging the PR of which this commit is a part.

Note: A followup commit will implement the frontend changes to support this change.
2024-02-29 13:16:36 -05:00
psychedelicious
d6ce901ad2 remove unused configdict import 2024-02-29 13:16:36 -05:00
psychedelicious
060038a8c0 fix(ui): remove original l2i node in HRF graph 2024-02-29 13:16:36 -05:00
psychedelicious
e38d275e20 fix(nodes): do not freeze or cache config in context wrapper
- The config is already cached by the config class's `get_config()` method.
- The config mutates itself in its `root_path` property getter. Freezing the class makes any attempt to grab a path from the config error. Unfortunately this means we cannot easily freeze the class without fiddling with the inner workings of `InvokeAIAppConfig`, which is outside the scope here.
2024-02-29 13:16:36 -05:00
psychedelicious
3fea7a6f00 feat(nodes): context.data -> context._data 2024-02-29 13:16:36 -05:00
psychedelicious
57ae23b222 feat(nodes): context.__services -> context._services 2024-02-29 13:16:36 -05:00
psychedelicious
10a4f1df8a feat(nodes): cache invocation interface config 2024-02-29 13:16:36 -05:00
psychedelicious
0fde0d1ff7 feat(nodes): do not hide services in invocation context interfaces 2024-02-29 13:16:36 -05:00