-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Refactor Model Installation
Our current install procedure involves two main scripts:
- A simple script to install python packages for the app
- A more complex configuration script, which installs the models in a TUI (terminal user interface)
The TUI is fairly difficult to maintain, with numerous edge cases related to terminal behavior across different platforms and the amount of content to be displayed in the TUI.
Functionally, it sits in an awkward place between the two typically use-cases:
-Headless installation would rather provide a config file that says exactly which models to install
- "Normal" users would rather use a GUI to do all model installation
A TUI is mostly good enough for either of these, but it's not exactly the right tool for either job.
Revised Installation flow
If we were to redesign the app and model installation flow from the ground up, what might it look like?
App Installation
This is a very simple script. It installs the python packages only.
The UI is launchable after this, though of course it cannot generate at this point, because models are not installed or set up.
App Launch
When the application launches, and the ModelManager is instantiated, it checks if its folder structure is correct. If not, it creates the default folder structure.
It also checks if all the support models are installed, and at least one SD model (?). The UI hits a route (maybe the app info route? or something on models/) that says if we have all the core models set up.
If something is missing, the user is prompted to go to the Model Manager UI to get everything set up.
Model Manager UI
New tabs here replace the TUI. Core model installation status is displayed.
A single button kicks off the core model installation if it hasn't been completed or is missing something.
Here we present recommended models for install. This includes ControlNet models, LoRAs, embeddings, VAEs and main models.
Integrated with models.invoke.ai, and retains the existing functionality to install models from repo IDs, or import from file.
Headless
The app may optionally be provided a model install file:
invokeai --models_from_file models.yaml
If this is received, it is parsed and used to queue up and kick off the model installation. The web API is not fired up until this is complete (?).
Model Services
The current Model Manager service is split up and new services are introduced.
The services are all narrow in scope and fairly low-level. Each has an ABC and light implementations for the OSS application, per our service architecture.
Services Overview
ModelQueueManager: manages the simple model install queue- wraps a python queue library eg Celery
- methods:
add_to_queueremove_from_queueget_statusreorder_queue
ModelTaskHandler: handles all side-effects/actionsModelQueueManagercalls this service to action queue items- methods:
download_modelconfigure_model
ModelStatusTracker: tracks the status of each individual model install, in-memory store- methods:
get_statusupdate_statussend_update(using events service)
- maybe this could be wrapped up in another service?
- methods:
ModelRecordStorage: manages the db for modelsModelFileStorage: manages model filesModelLoader: everything related to actually loading and providing models to the application; i.e. most of what theModelManagerdoes today including the model context manager
Model Install Queue Items
Queue items would look something like this:
model_id: unique identifier for the modelmodel_type:main,controlnet, etcmodel_url: where the model is downloaded fromstatus: status of model installation;queued,downloading,configuring,ready, orerrordownload_progress: float 0 to 100 indicating download progresserror: error if there is anycreated_at: when the item was added to queueupdated_at: last status update of the queue item
Model Install Events
These would include the queue item, or the relevant parts of it, as payload.
model_queuedmodel install added to queuemodel_download_startedmodel_download_progress: emitted once per second (?)model_download_completedmodel_configuring: the model configuration has startedmodel_ready: download & config are complete, model is readymodel_errormodel_removed- model install removed from queue, either user canceled or error
Web API
Routes would be something like this:
install_modelget_install_statusget_install_queuecancel_model_installreorder_install_queue
Summary
This is a pretty chonky refactor, but I think necessary if we want to provide a robust model system with a good user experience.
Feels like any improvements we want to make to the current system are actually steps towards something like this proposal.
We may as well just implement it properly as services, rather than stuff it all into the ever-growing model manager service. Makes it way easier to reason about, test and debug.
The individual services are all narrow and easy to tackle one at at time, and none of them is trying to do anything complex. I suspect splitting up the model manager will be the hardest part.