feat(app): add setting to allow unknown models

This commit is contained in:
psychedelicious
2025-09-18 18:54:00 +10:00
parent c9dd1159a8
commit 57787e3dcf
2 changed files with 11 additions and 4 deletions

View File

@@ -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

View File

@@ -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: