From 3ec5ce941626c3c5ff4aac884c926ceb4ba60d37 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Tue, 22 Aug 2023 19:05:03 +0300 Subject: [PATCH] add type annotations for extra fields of shared.sd_model --- modules/sd_models_types.py | 31 +++++++++++++++++++++++++++++++ modules/shared.py | 5 ++--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 modules/sd_models_types.py diff --git a/modules/sd_models_types.py b/modules/sd_models_types.py new file mode 100644 index 00000000..5ffd2f4f --- /dev/null +++ b/modules/sd_models_types.py @@ -0,0 +1,31 @@ +from ldm.models.diffusion.ddpm import LatentDiffusion +from typing import TYPE_CHECKING + + +if TYPE_CHECKING: + from modules.sd_models import CheckpointInfo + + +class WebuiSdModel(LatentDiffusion): + """This class is not actually instantinated, but its fields are created and fieeld by webui""" + + lowvram: bool + """True if lowvram/medvram optimizations are enabled -- see modules.lowvram for more info""" + + sd_model_hash: str + """short hash, 10 first characters of SHA1 hash of the model file; may be None if --no-hashing flag is used""" + + sd_model_checkpoint: str + """path to the file on disk that model weights were obtained from""" + + sd_checkpoint_info: 'CheckpointInfo' + """structure with additional information about the file with model's weights""" + + is_sdxl: bool + """True if the model's architecture is SDXL""" + + is_sd2: bool + """True if the model's architecture is SD 2.x""" + + is_sd1: bool + """True if the model's architecture is SD 1.x""" diff --git a/modules/shared.py b/modules/shared.py index f321159d..63661939 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -2,9 +2,8 @@ import sys import gradio as gr -from modules import shared_cmd_options, shared_gradio_themes, options, shared_items +from modules import shared_cmd_options, shared_gradio_themes, options, shared_items, sd_models_types from modules.paths_internal import models_path, script_path, data_path, sd_configs_path, sd_default_config, sd_model_file, default_sd_model_file, extensions_dir, extensions_builtin_dir # noqa: F401 -from ldm.models.diffusion.ddpm import LatentDiffusion from modules import util cmd_opts = shared_cmd_options.cmd_opts @@ -40,7 +39,7 @@ options_templates = None opts = None restricted_opts = None -sd_model: LatentDiffusion = None +sd_model: sd_models_types.WebuiSdModel = None settings_components = None """assinged from ui.py, a mapping on setting names to gradio components repsponsible for those settings"""