Skip to content

Commit 57787e3

Browse files
feat(app): add setting to allow unknown models
1 parent c9dd115 commit 57787e3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

invokeai/app/services/config/config_default.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class InvokeAIAppConfig(BaseSettings):
198198
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.")
199199
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.")
200200
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.")
201+
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.")
201202

202203
# fmt: on
203204

invokeai/backend/model_manager/config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag, TypeAdapter
3434
from typing_extensions import Annotated, Any, Dict
3535

36+
from invokeai.app.services.config.config_default import get_config
3637
from invokeai.app.util.misc import uuid_string
3738
from invokeai.backend.model_hash.hash_validator import validate_hash
3839
from invokeai.backend.model_hash.model_hash import HASHING_ALGORITHMS
@@ -55,6 +56,7 @@
5556
from invokeai.backend.stable_diffusion.schedulers.schedulers import SCHEDULER_NAME_VALUES
5657

5758
logger = logging.getLogger(__name__)
59+
app_config = get_config()
5860

5961

6062
class InvalidModelConfigException(Exception):
@@ -207,10 +209,14 @@ def classify(
207209
else:
208210
return config_cls.from_model_on_disk(mod, **overrides)
209211

210-
try:
211-
return UnknownModelConfig.from_model_on_disk(mod, **overrides)
212-
except Exception:
213-
raise InvalidModelConfigException("Unable to determine model type")
212+
if app_config.allow_unknown_models:
213+
try:
214+
return UnknownModelConfig.from_model_on_disk(mod, **overrides)
215+
except Exception:
216+
# Fall through to raising the exception below
217+
pass
218+
219+
raise InvalidModelConfigException("Unable to determine model type")
214220

215221
@classmethod
216222
def get_tag(cls) -> Tag:

0 commit comments

Comments
 (0)