mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(config): do not discard conf_path
, migrate custom models.yaml
Hold onto `conf_path` temporarily while migrating `invokeai.yaml` so that it gets migrated correctly as the model installer starts up. Stashed as `legacy_models_yaml_path` in the config, excluded from serialization.
This commit is contained in:
parent
415a4baf78
commit
e8b030427d
@ -175,6 +175,11 @@ class InvokeAIAppConfig(BaseSettings):
|
|||||||
hashing_algorithm: HASHING_ALGORITHMS = Field(default="blake3", description="Model hashing algorthim for model installs. 'blake3' is best for SSDs. 'blake3_single' is best for spinning disk HDDs. 'random' disables hashing, instead assigning a UUID to models. Useful when using a memory db to reduce model installation time, or if you don't care about storing stable hashes for models. Alternatively, any other hashlib algorithm is accepted, though these are not nearly as performant as blake3.")
|
hashing_algorithm: HASHING_ALGORITHMS = Field(default="blake3", description="Model hashing algorthim for model installs. 'blake3' is best for SSDs. 'blake3_single' is best for spinning disk HDDs. 'random' disables hashing, instead assigning a UUID to models. Useful when using a memory db to reduce model installation time, or if you don't care about storing stable hashes for models. Alternatively, any other hashlib algorithm is accepted, though these are not nearly as performant as blake3.")
|
||||||
remote_api_tokens: Optional[list[URLRegexTokenPair]] = Field(default=None, description="List of regular expression and token pairs used when downloading models from URLs. The download URL is tested against the regex, and if it matches, the token is provided in as a Bearer token.")
|
remote_api_tokens: Optional[list[URLRegexTokenPair]] = Field(default=None, description="List of regular expression and token pairs used when downloading models from URLs. The download URL is tested against the regex, and if it matches, the token is provided in as a Bearer token.")
|
||||||
|
|
||||||
|
# HIDDEN FIELDS
|
||||||
|
# v4 (MM2) doesn't use `models.yaml` files, but users were able to set paths in the v3 config. When we migrate a
|
||||||
|
# v3 config, we need to save the path to the models.yaml. This is only used during migration.
|
||||||
|
legacy_models_yaml_path: Optional[Path] = Field(default=None, description="The `conf_path` setting from a v3 `invokeai.yaml` file. Only present this app session migrated a config file, and it had `conf_test` on it.", exclude=True)
|
||||||
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
model_config = SettingsConfigDict(env_prefix="INVOKEAI_", env_ignore_empty=True)
|
model_config = SettingsConfigDict(env_prefix="INVOKEAI_", env_ignore_empty=True)
|
||||||
@ -349,7 +354,7 @@ def generate_config_docstrings() -> str:
|
|||||||
|
|
||||||
|
|
||||||
def migrate_v3_config_dict(config_dict: dict[str, Any]) -> InvokeAIAppConfig:
|
def migrate_v3_config_dict(config_dict: dict[str, Any]) -> InvokeAIAppConfig:
|
||||||
"""Migrate a v3 config dictionary to the latest version.
|
"""Migrate a v3 config dictionary to a current config object.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config_dict: A dictionary of settings from a v3 config file.
|
config_dict: A dictionary of settings from a v3 config file.
|
||||||
@ -370,10 +375,14 @@ def migrate_v3_config_dict(config_dict: dict[str, Any]) -> InvokeAIAppConfig:
|
|||||||
# `max_vram_cache_size` was renamed to `vram` some time in v3, but both names were used
|
# `max_vram_cache_size` was renamed to `vram` some time in v3, but both names were used
|
||||||
if k == "max_vram_cache_size" and "vram" not in category_dict:
|
if k == "max_vram_cache_size" and "vram" not in category_dict:
|
||||||
parsed_config_dict["vram"] = v
|
parsed_config_dict["vram"] = v
|
||||||
|
if k == "conf_path":
|
||||||
|
parsed_config_dict["legacy_models_yaml_path"] = v
|
||||||
elif k in InvokeAIAppConfig.model_fields:
|
elif k in InvokeAIAppConfig.model_fields:
|
||||||
# skip unknown fields
|
# skip unknown fields
|
||||||
parsed_config_dict[k] = v
|
parsed_config_dict[k] = v
|
||||||
return InvokeAIAppConfig.model_validate(parsed_config_dict)
|
config = InvokeAIAppConfig.model_validate(parsed_config_dict)
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def load_and_migrate_config(config_path: Path) -> InvokeAIAppConfig:
|
def load_and_migrate_config(config_path: Path) -> InvokeAIAppConfig:
|
||||||
|
@ -287,12 +287,17 @@ class ModelInstallService(ModelInstallServiceBase):
|
|||||||
|
|
||||||
def _migrate_yaml(self) -> None:
|
def _migrate_yaml(self) -> None:
|
||||||
db_models = self.record_store.all_models()
|
db_models = self.record_store.all_models()
|
||||||
legacy_models_yaml_path = self._app_config.root_path / "configs" / "models.yaml"
|
|
||||||
try:
|
legacy_models_yaml_path = (
|
||||||
legacy_models_yaml = yaml.safe_load(legacy_models_yaml_path.read_text())
|
self._app_config.legacy_models_yaml_path or self._app_config.root_path / "configs" / "models.yaml"
|
||||||
except OSError:
|
)
|
||||||
|
|
||||||
|
if not legacy_models_yaml_path.exists():
|
||||||
|
# No yaml to migrate
|
||||||
return
|
return
|
||||||
|
|
||||||
|
legacy_models_yaml = yaml.safe_load(legacy_models_yaml_path.read_text())
|
||||||
|
|
||||||
yaml_metadata = legacy_models_yaml.pop("__metadata__")
|
yaml_metadata = legacy_models_yaml.pop("__metadata__")
|
||||||
yaml_version = yaml_metadata.get("version")
|
yaml_version = yaml_metadata.get("version")
|
||||||
|
|
||||||
@ -302,7 +307,7 @@ class ModelInstallService(ModelInstallServiceBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self._logger.info(
|
self._logger.info(
|
||||||
f"Starting one-time migration of {len(legacy_models_yaml.items())} models from `models.yaml` to database. This may take a few minutes."
|
f"Starting one-time migration of {len(legacy_models_yaml.items())} models from {str(legacy_models_yaml_path)}. This may take a few minutes."
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(db_models) == 0 and len(legacy_models_yaml.items()) != 0:
|
if len(db_models) == 0 and len(legacy_models_yaml.items()) != 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user