mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-12-29 19:05:05 +08:00
Merge pull request #15831 from AUTOMATIC1111/fix-Hypertile-xyz
Fix Hypertile xyz
This commit is contained in:
commit
04164a83c4
@ -1,6 +1,5 @@
|
||||
import hypertile
|
||||
from modules import scripts, script_callbacks, shared
|
||||
from scripts.hypertile_xyz import add_axis_options
|
||||
|
||||
|
||||
class ScriptHypertile(scripts.Script):
|
||||
@ -93,7 +92,6 @@ def on_ui_settings():
|
||||
"hypertile_max_depth_unet": shared.OptionInfo(3, "Hypertile U-Net max depth", gr.Slider, {"minimum": 0, "maximum": 3, "step": 1}, infotext="Hypertile U-Net max depth").info("larger = more neural network layers affected; minor effect on performance"),
|
||||
"hypertile_max_tile_unet": shared.OptionInfo(256, "Hypertile U-Net max tile size", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}, infotext="Hypertile U-Net max tile size").info("larger = worse performance"),
|
||||
"hypertile_swap_size_unet": shared.OptionInfo(3, "Hypertile U-Net swap size", gr.Slider, {"minimum": 0, "maximum": 64, "step": 1}, infotext="Hypertile U-Net swap size"),
|
||||
|
||||
"hypertile_enable_vae": shared.OptionInfo(False, "Enable Hypertile VAE", infotext="Hypertile VAE").info("minimal change in the generated picture"),
|
||||
"hypertile_max_depth_vae": shared.OptionInfo(3, "Hypertile VAE max depth", gr.Slider, {"minimum": 0, "maximum": 3, "step": 1}, infotext="Hypertile VAE max depth"),
|
||||
"hypertile_max_tile_vae": shared.OptionInfo(128, "Hypertile VAE max tile size", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}, infotext="Hypertile VAE max tile size"),
|
||||
@ -105,5 +103,20 @@ def on_ui_settings():
|
||||
shared.opts.add_option(name, opt)
|
||||
|
||||
|
||||
def add_axis_options():
|
||||
xyz_grid = [x for x in scripts.scripts_data if x.script_class.__module__ == "xyz_grid.py"][0].module
|
||||
xyz_grid.axis_options.extend([
|
||||
xyz_grid.AxisOption("[Hypertile] Unet First pass Enabled", str, xyz_grid.apply_override('hypertile_enable_unet', boolean=True), choices=xyz_grid.boolean_choice(reverse=True)),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Second pass Enabled", str, xyz_grid.apply_override('hypertile_enable_unet_secondpass', boolean=True), choices=xyz_grid.boolean_choice(reverse=True)),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Max Depth", int, xyz_grid.apply_override("hypertile_max_depth_unet"), confirm=xyz_grid.confirm_range(0, 3, '[Hypertile] Unet Max Depth'), choices=lambda: [str(x) for x in range(4)]),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Max Tile Size", int, xyz_grid.apply_override("hypertile_max_tile_unet"), confirm=xyz_grid.confirm_range(0, 512, '[Hypertile] Unet Max Tile Size')),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Swap Size", int, xyz_grid.apply_override("hypertile_swap_size_unet"), confirm=xyz_grid.confirm_range(0, 64, '[Hypertile] Unet Swap Size')),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Enabled", str, xyz_grid.apply_override('hypertile_enable_vae', boolean=True), choices=xyz_grid.boolean_choice(reverse=True)),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Max Depth", int, xyz_grid.apply_override("hypertile_max_depth_vae"), confirm=xyz_grid.confirm_range(0, 3, '[Hypertile] VAE Max Depth'), choices=lambda: [str(x) for x in range(4)]),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Max Tile Size", int, xyz_grid.apply_override("hypertile_max_tile_vae"), confirm=xyz_grid.confirm_range(0, 512, '[Hypertile] VAE Max Tile Size')),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Swap Size", int, xyz_grid.apply_override("hypertile_swap_size_vae"), confirm=xyz_grid.confirm_range(0, 64, '[Hypertile] VAE Swap Size')),
|
||||
])
|
||||
|
||||
|
||||
script_callbacks.on_ui_settings(on_ui_settings)
|
||||
script_callbacks.on_before_ui(add_axis_options)
|
||||
|
@ -1,51 +0,0 @@
|
||||
from modules import scripts
|
||||
from modules.shared import opts
|
||||
|
||||
xyz_grid = [x for x in scripts.scripts_data if x.script_class.__module__ == "xyz_grid.py"][0].module
|
||||
|
||||
def int_applier(value_name:str, min_range:int = -1, max_range:int = -1):
|
||||
"""
|
||||
Returns a function that applies the given value to the given value_name in opts.data.
|
||||
"""
|
||||
def validate(value_name:str, value:str):
|
||||
value = int(value)
|
||||
# validate value
|
||||
if not min_range == -1:
|
||||
assert value >= min_range, f"Value {value} for {value_name} must be greater than or equal to {min_range}"
|
||||
if not max_range == -1:
|
||||
assert value <= max_range, f"Value {value} for {value_name} must be less than or equal to {max_range}"
|
||||
def apply_int(p, x, xs):
|
||||
validate(value_name, x)
|
||||
opts.data[value_name] = int(x)
|
||||
return apply_int
|
||||
|
||||
def bool_applier(value_name:str):
|
||||
"""
|
||||
Returns a function that applies the given value to the given value_name in opts.data.
|
||||
"""
|
||||
def validate(value_name:str, value:str):
|
||||
assert value.lower() in ["true", "false"], f"Value {value} for {value_name} must be either true or false"
|
||||
def apply_bool(p, x, xs):
|
||||
validate(value_name, x)
|
||||
value_boolean = x.lower() == "true"
|
||||
opts.data[value_name] = value_boolean
|
||||
return apply_bool
|
||||
|
||||
def add_axis_options():
|
||||
extra_axis_options = [
|
||||
xyz_grid.AxisOption("[Hypertile] Unet First pass Enabled", str, bool_applier("hypertile_enable_unet"), choices=xyz_grid.boolean_choice(reverse=True)),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Second pass Enabled", str, bool_applier("hypertile_enable_unet_secondpass"), choices=xyz_grid.boolean_choice(reverse=True)),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Max Depth", int, int_applier("hypertile_max_depth_unet", 0, 3), choices=lambda: [str(x) for x in range(4)]),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Max Tile Size", int, int_applier("hypertile_max_tile_unet", 0, 512)),
|
||||
xyz_grid.AxisOption("[Hypertile] Unet Swap Size", int, int_applier("hypertile_swap_size_unet", 0, 64)),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Enabled", str, bool_applier("hypertile_enable_vae"), choices=xyz_grid.boolean_choice(reverse=True)),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Max Depth", int, int_applier("hypertile_max_depth_vae", 0, 3), choices=lambda: [str(x) for x in range(4)]),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Max Tile Size", int, int_applier("hypertile_max_tile_vae", 0, 512)),
|
||||
xyz_grid.AxisOption("[Hypertile] VAE Swap Size", int, int_applier("hypertile_swap_size_vae", 0, 64)),
|
||||
]
|
||||
set_a = {opt.label for opt in xyz_grid.axis_options}
|
||||
set_b = {opt.label for opt in extra_axis_options}
|
||||
if set_a.intersection(set_b):
|
||||
return
|
||||
|
||||
xyz_grid.axis_options.extend(extra_axis_options)
|
@ -95,6 +95,17 @@ def confirm_checkpoints_or_none(p, xs):
|
||||
raise RuntimeError(f"Unknown checkpoint: {x}")
|
||||
|
||||
|
||||
def confirm_range(min_val, max_val, axis_label):
|
||||
"""Generates a AxisOption.confirm() function that checks all values are within the specified range."""
|
||||
|
||||
def confirm_range_fun(p, xs):
|
||||
for x in xs:
|
||||
if not (max_val >= x >= min_val):
|
||||
raise ValueError(f'{axis_label} value "{x}" out of range [{min_val}, {max_val}]')
|
||||
|
||||
return confirm_range_fun
|
||||
|
||||
|
||||
def apply_size(p, x: str, xs) -> None:
|
||||
try:
|
||||
width, _, height = x.partition('x')
|
||||
@ -146,12 +157,14 @@ def apply_override(field, boolean: bool = False):
|
||||
if boolean:
|
||||
x = True if x.lower() == "true" else False
|
||||
p.override_settings[field] = x
|
||||
|
||||
return fun
|
||||
|
||||
|
||||
def boolean_choice(reverse: bool = False):
|
||||
def choice():
|
||||
return ["False", "True"] if reverse else ["True", "False"]
|
||||
|
||||
return choice
|
||||
|
||||
|
||||
@ -550,7 +563,7 @@ class Script(scripts.Script):
|
||||
mc = re_range_count.fullmatch(val)
|
||||
if m is not None:
|
||||
start = int(m.group(1))
|
||||
end = int(m.group(2))+1
|
||||
end = int(m.group(2)) + 1
|
||||
step = int(m.group(3)) if m.group(3) is not None else 1
|
||||
|
||||
valslist_ext += list(range(start, end, step))
|
||||
@ -703,11 +716,11 @@ class Script(scripts.Script):
|
||||
ydim = len(ys) if vary_seeds_y else 1
|
||||
|
||||
if vary_seeds_x:
|
||||
pc.seed += ix
|
||||
pc.seed += ix
|
||||
if vary_seeds_y:
|
||||
pc.seed += iy * xdim
|
||||
pc.seed += iy * xdim
|
||||
if vary_seeds_z:
|
||||
pc.seed += iz * xdim * ydim
|
||||
pc.seed += iz * xdim * ydim
|
||||
|
||||
try:
|
||||
res = process_images(pc)
|
||||
@ -775,18 +788,18 @@ class Script(scripts.Script):
|
||||
z_count = len(zs)
|
||||
|
||||
# Set the grid infotexts to the real ones with extra_generation_params (1 main grid + z_count sub-grids)
|
||||
processed.infotexts[:1+z_count] = grid_infotext[:1+z_count]
|
||||
processed.infotexts[:1 + z_count] = grid_infotext[:1 + z_count]
|
||||
|
||||
if not include_lone_images:
|
||||
# Don't need sub-images anymore, drop from list:
|
||||
processed.images = processed.images[:z_count+1]
|
||||
processed.images = processed.images[:z_count + 1]
|
||||
|
||||
if opts.grid_save:
|
||||
# Auto-save main and sub-grids:
|
||||
grid_count = z_count + 1 if z_count > 1 else 1
|
||||
for g in range(grid_count):
|
||||
# TODO: See previous comment about intentional data misalignment.
|
||||
adj_g = g-1 if g > 0 else g
|
||||
adj_g = g - 1 if g > 0 else g
|
||||
images.save_image(processed.images[g], p.outpath_grids, "xyz_grid", info=processed.infotexts[g], extension=opts.grid_format, prompt=processed.all_prompts[adj_g], seed=processed.all_seeds[adj_g], grid=True, p=processed)
|
||||
if not include_sub_grids: # if not include_sub_grids then skip saving after the first grid
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user