Skip to content

Commit bacdf98

Browse files
committed
doc(model_manager): docstrings
1 parent e351905 commit bacdf98

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

invokeai/backend/model_management/model_manager.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ def sync_to_config(self):
385385
def model_exists(self, model_name: str, base_model: BaseModelType, model_type: ModelType, *, rescan=False) -> bool:
386386
"""
387387
Given a model name, returns True if it is a valid identifier.
388+
389+
:param model_name: symbolic name of the model in models.yaml
390+
:param model_type: ModelType enum indicating the type of model to return
391+
:param base_model: BaseModelType enum indicating the base model used by this model
392+
:param rescan: if True, scan_models_directory
388393
"""
389394
model_key = self.create_key(model_name, base_model, model_type)
390395
exists = model_key in self.models
@@ -470,7 +475,7 @@ def get_model(
470475

471476
else:
472477
self.models.pop(model_key, None)
473-
raise ModelNotFoundException(f"Model not found - {model_key}")
478+
raise ModelNotFoundException(f'Files for model "{model_key}" not found at {model_path}')
474479

475480
# TODO: path
476481
# TODO: is it accurate to use path as id
@@ -508,7 +513,13 @@ def get_model(
508513
_cache=self.cache,
509514
)
510515

511-
def _get_model_path(self, model_config: ModelConfigBase, submodel_type: SubModelType = None) -> (Path, bool):
516+
def _get_model_path(
517+
self, model_config: ModelConfigBase, submodel_type: Optional[SubModelType] = None
518+
) -> (Path, bool):
519+
"""Extract a model's filesystem path from its config.
520+
521+
:return: The fully qualified Path of the module (or submodule).
522+
"""
512523
model_path = model_config.path
513524
is_submodel_override = False
514525

@@ -523,6 +534,7 @@ def _get_model_path(self, model_config: ModelConfigBase, submodel_type: SubModel
523534
return model_path, is_submodel_override
524535

525536
def _get_model_config(self, base_model, model_name, model_type) -> ModelConfigBase:
537+
"""Get a model's config object."""
526538
model_key = self.create_key(model_name, base_model, model_type)
527539
try:
528540
model_config = self.models[model_key]
@@ -531,12 +543,18 @@ def _get_model_config(self, base_model, model_name, model_type) -> ModelConfigBa
531543
return model_config
532544

533545
def _get_implementation(self, base_model: BaseModelType, model_type: ModelType) -> type[ModelBase]:
546+
"""Get the concrete implementation class for a specific model type."""
534547
model_class = MODEL_CLASSES[base_model][model_type]
535548
return model_class
536549

537550
def _instantiate(
538-
self, model_name: str, base_model: BaseModelType, model_type: ModelType, submodel_type: SubModelType = None
551+
self,
552+
model_name: str,
553+
base_model: BaseModelType,
554+
model_type: ModelType,
555+
submodel_type: Optional[SubModelType] = None,
539556
) -> ModelBase:
557+
"""Make a new instance of this model, without loading it."""
540558
model_config = self._get_model_config(base_model, model_name, model_type)
541559
model_path, is_submodel_override = self._get_model_path(model_config, submodel_type)
542560
# FIXME: do non-overriden submodels get the right class?

invokeai/backend/model_management/models/vae.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import os
2-
import torch
3-
import safetensors
42
from enum import Enum
53
from pathlib import Path
6-
from typing import Optional, Union, Literal
4+
from typing import Optional
5+
6+
import safetensors
7+
import torch
8+
from diffusers.utils import is_safetensors_available
9+
from omegaconf import OmegaConf
10+
11+
from invokeai.app.services.config import InvokeAIAppConfig
712
from .base import (
813
ModelBase,
914
ModelConfigBase,
@@ -18,9 +23,6 @@
1823
InvalidModelException,
1924
ModelNotFoundException,
2025
)
21-
from invokeai.app.services.config import InvokeAIAppConfig
22-
from diffusers.utils import is_safetensors_available
23-
from omegaconf import OmegaConf
2426

2527

2628
class VaeModelFormat(str, Enum):
@@ -80,7 +82,7 @@ def save_to_config(cls) -> bool:
8082
@classmethod
8183
def detect_format(cls, path: str):
8284
if not os.path.exists(path):
83-
raise ModelNotFoundException()
85+
raise ModelNotFoundException(f"Does not exist as local file: {path}")
8486

8587
if os.path.isdir(path):
8688
if os.path.exists(os.path.join(path, "config.json")):

0 commit comments

Comments
 (0)