cddb07a176
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from transformers import CLIPVisionModelWithProjection
|
|
|
|
from invokeai.backend.model_manager.configs.base import Diffusers_Config_Base
|
|
from invokeai.backend.model_manager.configs.factory import AnyModelConfig
|
|
from invokeai.backend.model_manager.load.load_default import ModelLoader
|
|
from invokeai.backend.model_manager.load.model_loader_registry import ModelLoaderRegistry
|
|
from invokeai.backend.model_manager.taxonomy import AnyModel, BaseModelType, ModelFormat, ModelType, SubModelType
|
|
|
|
|
|
@ModelLoaderRegistry.register(base=BaseModelType.Any, type=ModelType.CLIPVision, format=ModelFormat.Diffusers)
|
|
class ClipVisionLoader(ModelLoader):
|
|
"""Class to load CLIPVision models."""
|
|
|
|
def _load_model(
|
|
self,
|
|
config: AnyModelConfig,
|
|
submodel_type: Optional[SubModelType] = None,
|
|
) -> AnyModel:
|
|
if not isinstance(config, Diffusers_Config_Base):
|
|
raise ValueError("Only DiffusersConfigBase models are currently supported here.")
|
|
|
|
if submodel_type is not None:
|
|
raise Exception("There are no submodels in CLIP Vision models.")
|
|
|
|
model_path = Path(config.path)
|
|
|
|
model = CLIPVisionModelWithProjection.from_pretrained(
|
|
model_path, torch_dtype=self._torch_dtype, local_files_only=True
|
|
)
|
|
assert isinstance(model, CLIPVisionModelWithProjection)
|
|
|
|
return model
|