move incorrectly placed models into correct directory at startup time

This commit is contained in:
Lincoln Stein
2023-09-19 01:18:03 -04:00
parent 73bc088fa7
commit de666fd7bc
2 changed files with 6 additions and 2 deletions

View File

@ -8,7 +8,7 @@ from invokeai.app.services.config import InvokeAIAppConfig
def check_invokeai_root(config: InvokeAIAppConfig):
try:
assert config.model_conf_path.exists(), f"{config.model_conf_path} not found"
assert config.model_conf_path.parent.exists(), f"{config.model_conf_path.parent} not found"
assert config.db_path.parent.exists(), f"{config.db_path.parent} not found"
assert config.models_path.exists(), f"{config.models_path} not found"
if not config.ignore_missing_core_models:

View File

@ -529,6 +529,9 @@ class ModelInstall(ModelInstallBase):
return old_path
new_path = models_dir / model.base_model.value / model.model_type.value / model.name
self._logger.info(
f"{old_path.name} is not in the right directory for a model of its type. Moving to {new_path}."
)
model.path = self._move_model(old_path, new_path).as_posix()
self._store.update_model(key, model)
return model
@ -652,7 +655,8 @@ class ModelInstall(ModelInstallBase):
def _scan_register(self, model: Path) -> bool:
try:
id = self.register_path(model)
self._logger.info(f"Registered {model} with id {id}")
self.sync_model_path(id) # possibly move it to right place in `models`
self._logger.info(f"Registered {model.name} with id {id}")
self._installed.add(id)
except DuplicateModelException:
pass