This commit is contained in:
Vladimir Mandic
2023-07-21 09:27:59 -04:00
parent d962383b13
commit b31fa98669
5 changed files with 17 additions and 9 deletions
+3 -3
View File
@@ -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:
+1 -1
View File
@@ -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):
+5 -3
View File
@@ -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')
+1
View File
@@ -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 "),
+7 -2
View File
@@ -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