diff --git a/invokeai/app/services/model_install/__init__.py b/invokeai/app/services/model_install/__init__.py index 79cd748243..00a33c203e 100644 --- a/invokeai/app/services/model_install/__init__.py +++ b/invokeai/app/services/model_install/__init__.py @@ -7,7 +7,6 @@ from .model_install_base import ( ModelInstallJob, ModelInstallServiceBase, ModelSource, - ModelSourceValidator, UnknownInstallJobException, URLModelSource, ) @@ -20,7 +19,6 @@ __all__ = [ "ModelInstallJob", "UnknownInstallJobException", "ModelSource", - "ModelSourceValidator", "LocalModelSource", "HFModelSource", "URLModelSource", diff --git a/invokeai/app/services/model_install/model_install_base.py b/invokeai/app/services/model_install/model_install_base.py index 3a796bb5da..c2c11341df 100644 --- a/invokeai/app/services/model_install/model_install_base.py +++ b/invokeai/app/services/model_install/model_install_base.py @@ -123,8 +123,6 @@ class URLModelSource(StringLikeSource): # https://github.com/tiangolo/fastapi/discussions/9287 ModelSource = Annotated[Union[LocalModelSource, HFModelSource, URLModelSource], Body(discriminator="type")] -ModelSourceValidator = TypeAdapter(ModelSource) - class ModelInstallJob(BaseModel): """Object that tracks the current status of an install request.""" @@ -147,7 +145,7 @@ class ModelInstallJob(BaseModel): def set_error(self, e: Exception) -> None: """Record the error and traceback from an exception.""" self.error_type = e.__class__.__name__ - self.error = traceback.format_exc() + self.error = "".join(traceback.format_exception(e)) self.status = InstallStatus.ERROR @@ -173,6 +171,10 @@ class ModelInstallServiceBase(ABC): """Call at InvokeAI startup time.""" self.sync_to_config() + @abstractmethod + def stop(self) -> None: + """Stop the model install service. After this the objection can be safely deleted.""" + @property @abstractmethod def app_config(self) -> InvokeAIAppConfig: diff --git a/invokeai/app/services/model_install/model_install_default.py b/invokeai/app/services/model_install/model_install_default.py index fa32c3a491..9022fc100c 100644 --- a/invokeai/app/services/model_install/model_install_default.py +++ b/invokeai/app/services/model_install/model_install_default.py @@ -73,10 +73,6 @@ class ModelInstallService(ModelInstallServiceBase): self._models_installed = set() self._start_installer_thread() - def __del__(self) -> None: - """At GC time, we stop the install thread and release its resources.""" - self._install_queue.put(STOP_JOB) - @property def app_config(self) -> InvokeAIAppConfig: # noqa D102 return self._app_config @@ -89,6 +85,10 @@ class ModelInstallService(ModelInstallServiceBase): def event_bus(self) -> Optional[EventServiceBase]: # noqa D102 return self._event_bus + def stop(self) -> None: + """Stop the install thread; after this the object can be deleted and garbage collected.""" + self._install_queue.put(STOP_JOB) + def _start_installer_thread(self) -> None: threading.Thread(target=self._install_next_item, daemon=True).start() @@ -114,6 +114,7 @@ class ModelInstallService(ModelInstallServiceBase): self._signal_job_errored(job, excp) finally: self._install_queue.task_done() + self._logger.info("Install thread exiting") def _signal_job_running(self, job: ModelInstallJob) -> None: job.status = InstallStatus.RUNNING diff --git a/invokeai/backend/model_manager/probe.py b/invokeai/backend/model_manager/probe.py index b5f9227af2..7cade3cada 100644 --- a/invokeai/backend/model_manager/probe.py +++ b/invokeai/backend/model_manager/probe.py @@ -425,7 +425,7 @@ class TextualInversionCheckpointProbe(CheckpointProbeBase): elif token_dim == 1280: return BaseModelType.StableDiffusionXL else: - raise InvalidModelConfigException("Could not determine base type") + raise InvalidModelConfigException(f"{self.model_path}: Could not determine base type") class ControlNetCheckpointProbe(CheckpointProbeBase): @@ -443,7 +443,7 @@ class ControlNetCheckpointProbe(CheckpointProbeBase): return BaseModelType.StableDiffusion1 elif checkpoint[key_name].shape[-1] == 1024: return BaseModelType.StableDiffusion2 - raise InvalidModelConfigException("Unable to determine base type for {self.checkpoint_path}") + raise InvalidModelConfigException("{self.model_path}: Unable to determine base type") class IPAdapterCheckpointProbe(CheckpointProbeBase):