From 5f7435955e767b9c4f35f4c38f3c52563387f51b Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sat, 8 Jul 2023 15:13:51 -0400 Subject: [PATCH] if models.yaml doesn't exist, rebuild it --- invokeai/app/services/model_manager_service.py | 4 +--- invokeai/backend/model_management/model_manager.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/invokeai/app/services/model_manager_service.py b/invokeai/app/services/model_manager_service.py index 63c13f3460..1b1c43dc11 100644 --- a/invokeai/app/services/model_manager_service.py +++ b/invokeai/app/services/model_manager_service.py @@ -258,9 +258,7 @@ class ModelManagerService(ModelManagerServiceBase): config_file = config.model_conf_path else: config_file = config.root_dir / "configs/models.yaml" - if not config_file.exists(): - raise IOError(f"The file {config_file} could not be found.") - + logger.debug(f'config file={config_file}') device = torch.device(choose_torch_device()) diff --git a/invokeai/backend/model_management/model_manager.py b/invokeai/backend/model_management/model_manager.py index e5c11d2fdd..686c980ab2 100644 --- a/invokeai/backend/model_management/model_manager.py +++ b/invokeai/backend/model_management/model_manager.py @@ -231,6 +231,7 @@ from __future__ import annotations import os import hashlib import textwrap +import yaml from dataclasses import dataclass from pathlib import Path from typing import Optional, List, Tuple, Union, Dict, Set, Callable, types @@ -314,6 +315,9 @@ class ModelManager(object): self.config_path = None if isinstance(config, (str, Path)): self.config_path = Path(config) + if not self.config_path.exists(): + logger.warning(f'The file {self.config_path} was not found. Initializing a new file') + self.initialize_model_config(self.config_path) config = OmegaConf.load(self.config_path) elif not isinstance(config, DictConfig): @@ -386,6 +390,16 @@ class ModelManager(object): def _get_model_cache_path(self, model_path): return self.app_config.models_path / ".cache" / hashlib.md5(str(model_path).encode()).hexdigest() + @classmethod + def initialize_model_config(cls, config_path: Path): + """Create empty config file""" + with open(config_path,'w') as yaml_file: + yaml_file.write(yaml.dump({'__metadata__': + {'version':'3.0.0'} + } + ) + ) + def get_model( self, model_name: str,