Update reforge
Browse files- ldm_patched/k_diffusion/sampling.py +9 -7
- ldm_patched/modules/sd.py +10 -0
- modules/sd_schedulers.py +12 -8
- modules/shared_options.py +1 -0
ldm_patched/k_diffusion/sampling.py
CHANGED
|
@@ -69,10 +69,11 @@ def get_sigmas_ays(n, sigma_min, sigma_max, is_sdxl=False, device='cpu'):
|
|
| 69 |
return interped_ys
|
| 70 |
|
| 71 |
if is_sdxl:
|
| 72 |
-
sigmas = [
|
| 73 |
else:
|
| 74 |
# Default to SD 1.5 sigmas.
|
| 75 |
-
sigmas = [
|
|
|
|
| 76 |
|
| 77 |
if n != len(sigmas):
|
| 78 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
@@ -91,9 +92,10 @@ def get_sigmas_ays_gits(n, sigma_min, sigma_max, is_sdxl=False, device='cpu'):
|
|
| 91 |
return interped_ys
|
| 92 |
|
| 93 |
if is_sdxl:
|
| 94 |
-
sigmas = [
|
|
|
|
| 95 |
else:
|
| 96 |
-
sigmas = [
|
| 97 |
|
| 98 |
if n != len(sigmas):
|
| 99 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
@@ -116,10 +118,10 @@ def get_sigmas_ays_32steps(n, sigma_min, sigma_max, is_sdxl=False, device='cpu')
|
|
| 116 |
return interped_ys
|
| 117 |
|
| 118 |
if is_sdxl:
|
| 119 |
-
sigmas = [
|
| 120 |
else:
|
| 121 |
-
sigmas = [
|
| 122 |
-
|
| 123 |
if n != len(sigmas):
|
| 124 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
| 125 |
else:
|
|
|
|
| 69 |
return interped_ys
|
| 70 |
|
| 71 |
if is_sdxl:
|
| 72 |
+
sigmas = [sigma_max, sigma_max/2.314, sigma_max/3.875, sigma_max/6.701, sigma_max/10.89, sigma_max/16.954, sigma_max/26.333, sigma_max/38.46, sigma_max/62.457, sigma_max/129.336, 0.029]
|
| 73 |
else:
|
| 74 |
# Default to SD 1.5 sigmas.
|
| 75 |
+
sigmas = [sigma_max, sigma_max/2.257, sigma_max/3.785, sigma_max/5.418, sigma_max/7.749, sigma_max/10.469, sigma_max/15.176, sigma_max/22.415, sigma_max/36.629, sigma_max/96.151, 0.029]
|
| 76 |
+
|
| 77 |
|
| 78 |
if n != len(sigmas):
|
| 79 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
|
|
| 92 |
return interped_ys
|
| 93 |
|
| 94 |
if is_sdxl:
|
| 95 |
+
sigmas = [sigma_max, sigma_max/3.087, sigma_max/5.693, sigma_max/9.558, sigma_max/14.807, sigma_max/22.415, sigma_max/34.964, sigma_max/54.533, sigma_max/81.648, sigma_max/115.078, 0.029]
|
| 96 |
+
|
| 97 |
else:
|
| 98 |
+
sigmas = [sigma_max, sigma_max/3.165, sigma_max/5.829, sigma_max/11.824, sigma_max/20.819, sigma_max/36.355, sigma_max/60.895, sigma_max/93.685, sigma_max/140.528, sigma_max/155.478, 0.029]
|
| 99 |
|
| 100 |
if n != len(sigmas):
|
| 101 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
|
|
| 118 |
return interped_ys
|
| 119 |
|
| 120 |
if is_sdxl:
|
| 121 |
+
sigmas = [sigma_max, sigma_max/1.310860875657935, sigma_max/1.718356235075352, sigma_max/2.252525958180810, sigma_max/2.688026675053433, sigma_max/3.174423075322040, sigma_max/3.748832539417044, sigma_max/4.463856789920335, sigma_max/5.326233593328242, sigma_max/6.355213820679800, sigma_max/7.477672611007930, sigma_max/8.745803592589411, sigma_max/10.228995682978878, sigma_max/11.864653584709637, sigma_max/13.685783347784952, sigma_max/15.786441921021279, sigma_max/18.202564111697559, sigma_max/20.980440157432400, sigma_max/24.182245076323649, sigma_max/27.652401723193991, sigma_max/31.246429590323925, sigma_max/35.307579021272943, sigma_max/40.308138967569972, sigma_max/47.132212095147923, sigma_max/55.111585405517003, sigma_max/65.460441760115945, sigma_max/82.786347724072168, sigma_max/104.698036963744033, sigma_max/138.041693219503482, sigma_max/264.794761864988552, sigma_max/507.935470821253285, 0.015000000000000000]
|
| 122 |
else:
|
| 123 |
+
sigmas = [sigma_max, sigma_max/1.300323183382763, sigma_max/1.690840379611262, sigma_max/2.198638945761486, sigma_max/2.622696705671493, sigma_max/3.098705619671305, sigma_max/3.661108232617473, sigma_max/4.152506637972936, sigma_max/4.662023756728857, sigma_max/5.234059175875519, sigma_max/5.874818853387466, sigma_max/6.593316416277412, sigma_max/7.399687115002039, sigma_max/8.213824943635682, sigma_max/9.050917900247738, sigma_max/9.973321246245751, sigma_max/11.115344803852001, sigma_max/12.529738625194212, sigma_max/14.124109921351757, sigma_max/15.959814856974724, sigma_max/18.099481611774999, sigma_max/20.526004748634670, sigma_max/23.506648288108032, sigma_max/27.541589307433523, sigma_max/32.269132736422456, sigma_max/38.982216080970984, sigma_max/53.219344283057142, sigma_max/72.656173487928834, sigma_max/103.609326413189740, sigma_max/218.693105563304210, sigma_max/461.605857767280530, 0.015000000000000000]
|
| 124 |
+
|
| 125 |
if n != len(sigmas):
|
| 126 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
| 127 |
else:
|
ldm_patched/modules/sd.py
CHANGED
|
@@ -542,6 +542,16 @@ class VAE:
|
|
| 542 |
|
| 543 |
self.patcher = ldm_patched.modules.model_patcher.ModelPatcher(self.first_stage_model, load_device=self.device, offload_device=offload_device)
|
| 544 |
logging.info("VAE load device: {}, offload device: {}, dtype: {}".format(self.device, offload_device, self.vae_dtype))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
def throw_exception_if_invalid(self):
|
| 546 |
if self.first_stage_model is None:
|
| 547 |
raise RuntimeError("ERROR: VAE is invalid: None\n\nIf the VAE is from a checkpoint loader node your checkpoint does not contain a valid VAE.")
|
|
|
|
| 542 |
|
| 543 |
self.patcher = ldm_patched.modules.model_patcher.ModelPatcher(self.first_stage_model, load_device=self.device, offload_device=offload_device)
|
| 544 |
logging.info("VAE load device: {}, offload device: {}, dtype: {}".format(self.device, offload_device, self.vae_dtype))
|
| 545 |
+
|
| 546 |
+
if shared.opts.reflective_padding_vae_sd == "Enabled":
|
| 547 |
+
for module in self.first_stage_model.modules():
|
| 548 |
+
from torch import nn
|
| 549 |
+
logging.info(self)
|
| 550 |
+
if isinstance(module, nn.Conv2d):
|
| 551 |
+
pad_h, pad_w = module.padding if isinstance(module.padding, tuple) else (module.padding, module.padding)
|
| 552 |
+
if pad_h > 0 or pad_w > 0:
|
| 553 |
+
module.padding_mode = "reflect"
|
| 554 |
+
logging.info("Setting reflective padding")
|
| 555 |
def throw_exception_if_invalid(self):
|
| 556 |
if self.first_stage_model is None:
|
| 557 |
raise RuntimeError("ERROR: VAE is invalid: None\n\nIf the VAE is from a checkpoint loader node your checkpoint does not contain a valid VAE.")
|
modules/sd_schedulers.py
CHANGED
|
@@ -108,10 +108,11 @@ def get_align_your_steps_sigmas(n, sigma_min, sigma_max, device):
|
|
| 108 |
return interped_ys
|
| 109 |
|
| 110 |
if shared.sd_model.is_sdxl:
|
| 111 |
-
sigmas = [
|
| 112 |
else:
|
| 113 |
# Default to SD 1.5 sigmas.
|
| 114 |
-
sigmas = [
|
|
|
|
| 115 |
|
| 116 |
if n != len(sigmas):
|
| 117 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
@@ -219,9 +220,10 @@ def get_align_your_steps_sigmas_GITS(n, sigma_min, sigma_max, device):
|
|
| 219 |
return interped_ys
|
| 220 |
|
| 221 |
if shared.sd_model.is_sdxl:
|
| 222 |
-
sigmas = [
|
|
|
|
| 223 |
else:
|
| 224 |
-
sigmas = [
|
| 225 |
|
| 226 |
if n != len(sigmas):
|
| 227 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
@@ -245,9 +247,10 @@ def ays_11_sigmas(n, sigma_min, sigma_max, device='cpu'):
|
|
| 245 |
return interped_ys
|
| 246 |
|
| 247 |
if shared.sd_model.is_sdxl:
|
| 248 |
-
sigmas = [
|
| 249 |
else:
|
| 250 |
-
sigmas = [
|
|
|
|
| 251 |
|
| 252 |
if n != len(sigmas):
|
| 253 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
@@ -268,9 +271,10 @@ def ays_32_sigmas(n, sigma_min, sigma_max, device='cpu'):
|
|
| 268 |
interped_ys = np.exp(new_ys)[::-1].copy()
|
| 269 |
return interped_ys
|
| 270 |
if shared.sd_model.is_sdxl:
|
| 271 |
-
sigmas = [
|
| 272 |
else:
|
| 273 |
-
sigmas = [
|
|
|
|
| 274 |
if n != len(sigmas):
|
| 275 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
| 276 |
else:
|
|
|
|
| 108 |
return interped_ys
|
| 109 |
|
| 110 |
if shared.sd_model.is_sdxl:
|
| 111 |
+
sigmas = sigmas = [sigma_max, sigma_max/2.314, sigma_max/3.875, sigma_max/6.701, sigma_max/10.89, sigma_max/16.954, sigma_max/26.333, sigma_max/38.46, sigma_max/62.457, sigma_max/129.336, 0.029]
|
| 112 |
else:
|
| 113 |
# Default to SD 1.5 sigmas.
|
| 114 |
+
sigmas = [sigma_max, sigma_max/2.257, sigma_max/3.785, sigma_max/5.418, sigma_max/7.749, sigma_max/10.469, sigma_max/15.176, sigma_max/22.415, sigma_max/36.629, sigma_max/96.151, 0.029]
|
| 115 |
+
|
| 116 |
|
| 117 |
if n != len(sigmas):
|
| 118 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
|
|
| 220 |
return interped_ys
|
| 221 |
|
| 222 |
if shared.sd_model.is_sdxl:
|
| 223 |
+
sigmas = [sigma_max, sigma_max/3.087, sigma_max/5.693, sigma_max/9.558, sigma_max/14.807, sigma_max/22.415, sigma_max/34.964, sigma_max/54.533, sigma_max/81.648, sigma_max/115.078, 0.029]
|
| 224 |
+
|
| 225 |
else:
|
| 226 |
+
sigmas = [sigma_max, sigma_max/3.165, sigma_max/5.829, sigma_max/11.824, sigma_max/20.819, sigma_max/36.355, sigma_max/60.895, sigma_max/93.685, sigma_max/140.528, sigma_max/155.478, 0.029]
|
| 227 |
|
| 228 |
if n != len(sigmas):
|
| 229 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
|
|
| 247 |
return interped_ys
|
| 248 |
|
| 249 |
if shared.sd_model.is_sdxl:
|
| 250 |
+
sigmas = [sigma_max, sigma_max/2.314, sigma_max/3.875, sigma_max/6.701, sigma_max/10.89, sigma_max/16.954, sigma_max/26.333, sigma_max/38.46, sigma_max/62.457, sigma_max/129.336, 0.029]
|
| 251 |
else:
|
| 252 |
+
sigmas = [sigma_max, sigma_max/2.257, sigma_max/3.785, sigma_max/5.418, sigma_max/7.749, sigma_max/10.469, sigma_max/15.176, sigma_max/22.415, sigma_max/36.629, sigma_max/96.151, 0.029]
|
| 253 |
+
|
| 254 |
|
| 255 |
if n != len(sigmas):
|
| 256 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
|
|
|
| 271 |
interped_ys = np.exp(new_ys)[::-1].copy()
|
| 272 |
return interped_ys
|
| 273 |
if shared.sd_model.is_sdxl:
|
| 274 |
+
sigmas = [sigma_max, sigma_max/1.310860875657935, sigma_max/1.718356235075352, sigma_max/2.252525958180810, sigma_max/2.688026675053433, sigma_max/3.174423075322040, sigma_max/3.748832539417044, sigma_max/4.463856789920335, sigma_max/5.326233593328242, sigma_max/6.355213820679800, sigma_max/7.477672611007930, sigma_max/8.745803592589411, sigma_max/10.228995682978878, sigma_max/11.864653584709637, sigma_max/13.685783347784952, sigma_max/15.786441921021279, sigma_max/18.202564111697559, sigma_max/20.980440157432400, sigma_max/24.182245076323649, sigma_max/27.652401723193991, sigma_max/31.246429590323925, sigma_max/35.307579021272943, sigma_max/40.308138967569972, sigma_max/47.132212095147923, sigma_max/55.111585405517003, sigma_max/65.460441760115945, sigma_max/82.786347724072168, sigma_max/104.698036963744033, sigma_max/138.041693219503482, sigma_max/264.794761864988552, sigma_max/507.935470821253285, 0.015000000000000000]
|
| 275 |
else:
|
| 276 |
+
sigmas = [sigma_max, sigma_max/1.300323183382763, sigma_max/1.690840379611262, sigma_max/2.198638945761486, sigma_max/2.622696705671493, sigma_max/3.098705619671305, sigma_max/3.661108232617473, sigma_max/4.152506637972936, sigma_max/4.662023756728857, sigma_max/5.234059175875519, sigma_max/5.874818853387466, sigma_max/6.593316416277412, sigma_max/7.399687115002039, sigma_max/8.213824943635682, sigma_max/9.050917900247738, sigma_max/9.973321246245751, sigma_max/11.115344803852001, sigma_max/12.529738625194212, sigma_max/14.124109921351757, sigma_max/15.959814856974724, sigma_max/18.099481611774999, sigma_max/20.526004748634670, sigma_max/23.506648288108032, sigma_max/27.541589307433523, sigma_max/32.269132736422456, sigma_max/38.982216080970984, sigma_max/53.219344283057142, sigma_max/72.656173487928834, sigma_max/103.609326413189740, sigma_max/218.693105563304210, sigma_max/461.605857767280530, 0.015000000000000000]
|
| 277 |
+
|
| 278 |
if n != len(sigmas):
|
| 279 |
sigmas = np.append(loglinear_interp(sigmas, n), [0.0])
|
| 280 |
else:
|
modules/shared_options.py
CHANGED
|
@@ -205,6 +205,7 @@ options_templates.update(options_section(('sd', "Stable Diffusion", "sd"), {
|
|
| 205 |
"tiling": OptionInfo(False, "Tiling", infotext='Tiling').info("produce a tileable picture"),
|
| 206 |
"hires_fix_refiner_pass": OptionInfo("second pass", "Hires fix: which pass to enable refiner for", gr.Radio, {"choices": ["first pass", "second pass", "both passes"]}, infotext="Hires refiner"),
|
| 207 |
"cond_stage_model_device_compatibility_check": OptionInfo(False, "Perform device compatibility check for conditional stage model. Enables broader hardware compatibility by falling back to CPU if GPU doesn't support required data types. May improve stability on some systems, but can significantly slow down model loading and potentially impact generation speed.", gr.Checkbox, {"interactive": True}),
|
|
|
|
| 208 |
}))
|
| 209 |
|
| 210 |
options_templates.update(options_section(('sdxl', "Stable Diffusion XL", "sd"), {
|
|
|
|
| 205 |
"tiling": OptionInfo(False, "Tiling", infotext='Tiling').info("produce a tileable picture"),
|
| 206 |
"hires_fix_refiner_pass": OptionInfo("second pass", "Hires fix: which pass to enable refiner for", gr.Radio, {"choices": ["first pass", "second pass", "both passes"]}, infotext="Hires refiner"),
|
| 207 |
"cond_stage_model_device_compatibility_check": OptionInfo(False, "Perform device compatibility check for conditional stage model. Enables broader hardware compatibility by falling back to CPU if GPU doesn't support required data types. May improve stability on some systems, but can significantly slow down model loading and potentially impact generation speed.", gr.Checkbox, {"interactive": True}),
|
| 208 |
+
"reflective_padding_vae_sd": OptionInfo("Disabled", "Enables or disables reflective vae padding, for models/VAEs like MS-LC-EQ-D-VR VAE", gr.Radio, {"choices": ["Disabled", "Enabled"]}, infotext="reflective vae padding"),
|
| 209 |
}))
|
| 210 |
|
| 211 |
options_templates.update(options_section(('sdxl', "Stable Diffusion XL", "sd"), {
|