From 8aa2d0347c227c8ee5c5729a5951cedb0b9f3c71 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 17 Oct 2023 08:01:33 -0400 Subject: [PATCH] premerge fixes --- extensions-builtin/Lora/networks.py | 17 ++--------------- .../multidiffusion-upscaler-for-automatic1111 | 2 +- installer.py | 2 +- modules/sd_models.py | 7 +++++-- modules/ui_extra_networks.py | 3 ++- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 10f0da215..4edcf986b 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -39,23 +39,10 @@ module_types = [ def assign_network_names_to_compvis_modules(sd_model): - """ - if shared.sd_model.is_sdxl: - for i, embedder in enumerate(shared.sd_model.conditioner.embedders): - if not hasattr(embedder, 'wrapped'): - continue - for name, module in embedder.wrapped.named_modules(): - network_name = f'{i}_{name.replace(".", "_")}' - network_layer_mapping[network_name] = module - module.network_layer_name = network_name - else: - for name, module in shared.sd_model.cond_stage_model.wrapped.named_modules(): - network_name = name.replace(".", "_") - network_layer_mapping[network_name] = module - module.network_layer_name = network_name - """ network_layer_mapping = {} if shared.backend == shared.Backend.DIFFUSERS: + if not hasattr(shared.sd_model, 'text_encoder') or not hasattr(shared.sd_model, 'unet'): + return for name, module in shared.sd_model.text_encoder.named_modules(): prefix = "lora_te1_" if shared.sd_model_type == "sdxl" else "lora_te_" network_name = prefix + name.replace(".", "_") diff --git a/extensions-builtin/multidiffusion-upscaler-for-automatic1111 b/extensions-builtin/multidiffusion-upscaler-for-automatic1111 index 9894b2d82..b9af9312e 160000 --- a/extensions-builtin/multidiffusion-upscaler-for-automatic1111 +++ b/extensions-builtin/multidiffusion-upscaler-for-automatic1111 @@ -1 +1 @@ -Subproject commit 9894b2d82274a87c6fbea7a307b39d3e7d8236a1 +Subproject commit b9af9312ef62fed2bbc70d35ed02f73b110ec88d diff --git a/installer.py b/installer.py index 90ae210b3..c1493b093 100644 --- a/installer.py +++ b/installer.py @@ -365,7 +365,7 @@ def check_torch(): torch_command = os.environ.get('TORCH_COMMAND', 'torch torchvision --index-url https://download.pytorch.org/whl/cu121') else: torch_command = os.environ.get('TORCH_COMMAND', 'torch torchvision --index-url https://download.pytorch.org/whl/cu118') - xformers_package = os.environ.get('XFORMERS_PACKAGE', '--pre xformers<0.0.24' if opts.get('cross_attention_optimization', '') == 'xFormers' else 'none') + xformers_package = os.environ.get('XFORMERS_PACKAGE', '--pre xformers' if opts.get('cross_attention_optimization', '') == 'xFormers' else 'none') elif allow_rocm and (shutil.which('rocminfo') is not None or os.path.exists('/opt/rocm/bin/rocminfo') or os.path.exists('/dev/kfd')): log.info('AMD ROCm toolkit detected') os.environ.setdefault('PYTORCH_HIP_ALLOC_CONF', 'garbage_collection_threshold:0.8,max_split_size_mb:512') diff --git a/modules/sd_models.py b/modules/sd_models.py index 8d6776394..2692eb996 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -379,8 +379,9 @@ def read_metadata_from_safetensors(filename): def read_state_dict(checkpoint_file, map_location=None): # pylint: disable=unused-argument - #if shared.backend == shared.Backend.DIFFUSERS: - #return None + if not os.path.isfile(checkpoint_file): + shared.log.error(f"Model is not a file: {checkpoint_file}") + return None try: pl_sd = None with progress.open(checkpoint_file, 'rb', description=f'[cyan]Loading weights: [yellow]{checkpoint_file}', auto_refresh=True, console=shared.console) as f: @@ -413,6 +414,8 @@ def read_state_dict(checkpoint_file, map_location=None): # pylint: disable=unuse def get_checkpoint_state_dict(checkpoint_info: CheckpointInfo, timer): + if not os.path.isfile(checkpoint_info.filename): + return None if checkpoint_info in checkpoints_loaded: shared.log.info("Model weights loading: from cache") return checkpoints_loaded[checkpoint_info] diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index 15618101a..cc5101931 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -182,8 +182,9 @@ class ExtraNetworksPage: shared.log.warning(f'Extra network removing invalid image: {f}') try: if img is None: + img = None os.remove(f) - if img is not None and img.width > 1024 or img.height > 1024 or os.path.getsize(f) > 65536: + elif img.width > 1024 or img.height > 1024 or os.path.getsize(f) > 65536: img = img.convert('RGB') img.thumbnail((512, 512), Image.HAMMING) img.save(fn, quality=50)