diff --git a/modules/devices.py b/modules/devices.py index 5a60e527f..207ddbac3 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -181,7 +181,7 @@ else: if backend == 'ipex': import os - def ipex_no_cuda(orig_func, *args, **kwargs): + def ipex_no_cuda(orig_func, *args, **kwargs): # pylint: disable=redefined-outer-name torch.cuda.is_available = lambda: False orig_func(*args, **kwargs) torch.cuda.is_available = torch.xpu.is_available @@ -193,7 +193,7 @@ if backend == 'ipex': torch.cuda.current_device = torch.xpu.current_device torch.cuda.get_device_name = torch.xpu.get_device_name torch.cuda.get_device_properties = torch.xpu.get_device_properties - torch._utils._get_available_device_type = lambda: "xpu" + torch._utils._get_available_device_type = lambda: "xpu" # pylint: disable=protected-access torch.cuda.set_device = torch.xpu.set_device torch.Tensor.cuda = torch.Tensor.xpu @@ -321,7 +321,7 @@ def without_autocast(disable=False): if disable: return contextlib.nullcontext() if shared.cmd_opts.use_directml: - return torch.dml.amp.autocast(enabled=False) if torch.is_autocast_enabled() else contextlib.nullcontext() + return torch.dml.amp.autocast(enabled=False) if torch.is_autocast_enabled() else contextlib.nullcontext() # pylint: disable=unexpected-keyword-arg if backend == 'ipex': return torch.xpu.amp.autocast(enabled=False) if torch.is_autocast_enabled() else contextlib.nullcontext() if cuda_ok: diff --git a/modules/img2img.py b/modules/img2img.py index dde82b4b8..9e822603e 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -11,7 +11,7 @@ from modules.memstats import memory_stats def process_batch(p, input_files, input_dir, output_dir, inpaint_mask_dir, args): shared.log.debug(f'batch: {input_dir}|{output_dir}|{inpaint_mask_dir}') processing.fix_seed(p) - if len(input_files) > 0: + if input_files is not None and len(input_files) > 0: image_files = [f.name for f in input_files] else: if not os.path.isdir(input_dir): diff --git a/modules/sd_models.py b/modules/sd_models.py index 03422f12a..5dde9427a 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -395,8 +395,10 @@ def load_model_weights(model: torch.nn.Module, checkpoint_info: CheckpointInfo, model.first_stage_model = vae if depth_model: model.depth_model = depth_model - # devices.dtype_unet = model.model.diffusion_model.dtype - model.model.diffusion_model.to(devices.dtype_unet) + if shared.opts.cuda_cast_unet: + devices.dtype_unet = model.model.diffusion_model.dtype + else: + model.model.diffusion_model.to(devices.dtype_unet) model.first_stage_model.to(devices.dtype_vae) # clean up cache if limit is reached while len(checkpoints_loaded) > shared.opts.sd_checkpoint_cache: @@ -727,7 +729,7 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No sd_model.enable_attention_slicing() else: sd_model.disable_attention_slicing() - if shared.opts.cross_attention_optimization == "xFormers": + if shared.opts.cross_attention_optimization == "xFormers" and hasattr(sd_model, 'enable_xformers_memory_efficient_attention'): sd_model.enable_xformers_memory_efficient_attention() if shared.opts.opt_channelslast: shared.log.debug('Diffusers: enable channels last') diff --git a/modules/shared.py b/modules/shared.py index 788f68806..6a1d9b4ab 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -381,6 +381,7 @@ options_templates.update(options_section(('cuda', "Compute Settings"), { "no_half_vae": OptionInfo(False, "Use full precision for VAE (--no-half-vae)"), "upcast_sampling": OptionInfo(True if sys.platform == "darwin" else False, "Enable upcast sampling"), "upcast_attn": OptionInfo(False, "Enable upcast cross attention layer"), + "cuda_cast_unet": OptionInfo(False, "Use fixed UNet precision"), "disable_nan_check": OptionInfo(True, "Disable NaN check in produced images/latent spaces"), "rollback_vae": OptionInfo(False, "Attempt VAE roll back when produced NaN values (experimental)"), "opt_channelslast": OptionInfo(False, "Use channels last as torch memory format "), diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index 2e29af5e8..39a868930 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -1,3 +1,4 @@ +import re import json import html import os.path @@ -249,7 +250,9 @@ class ExtraNetworksPage: for file in [f"{path}.txt", f"{path}.description.txt"]: try: with open(file, "r", encoding="utf-8", errors="replace") as f: - return f.read() + txt = f.read() + txt = re.sub('[<>]', '', txt) + return txt except OSError: pass return None @@ -259,7 +262,9 @@ class ExtraNetworksPage: for file in [f"{path}.info", f"{path}.civitai.info", f"{basename}.info", f"{basename}.civitai.info"]: try: with open(file, "r", encoding="utf-8", errors="replace") as f: - return f.read() + txt = f.read() + txt = re.sub('[<>]', '', txt) + return txt except OSError: pass return None