Skip to content

Commit c87cad3

Browse files
author
Lincoln Stein
committed
simplified config schema migration code
1 parent 1109708 commit c87cad3

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

invokeai/app/services/config/config_default.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from __future__ import annotations
55

6+
import copy
67
import locale
78
import os
89
import re
@@ -84,7 +85,7 @@ class InvokeAIAppConfig(BaseSettings):
8485
log_tokenization: Enable logging of parsed prompt tokens.
8586
patchmatch: Enable patchmatch inpaint code.
8687
models_dir: Path to the models directory.
87-
convert_cache_dir: Path to the converted models cache directory (DEPRECATED).
88+
convert_cache_dir: Path to the converted models cache directory (DEPRECATED, but do not delete because it is needed for migration from previous versions).
8889
download_cache_dir: Path to the directory that contains dynamically downloaded models.
8990
legacy_conf_dir: Path to directory of legacy checkpoint config files.
9091
db_dir: Path to InvokeAI databases directory.
@@ -145,7 +146,7 @@ class InvokeAIAppConfig(BaseSettings):
145146

146147
# PATHS
147148
models_dir: Path = Field(default=Path("models"), description="Path to the models directory.")
148-
convert_cache_dir: Path = Field(default=Path("models/.convert_cache"), description="Path to the converted models cache directory (DEPRECATED).")
149+
convert_cache_dir: Path = Field(default=Path("models/.convert_cache"), description="Path to the converted models cache directory (DEPRECATED, but do not delete because it is needed for migration from previous versions).")
149150
download_cache_dir: Path = Field(default=Path("models/.download_cache"), description="Path to the directory that contains dynamically downloaded models.")
150151
legacy_conf_dir: Path = Field(default=Path("configs"), description="Path to directory of legacy checkpoint config files.")
151152
db_dir: Path = Field(default=Path("databases"), description="Path to InvokeAI databases directory.")
@@ -406,15 +407,11 @@ def migrate_v4_0_0_to_4_0_1_config_dict(config_dict: dict[str, Any]) -> dict[str
406407
Returns:
407408
A config dict with the settings migrated to v4.0.1.
408409
"""
409-
parsed_config_dict: dict[str, Any] = {}
410-
for k, v in config_dict.items():
411-
# autocast was removed from precision in v4.0.1
412-
if k == "precision" and v == "autocast":
413-
parsed_config_dict["precision"] = "auto"
414-
else:
415-
parsed_config_dict[k] = v
416-
if k == "schema_version":
417-
parsed_config_dict[k] = "4.0.1"
410+
parsed_config_dict: dict[str, Any] = copy.deepcopy(config_dict)
411+
# precision "autocast" was replaced by "auto" in v4.0.1
412+
if parsed_config_dict.get("precision") == "autocast":
413+
parsed_config_dict["precision"] = "auto"
414+
parsed_config_dict["schema_version"] = "4.0.1"
418415
return parsed_config_dict
419416

420417

@@ -427,15 +424,10 @@ def migrate_v4_0_1_to_4_0_2_config_dict(config_dict: dict[str, Any]) -> dict[str
427424
Returns:
428425
An config dict with the settings migrated to v4.0.2.
429426
"""
430-
parsed_config_dict: dict[str, Any] = {}
431-
for k, v in config_dict.items():
432-
# autocast was removed from precision in v4.0.1
433-
if k == "convert_cache":
434-
continue
435-
else:
436-
parsed_config_dict[k] = v
437-
if k == "schema_version":
438-
parsed_config_dict[k] = "4.0.2"
427+
parsed_config_dict: dict[str, Any] = copy.deepcopy(config_dict)
428+
# convert_cache was removed in 4.0.2
429+
parsed_config_dict.pop("convert_cache", None)
430+
parsed_config_dict["schema_version"] = "4.0.2"
439431
return parsed_config_dict
440432

441433

0 commit comments

Comments
 (0)