diff --git a/invokeai/app/services/config/config_default.py b/invokeai/app/services/config/config_default.py index 105ce0d227..8dbe95bd45 100644 --- a/invokeai/app/services/config/config_default.py +++ b/invokeai/app/services/config/config_default.py @@ -198,6 +198,7 @@ class InvokeAIAppConfig(BaseSettings): 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.") scan_models_on_startup: bool = Field(default=False, description="Scan the models directory on startup, registering orphaned models. This is typically only used in conjunction with `use_memory_db` for testing purposes.") unsafe_disable_picklescan: bool = Field(default=False, description="UNSAFE. Disable the picklescan security check during model installation. Recommended only for development and testing purposes. This will allow arbitrary code execution during model installation, so should never be used in production.") + allow_unknown_models: bool = Field(default=True, description="Allow installation of models that we are unable to identify. If enabled, models will be marked as `unknown` in the database, and will not have any metadata associated with them. If disabled, unknown models will be rejected during installation.") # fmt: on diff --git a/invokeai/backend/model_manager/config.py b/invokeai/backend/model_manager/config.py index a222fc19f6..b0b46b75ec 100644 --- a/invokeai/backend/model_manager/config.py +++ b/invokeai/backend/model_manager/config.py @@ -33,6 +33,7 @@ from typing import ClassVar, Literal, Optional, Type, TypeAlias, Union from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag, TypeAdapter from typing_extensions import Annotated, Any, Dict +from invokeai.app.services.config.config_default import get_config from invokeai.app.util.misc import uuid_string from invokeai.backend.model_hash.hash_validator import validate_hash from invokeai.backend.model_hash.model_hash import HASHING_ALGORITHMS @@ -55,6 +56,7 @@ from invokeai.backend.model_manager.util.model_util import lora_token_vector_len from invokeai.backend.stable_diffusion.schedulers.schedulers import SCHEDULER_NAME_VALUES logger = logging.getLogger(__name__) +app_config = get_config() class InvalidModelConfigException(Exception): @@ -207,10 +209,14 @@ class ModelConfigBase(ABC, BaseModel): else: return config_cls.from_model_on_disk(mod, **overrides) - try: - return UnknownModelConfig.from_model_on_disk(mod, **overrides) - except Exception: - raise InvalidModelConfigException("Unable to determine model type") + if app_config.allow_unknown_models: + try: + return UnknownModelConfig.from_model_on_disk(mod, **overrides) + except Exception: + # Fall through to raising the exception below + pass + + raise InvalidModelConfigException("Unable to determine model type") @classmethod def get_tag(cls) -> Tag: