From 00e85bcd6747aebeaf187e9adf37ab1f58db7b6b Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sat, 7 Oct 2023 14:00:38 -0400 Subject: [PATCH] make autoimport directory optional, defaulting to inactive --- docs/features/CONFIGURATION.md | 7 ++----- invokeai/app/services/config/invokeai_config.py | 11 +++++++---- invokeai/app/services/model_install_service.py | 3 +++ invokeai/backend/install/invokeai_configure.py | 6 ++++-- invokeai/backend/model_manager/install.py | 4 ++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/docs/features/CONFIGURATION.md b/docs/features/CONFIGURATION.md index 98c8dbb84c..d249e5331e 100644 --- a/docs/features/CONFIGURATION.md +++ b/docs/features/CONFIGURATION.md @@ -207,11 +207,8 @@ if INVOKEAI_ROOT is `/home/fred/invokeai` and the path is | Setting | Default Value | Description | |----------|----------------|--------------| -| `autoimport_dir` | `autoimport/main` | At startup time, read and import any main model files found in this directory | -| `lora_dir` | `autoimport/lora` | At startup time, read and import any LoRA/LyCORIS models found in this directory | -| `embedding_dir` | `autoimport/embedding` | At startup time, read and import any textual inversion (embedding) models found in this directory | -| `controlnet_dir` | `autoimport/controlnet` | At startup time, read and import any ControlNet models found in this directory | -| `conf_path` | `configs/models.yaml` | Location of the `models.yaml` model configuration file | +| `autoimport_dir` | `autoimport/main` | At startup time, read and import any main model files found in this directory (not recommended)| +| `model_config_db` | `auto` | Location of the model configuration database. Specify `auto` to use the main invokeai.db database, or specify a `.yaml` or `.db` file to store the data externally.| | `models_dir` | `models` | Location of the directory containing models installed by InvokeAI's model manager | | `legacy_conf_dir` | `configs/stable-diffusion` | Location of the directory containing the .yaml configuration files for legacy checkpoint models | | `db_dir` | `databases` | Location of the directory containing InvokeAI's image, schema and session database | diff --git a/invokeai/app/services/config/invokeai_config.py b/invokeai/app/services/config/invokeai_config.py index 854b76483c..d53b841ce9 100644 --- a/invokeai/app/services/config/invokeai_config.py +++ b/invokeai/app/services/config/invokeai_config.py @@ -219,10 +219,7 @@ class InvokeAIAppConfig(InvokeAISettings): # PATHS root : Path = Field(default=None, description='InvokeAI runtime root directory', category='Paths') - autoimport_dir : Path = Field(default='autoimport', description='Path to a directory of models files to be imported on startup.', category='Paths') - lora_dir : Path = Field(default=None, description='Path to a directory of LoRA/LyCORIS models to be imported on startup.', category='Paths') - embedding_dir : Path = Field(default=None, description='Path to a directory of Textual Inversion embeddings to be imported on startup.', category='Paths') - controlnet_dir : Path = Field(default=None, description='Path to a directory of ControlNet embeddings to be imported on startup.', category='Paths') + autoimport_dir : Optional[Path] = Field(default=None, description='Path to a directory of models files to be imported on startup.', category='Paths') model_config_db : Union[Path, Literal['auto'], None] = Field(default=None, description='Path to a sqlite .db file or .yaml file for storing model config records; "auto" will reuse the main sqlite db', category='Paths') models_dir : Path = Field(default='models', description='Path to the models directory', category='Paths') legacy_conf_dir : Path = Field(default='configs/stable-diffusion', description='Path to directory of legacy checkpoint config files', category='Paths') @@ -274,6 +271,9 @@ class InvokeAIAppConfig(InvokeAISettings): xformers_enabled : bool = Field(default=True, description="Enable/disable memory-efficient attention", category='Memory/Performance') tiled_decode : bool = Field(default=False, description="Whether to enable tiled VAE decode (reduces memory consumption with some performance penalty)", category='Memory/Performance') conf_path : Path = Field(default='configs/models.yaml', description='Path to models definition file', category='Paths') + lora_dir : Path = Field(default=None, description='Path to a directory of LoRA/LyCORIS models to be imported on startup.', category='Paths') + embedding_dir : Path = Field(default=None, description='Path to a directory of Textual Inversion embeddings to be imported on startup.', category='Paths') + controlnet_dir : Path = Field(default=None, description='Path to a directory of ControlNet embeddings to be imported on startup.', category='Paths') # See InvokeAIAppConfig subclass below for CACHE and DEVICE categories # fmt: on @@ -340,6 +340,9 @@ class InvokeAIAppConfig(InvokeAISettings): "xformers_enabled", "tiled_decode", "conf_path", + "lora_dir", + "embedding_dir", + "controlnet_dir", ] ) return el diff --git a/invokeai/app/services/model_install_service.py b/invokeai/app/services/model_install_service.py index d5d07beee4..b6f4b543c7 100644 --- a/invokeai/app/services/model_install_service.py +++ b/invokeai/app/services/model_install_service.py @@ -178,6 +178,9 @@ class ModelInstallService(ModelInstall, ModelInstallServiceBase): def start(self, invoker: Any): # Because .processor is giving circular import errors, declaring invoker an 'Any' """Call automatically at process start.""" self.scan_models_directory() # synchronize new/deleted models found in models directory + if autoimport := self._app_config.autoimport_dir: + self._logger.info("Scanning autoimport directory for new models") + self.scan_directory(self._app_config.root_path / autoimport) def install_model( self, diff --git a/invokeai/backend/install/invokeai_configure.py b/invokeai/backend/install/invokeai_configure.py index 62777e830d..4e15a023ff 100755 --- a/invokeai/backend/install/invokeai_configure.py +++ b/invokeai/backend/install/invokeai_configure.py @@ -587,8 +587,8 @@ Use cursor arrows to make a checkbox selection, and space to toggle. self.autoimport_dirs = {} self.autoimport_dirs["autoimport_dir"] = self.add_widget_intelligent( FileBox, - name="Folder to recursively scan for new checkpoints, ControlNets, LoRAs and TI models", - value=str(config.root_path / config.autoimport_dir), + name="Optional folder to scan for new checkpoints, ControlNets, LoRAs and TI models", + value=str(config.root_path / config.autoimport_dir) if config.autoimport_dir else "", select_dir=True, must_exist=False, use_two_lines=False, @@ -678,6 +678,8 @@ https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/LICENS setattr(new_opts, attr, getattr(self, attr).value) for attr in self.autoimport_dirs: + if not self.autoimport_dirs[attr].value: + continue directory = Path(self.autoimport_dirs[attr].value) if directory.is_relative_to(config.root_path): directory = directory.relative_to(config.root_path) diff --git a/invokeai/backend/model_manager/install.py b/invokeai/backend/model_manager/install.py index 3cc610bd1a..a8569b8544 100644 --- a/invokeai/backend/model_manager/install.py +++ b/invokeai/backend/model_manager/install.py @@ -764,11 +764,11 @@ class ModelInstall(ModelInstallBase): installed = set() with Chdir(self._app_config.models_path): - self._logger.info("Checking for models that have been moved or deleted from disk.") + self._logger.info("Checking for models that have been moved or deleted from disk") for model_config in self._store.all_models(): path = Path(model_config.path) if not path.exists(): - self._logger.info(f"{model_config.name}: path {path.as_posix()} no longer exists. Unregistering.") + self._logger.info(f"{model_config.name}: path {path.as_posix()} no longer exists. Unregistering") defunct_models.add(model_config.key) for key in defunct_models: self.unregister(key)