From 505f36df8707ee0b2faa12799bc1477d0e4a2e7a Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Thu, 19 Oct 2023 09:36:10 -0400 Subject: [PATCH] multiple fixes --- CHANGELOG.md | 9 +++++++-- installer.py | 1 + launch.py | 2 +- modules/cmd_args.py | 2 +- modules/loader.py | 10 +++++++--- modules/processing.py | 10 +++++++--- modules/sd_models.py | 8 ++++++++ modules/sd_vae_approx.py | 35 ++++++++++++++++------------------- requirements.txt | 2 +- 9 files changed, 49 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f329bbaea..75ac65794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,13 @@ Service release addressing all zero-day issues reported so far... - fix loading diffuser models in huggingface format from non-standard location - fix default styles looking in wrong location - fix missing upscaler folder on initial startup -- complete lyco removal -- enhance extension compatibility for exensions directly importing codeformers +- fix handling of relative path for models +- fix simple live preview device mismatch +- fix batch img2img +- force second requirements check on startup +- remove lyco, multiple_tqdm +- enhance extension compatibility for exensions directly importing codeformers +- enhance extension compatibility for exensions directly accessing processing params - update `typing-extensions` **Themes** diff --git a/installer.py b/installer.py index 71ac51a28..e93ae9b01 100644 --- a/installer.py +++ b/installer.py @@ -786,6 +786,7 @@ def set_environment(): os.environ.setdefault('HF_HUB_DISABLE_EXPERIMENTAL_WARNING', '1') os.environ.setdefault('UVICORN_TIMEOUT_KEEP_ALIVE', '60') os.environ.setdefault('K_DIFFUSION_USE_COMPILE', '0') + os.environ.setdefault('TF_ENABLE_ONEDNN_OPTS', '0') if sys.platform == 'darwin': os.environ.setdefault('PYTORCH_ENABLE_MPS_FALLBACK', '1') diff --git a/launch.py b/launch.py index d5fe9a7d1..b725961f9 100644 --- a/launch.py +++ b/launch.py @@ -199,7 +199,7 @@ if __name__ == "__main__": installer.install_repositories() installer.install_submodules() installer.install_extensions() - installer.install_packages() # redo packages since extensions may change them + installer.install_requirements() # redo requirements since extensions may change them installer.update_wiki() if installer.errors == 0: installer.log.debug(f'Setup complete without errors: {round(time.time())}') diff --git a/modules/cmd_args.py b/modules/cmd_args.py index 5570bd02a..ef2074f1e 100644 --- a/modules/cmd_args.py +++ b/modules/cmd_args.py @@ -114,7 +114,7 @@ def compatibility_args(opts, args): opts.sd_vae_as_default = True opts.enable_emphasis = True opts.enable_batch_seeds = True - opts.multiple_tqdm = False + # opts.multiple_tqdm = False opts.print_hypernet_extra = False opts.dimensions_and_batch_together = True opts.enable_pnginfo = True diff --git a/modules/loader.py b/modules/loader.py index c0cc8dea3..6353ee1bb 100644 --- a/modules/loader.py +++ b/modules/loader.py @@ -9,7 +9,11 @@ initialized = False logging.getLogger("DeepSpeed").disabled = True # os.environ.setdefault('OMP_NUM_THREADS', 1) # os.environ.setdefault('MKL_NUM_THREADS', 1) + +# import tensorflow as tf # pylint: disable=C0411 + import torch # pylint: disable=C0411 + # torch.set_num_threads(1) try: import intel_extension_for_pytorch as ipex # pylint: disable=import-error, unused-import @@ -19,14 +23,14 @@ except Exception: urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) import torchvision # pylint: disable=W0611,C0411 import pytorch_lightning # pytorch_lightning should be imported after torch, but it re-enables warnings on import so import once to disable them # pylint: disable=W0611,C0411 -if ".dev" in torch.__version__ or "+git" in torch.__version__: - torch.__long_version__ = torch.__version__ - torch.__version__ = re.search(r'[\d.]+[\d]', torch.__version__).group(0) logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage()) logging.getLogger("pytorch_lightning").disabled = True warnings.filterwarnings(action="ignore", category=DeprecationWarning) warnings.filterwarnings(action="ignore", category=FutureWarning) warnings.filterwarnings(action="ignore", category=UserWarning, module="torchvision") +if ".dev" in torch.__version__ or "+git" in torch.__version__: + torch.__long_version__ = torch.__version__ + torch.__version__ = re.search(r'[\d.]+[\d]', torch.__version__).group(0) timer.startup.record("torch") from fastapi import FastAPI # pylint: disable=W0611,C0411 diff --git a/modules/processing.py b/modules/processing.py index aa0bfafc8..2c6deb0b1 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -163,6 +163,7 @@ class StableDiffusionProcessing: self.refiner_steps = 5 self.refiner_start = 0 self.ops = [] + self.resize_mode: int = 0 self.ddim_discretize = shared.opts.ddim_discretize self.s_min_uncond = shared.opts.s_min_uncond self.s_churn = shared.opts.s_churn @@ -172,9 +173,10 @@ class StableDiffusionProcessing: self.s_tmin = shared.opts.s_tmin self.s_tmax = float('inf') # not representable as a standard ui option self.refiner_switch_at = 0 # a1111 compatibility item - self.comments = {} - self.is_api = False - self.resize_mode: int = 0 + self.all_hr_prompts = [] # a1111 compatibility item + self.hr_prompt = '' # a1111 compatibility item + self.comments = {} # a1111 compatibility item + self.is_api = False # a1111 compatibility item shared.opts.data['clip_skip'] = clip_skip @property @@ -1180,6 +1182,8 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing): crop_region = None image_mask = self.image_mask if image_mask is not None: + if type(image_mask) == list: + image_mask = image_mask[0] image_mask = image_mask.convert('L') if self.inpainting_mask_invert: image_mask = ImageOps.invert(image_mask) diff --git a/modules/sd_models.py b/modules/sd_models.py index d35eb4955..a6ab5656a 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -51,6 +51,7 @@ class CheckpointInfo: self.filename = filename self.type = '' relname = filename + app_path = os.path.abspath(script_path) def rel(fn, path): try: @@ -58,6 +59,8 @@ class CheckpointInfo: except Exception: return fn + if relname.startswith('..'): + relname = os.path.abspath(relname) if relname.startswith(shared.opts.ckpt_dir): relname = rel(filename, shared.opts.ckpt_dir) elif relname.startswith(shared.opts.diffusers_dir): @@ -66,6 +69,8 @@ class CheckpointInfo: relname = rel(filename, model_path) elif relname.startswith(script_path): relname = rel(filename, script_path) + elif relname.startswith(app_path): + relname = rel(filename, app_path) else: relname = os.path.abspath(relname) relname, ext = os.path.splitext(relname) @@ -705,6 +710,9 @@ def compile_diffusers(sd_model): def set_diffuser_options(sd_model, vae, op: str): + if sd_model is None: + shared.log.warning(f'{op} is not loaded') + return if (shared.opts.diffusers_model_cpu_offload or shared.cmd_opts.medvram) and (shared.opts.diffusers_seq_cpu_offload or shared.cmd_opts.lowvram): shared.log.warning(f'Setting {op}: Model CPU offload and Sequential CPU offload are not compatible') shared.log.debug(f'Setting {op}: disabling model CPU offload') diff --git a/modules/sd_vae_approx.py b/modules/sd_vae_approx.py index f5c577458..6c48d977a 100644 --- a/modules/sd_vae_approx.py +++ b/modules/sd_vae_approx.py @@ -5,8 +5,6 @@ from modules import devices, paths, shared sd_vae_approx_model = None -simple_weights = None -simple_bias = None class VAEApprox(nn.Module): @@ -58,24 +56,23 @@ def nn_approximation(sample): # Approximate NN def cheap_approximation(sample): # Approximate simple # https://discuss.huggingface.co/t/decoding-latents-to-rgb-without-upscaling/23204/2 - global simple_weights, simple_bias # pylint: disable=global-statement - if simple_weights is None or simple_bias is None: - if shared.sd_model_type == "sdxl": - simple_weights = torch.tensor([ - [0.4543,-0.2868, 0.1566,-0.4748], - [0.5008, 0.0952, 0.2155,-0.3268], - [0.5294, 0.1625,-0.0624,-0.3793] - ]).reshape(3, 4, 1, 1).to(sample.device) - simple_bias = torch.tensor([0.1375, 0.0144, -0.0675]).to(sample.device) - else: - simple_weights = torch.tensor([ - [0.298, 0.187,-0.158,-0.184], - [0.207, 0.286, 0.189,-0.271], - [0.208, 0.173, 0.264,-0.473], - ]).reshape(3, 4, 1, 1).to(sample.device) - simple_bias = None + if shared.sd_model_type == "sdxl": + simple_weights = torch.tensor([ + [0.4543,-0.2868, 0.1566,-0.4748], + [0.5008, 0.0952, 0.2155,-0.3268], + [0.5294, 0.1625,-0.0624,-0.3793] + ]).reshape(3, 4, 1, 1) + simple_bias = torch.tensor([0.1375, 0.0144, -0.0675]) + else: + simple_weights = torch.tensor([ + [0.298, 0.187,-0.158,-0.184], + [0.207, 0.286, 0.189,-0.271], + [0.208, 0.173, 0.264,-0.473], + ]).reshape(3, 4, 1, 1) + simple_bias = None try: - x_sample = nn.functional.conv2d(sample, simple_weights, simple_bias) # pylint: disable=not-callable + print('HERE', sample.dtype, sample.device) + x_sample = nn.functional.conv2d(sample, simple_weights.to(sample.device, sample.dtype), simple_bias.to(sample.device, sample.dtype)) # pylint: disable=not-callable return x_sample except Exception as e: shared.log.error(f'Decode simple: {e}') diff --git a/requirements.txt b/requirements.txt index 0f716d03e..ffb5dacc3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -43,7 +43,6 @@ fasteners dctorch compel==2.0.2 torchsde==0.2.6 -typing-extensions==4.8.0 antlr4-python3-runtime==4.9.3 requests==2.31.0 tqdm==4.66.1 @@ -65,3 +64,4 @@ urllib3==1.26.15 Pillow==9.5.0 timm==0.9.7 pydantic==1.10.13 +typing-extensions==4.8.0