mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
update vae tiling defaults and allow hypertile min size setting
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
+2
-1
@@ -4,9 +4,10 @@
|
||||
|
||||
### Post release
|
||||
|
||||
- Add granular VAE tiling options in *settings -> variable auto encoder*
|
||||
- Add legacy option to use old LoRA loader in *settings -> networks*
|
||||
- Add granular VAE tiling options in *settings -> variable auto encoder*
|
||||
- Add sigma calculation to VAE preview, thanks @Disty0
|
||||
- Fix live preview image sizes in modern and standard ui
|
||||
|
||||
## Update for 2024-12-24
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ def split_attention(layer: nn.Module, tile_size: int=256, min_tile_size: int=128
|
||||
except Exception as e:
|
||||
if not error_reported:
|
||||
error_reported = True
|
||||
log.error(f'Hypertile error: width={width} height={height} {e}')
|
||||
log.error(f'Hypertile calculate: width={width} height={height} {e}')
|
||||
out = forward(x, *args[1:], **kwargs)
|
||||
return out
|
||||
if x.ndim == 4: # VAE
|
||||
@@ -155,7 +155,7 @@ def split_attention(layer: nn.Module, tile_size: int=256, min_tile_size: int=128
|
||||
except Exception as e:
|
||||
if not error_reported:
|
||||
error_reported = True
|
||||
log.error(f'Hypertile error: width={width} height={height} {e}')
|
||||
log.error(f'Hypertile apply: cls={layer.__class__} width={width} height={height} {e}')
|
||||
out = forward(x, *args[1:], **kwargs)
|
||||
return out
|
||||
return wrapper
|
||||
@@ -195,9 +195,10 @@ def context_hypertile_vae(p):
|
||||
return nullcontext()
|
||||
else:
|
||||
tile_size = shared.opts.hypertile_vae_tile if shared.opts.hypertile_vae_tile > 0 else max(128, 64 * min(p.width // 128, p.height // 128))
|
||||
shared.log.info(f'Applying hypertile: vae={tile_size}')
|
||||
min_tile_size = shared.opts.hypertile_unet_min_tile if shared.opts.hypertile_unet_min_tile > 0 else 128
|
||||
shared.log.info(f'Applying hypertile: vae={min_tile_size}/{tile_size}')
|
||||
p.extra_generation_params['Hypertile VAE'] = tile_size
|
||||
return split_attention(vae, tile_size=tile_size, min_tile_size=128, swap_size=shared.opts.hypertile_vae_swap_size)
|
||||
return split_attention(vae, tile_size=tile_size, min_tile_size=min_tile_size, swap_size=shared.opts.hypertile_vae_swap_size)
|
||||
|
||||
|
||||
def context_hypertile_unet(p):
|
||||
@@ -220,9 +221,10 @@ def context_hypertile_unet(p):
|
||||
return nullcontext()
|
||||
else:
|
||||
tile_size = shared.opts.hypertile_unet_tile if shared.opts.hypertile_unet_tile > 0 else max(128, 64 * min(p.width // 128, p.height // 128))
|
||||
shared.log.info(f'Applying hypertile: unet={tile_size}')
|
||||
min_tile_size = shared.opts.hypertile_unet_min_tile if shared.opts.hypertile_unet_min_tile > 0 else 128
|
||||
shared.log.info(f'Applying hypertile: unet={min_tile_size}/{tile_size}')
|
||||
p.extra_generation_params['Hypertile UNet'] = tile_size
|
||||
return split_attention(unet, tile_size=tile_size, min_tile_size=128, swap_size=shared.opts.hypertile_unet_swap_size, depth=shared.opts.hypertile_unet_depth)
|
||||
return split_attention(unet, tile_size=tile_size, min_tile_size=min_tile_size, swap_size=shared.opts.hypertile_unet_swap_size, depth=shared.opts.hypertile_unet_depth)
|
||||
|
||||
|
||||
def hypertile_set(p, hr=False):
|
||||
|
||||
@@ -1350,23 +1350,21 @@ def set_diffusers_attention(pipe):
|
||||
|
||||
def add_noise_pred_to_diffusers_callback(pipe):
|
||||
if pipe.__class__.__name__.startswith("StableDiffusion"):
|
||||
pipe._callback_tensor_inputs.append("noise_pred")
|
||||
pipe._callback_tensor_inputs.append("noise_pred") # pylint: disable=protected-access
|
||||
elif pipe.__class__.__name__.startswith("StableCascade"):
|
||||
pipe.prior_pipe._callback_tensor_inputs.append("predicted_image_embedding")
|
||||
pipe.prior_pipe._callback_tensor_inputs.append("predicted_image_embedding") # pylint: disable=protected-access
|
||||
elif hasattr(pipe, "scheduler") and "flow" in pipe.scheduler.__class__.__name__.lower():
|
||||
pipe._callback_tensor_inputs.append("noise_pred")
|
||||
pipe._callback_tensor_inputs.append("noise_pred") # pylint: disable=protected-access
|
||||
elif hasattr(pipe, "default_scheduler") and "flow" in pipe.default_scheduler.__class__.__name__.lower():
|
||||
pipe._callback_tensor_inputs.append("noise_pred")
|
||||
pipe._callback_tensor_inputs.append("noise_pred") # pylint: disable=protected-access
|
||||
return pipe
|
||||
|
||||
|
||||
def get_native(pipe: diffusers.DiffusionPipeline):
|
||||
if hasattr(pipe, "vae") and hasattr(pipe.vae.config, "sample_size"):
|
||||
# Stable Diffusion
|
||||
size = pipe.vae.config.sample_size
|
||||
size = pipe.vae.config.sample_size # Stable Diffusion
|
||||
elif hasattr(pipe, "movq") and hasattr(pipe.movq.config, "sample_size"):
|
||||
# Kandinsky
|
||||
size = pipe.movq.config.sample_size
|
||||
size = pipe.movq.config.sample_size # Kandinsky
|
||||
elif hasattr(pipe, "unet") and hasattr(pipe.unet.config, "sample_size"):
|
||||
size = pipe.unet.config.sample_size
|
||||
else:
|
||||
|
||||
+6
-5
@@ -507,7 +507,7 @@ options_templates.update(options_section(('vae_encoder', "Variable Auto Encoder"
|
||||
"diffusers_vae_slicing": OptionInfo(True, "VAE slicing", gr.Checkbox, {"visible": native}),
|
||||
"diffusers_vae_tiling": OptionInfo(cmd_opts.lowvram or cmd_opts.medvram, "VAE tiling", gr.Checkbox, {"visible": native}),
|
||||
"diffusers_vae_tile_size": OptionInfo(1024, "VAE tile size", gr.Slider, {"minimum": 256, "maximum": 4096, "step": 8 }),
|
||||
"diffusers_vae_tile_overlap": OptionInfo(0.1, "VAE tile overlap", gr.Slider, {"minimum": 0, "maximum": 0.9, "step": 0.1 }),
|
||||
"diffusers_vae_tile_overlap": OptionInfo(0.25, "VAE tile overlap", gr.Slider, {"minimum": 0, "maximum": 0.95, "step": 0.05 }),
|
||||
"sd_vae_sliced_encode": OptionInfo(False, "VAE sliced encode", gr.Checkbox, {"visible": not native}),
|
||||
"nan_skip": OptionInfo(False, "Skip Generation if NaN found in latents", gr.Checkbox),
|
||||
"rollback_vae": OptionInfo(False, "Attempt VAE roll back for NaN values"),
|
||||
@@ -609,12 +609,12 @@ options_templates.update(options_section(('quantization', "Quantization Settings
|
||||
|
||||
options_templates.update(options_section(('advanced', "Pipeline Modifiers"), {
|
||||
"token_merging_sep": OptionInfo("<h2>Token Merging</h2>", "", gr.HTML),
|
||||
"token_merging_method": OptionInfo("None", "Token merging method", gr.Radio, {"choices": ['None', 'ToMe', 'ToDo']}),
|
||||
"token_merging_method": OptionInfo("None", "Token merging enabled", gr.Radio, {"choices": ['None', 'ToMe', 'ToDo']}),
|
||||
"tome_ratio": OptionInfo(0.0, "ToMe token merging ratio", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.05}),
|
||||
"todo_ratio": OptionInfo(0.0, "ToDo token merging ratio", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.05}),
|
||||
|
||||
"freeu_sep": OptionInfo("<h2>FreeU</h2>", "", gr.HTML),
|
||||
"freeu_enabled": OptionInfo(False, "FreeU"),
|
||||
"freeu_enabled": OptionInfo(False, "FreeU enabled"),
|
||||
"freeu_b1": OptionInfo(1.2, "1st stage backbone", gr.Slider, {"minimum": 1.0, "maximum": 2.0, "step": 0.01}),
|
||||
"freeu_b2": OptionInfo(1.4, "2nd stage backbone", gr.Slider, {"minimum": 1.0, "maximum": 2.0, "step": 0.01}),
|
||||
"freeu_s1": OptionInfo(0.9, "1st stage skip", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}),
|
||||
@@ -624,9 +624,10 @@ options_templates.update(options_section(('advanced', "Pipeline Modifiers"), {
|
||||
"pag_apply_layers": OptionInfo("m0", "PAG layer names"),
|
||||
|
||||
"hypertile_sep": OptionInfo("<h2>HyperTile</h2>", "", gr.HTML),
|
||||
"hypertile_hires_only": OptionInfo(False, "HiRes pass only"),
|
||||
"hypertile_unet_enabled": OptionInfo(False, "UNet Enabled"),
|
||||
"hypertile_unet_tile": OptionInfo(0, "UNet tile size", gr.Slider, {"minimum": 0, "maximum": 1024, "step": 8}),
|
||||
"hypertile_hires_only": OptionInfo(False, "HiRes pass only"),
|
||||
"hypertile_unet_tile": OptionInfo(0, "UNet max tile size", gr.Slider, {"minimum": 0, "maximum": 1024, "step": 8}),
|
||||
"hypertile_unet_min_tile": OptionInfo(0, "UNet min tile size", gr.Slider, {"minimum": 0, "maximum": 1024, "step": 8}),
|
||||
"hypertile_unet_swap_size": OptionInfo(1, "UNet swap size", gr.Slider, {"minimum": 1, "maximum": 10, "step": 1}),
|
||||
"hypertile_unet_depth": OptionInfo(0, "UNet depth", gr.Slider, {"minimum": 0, "maximum": 4, "step": 1}),
|
||||
"hypertile_vae_enabled": OptionInfo(False, "VAE Enabled", gr.Checkbox),
|
||||
|
||||
Reference in New Issue
Block a user