mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 09:38:23 +02:00
need full precision for model & vae.
Stable & tested.
This commit is contained in:
@@ -92,6 +92,7 @@ sampling.sample_dpm_adaptive = sample_dpm_adaptive
|
||||
|
||||
# stablediffusion
|
||||
from ldm.models.diffusion.ddim import DDIMSampler
|
||||
from ldm.modules.diffusionmodules.util import noise_like
|
||||
|
||||
@torch.no_grad()
|
||||
def p_sample_ddim(self, x, c, t, index, repeat_noise=False, use_original_steps=False, quantize_denoised=False,
|
||||
@@ -168,3 +169,13 @@ def p_sample_ddim(self, x, c, t, index, repeat_noise=False, use_original_steps=F
|
||||
return x_prev, pred_x0
|
||||
|
||||
DDIMSampler.p_sample_ddim = p_sample_ddim
|
||||
|
||||
# torch
|
||||
|
||||
Generator_init = torch.Generator.__init__
|
||||
def Generator_init_fix(self, device = None, *args, **kwargs):
|
||||
if device is not None and device.type == 'privateuseone':
|
||||
return Generator_init(self, 'cpu', *args, **kwargs) # DML Solution: torch.Generator fallback to cpu.
|
||||
else:
|
||||
return Generator_init(self, device, *args, **kwargs)
|
||||
torch.Generator.__init__ = Generator_init_fix
|
||||
|
||||
@@ -32,7 +32,7 @@ def get_available_vram():
|
||||
return mem_free_total
|
||||
elif shared.device.type == 'privateuseone':
|
||||
# DML ISSUE: There's no way to get any memory info.
|
||||
return 1048576
|
||||
return 1073741824
|
||||
else:
|
||||
return psutil.virtual_memory().available
|
||||
|
||||
@@ -200,7 +200,7 @@ def einsum_op_cuda(q, k, v):
|
||||
|
||||
def einsum_op_dml(q, k, v):
|
||||
# DML ISSUE: There's no way to get any memory info.
|
||||
return einsum_op_tensor_mem(q, k, v, 1024)
|
||||
return einsum_op_tensor_mem(q, k, v, 1073741824)
|
||||
|
||||
def einsum_op(q, k, v):
|
||||
if q.device.type == 'cuda':
|
||||
|
||||
+7
-5
@@ -57,13 +57,15 @@ devices.device, devices.device_interrogate, devices.device_gfpgan, devices.devic
|
||||
(devices.cpu if any(y in cmd_opts.use_cpu for y in [x, 'all']) else devices.get_optimal_device() for x in ['sd', 'interrogate', 'gfpgan', 'esrgan', 'codeformer'])
|
||||
|
||||
device = devices.device
|
||||
is_device_dml = False
|
||||
sd_upscalers = []
|
||||
sd_model = None
|
||||
clip_model = None
|
||||
|
||||
|
||||
#if device.type == 'privateuseone':
|
||||
# import sd_hijack_directml
|
||||
if device.type == 'privateuseone':
|
||||
import sd_hijack_directml
|
||||
is_device_dml = True
|
||||
|
||||
|
||||
def reload_hypernetworks():
|
||||
@@ -251,7 +253,7 @@ options_templates.update(options_section(('sd', "Stable Diffusion"), {
|
||||
"comma_padding_backtrack": OptionInfo(20, "Increase coherency by padding from the last comma within n tokens when using more than 75 tokens", gr.Slider, {"minimum": 0, "maximum": 74, "step": 1 }),
|
||||
"CLIP_stop_at_last_layers": OptionInfo(1, "Clip skip", gr.Slider, {"minimum": 1, "maximum": 12, "step": 1}),
|
||||
"upcast_attn": OptionInfo(False, "Upcast cross attention layer to float32"),
|
||||
"cross_attention_optimization": OptionInfo("Scaled-Dot-Product", "Cross-attention optimization method", gr.Radio, lambda: {"choices": shared_items.list_crossattention() }),
|
||||
"cross_attention_optimization": OptionInfo("Sub-quadratic" if is_device_dml else "Scaled-Dot-Product", "Cross-attention optimization method", gr.Radio, lambda: {"choices": shared_items.list_crossattention() }),
|
||||
"cross_attention_options": OptionInfo([], "Cross-attention advanced options", gr.CheckboxGroup, lambda: {"choices": ['xFormers enable flash Attention', 'SDP disable memory attention']}),
|
||||
"sub_quad_q_chunk_size": OptionInfo(512, "Sub-quadratic cross-attention query chunk size for the layer optimization to use", gr.Slider, {"minimum": 16, "maximum": 8192, "step": 8}),
|
||||
"sub_quad_kv_chunk_size": OptionInfo(512, "Sub-quadratic cross-attentionkv chunk size for the sub-quadratic cross-attention layer optimization to use", gr.Slider, {"minimum": 0, "maximum": 8192, "step": 8}),
|
||||
@@ -328,8 +330,8 @@ options_templates.update(options_section(('saving-paths', "Image Paths"), {
|
||||
options_templates.update(options_section(('cuda', "CUDA Settings"), {
|
||||
"precision": OptionInfo("Autocast", "Precision type", gr.Radio, lambda: {"choices": ["Autocast", "Full"]}),
|
||||
"cuda_dtype": OptionInfo("FP16", "Device precision type", gr.Radio, lambda: {"choices": ["FP32", "FP16", "BF16"]}),
|
||||
"no_half": OptionInfo(False, "Use full precision for model (--no-half)"),
|
||||
"no_half_vae": OptionInfo(False, "Use full precision for VAE (--no-half-vae)"),
|
||||
"no_half": OptionInfo(True if is_device_dml else False, "Use full precision for model (--no-half)"),
|
||||
"no_half_vae": OptionInfo(True if is_device_dml else False, "Use full precision for VAE (--no-half-vae)"),
|
||||
"disable_nan_check": OptionInfo(True, "Do not check if produced images/latent spaces have NaN values"),
|
||||
"opt_channelslast": OptionInfo(False, "Use channels last as torch memory format "),
|
||||
"cudnn_benchmark": OptionInfo(False, "Enable cuDNN benchmark feature"),
|
||||
|
||||
Reference in New Issue
Block a user