Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.2 KB
Raw Blame
"""Which registered models have lost their files, by the one rule the Model Manager and the calibration share."""

from collections.abc import Iterable
from pathlib import Path

from invokeai.backend.model_manager.configs.factory import AnyModelConfig
from invokeai.backend.model_manager.taxonomy import BaseModelType, ModelFormat


def is_model_missing(config: AnyModelConfig, models_path: Path) -> bool:
    """Whether the files of a registered model are gone. External providers have none, so they are never missing."""
    if config.base == BaseModelType.External or config.format == ModelFormat.ExternalApi:
        return False
    try:
        return not (models_path / config.path).resolve().exists()
    except (OSError, RuntimeError):
        # An inaccessible directory (PermissionError) or a symlink loop (RuntimeError from resolve() before Python 3.13)
        # makes the files unusable, and must not stop the scan of the other models.
        return True


def find_missing_models(configs: Iterable[AnyModelConfig], models_path: Path) -> list[AnyModelConfig]:
    """The registered models among `configs` whose files are gone, in order."""
    return [config for config in configs if is_model_missing(config, models_path)]