Cascade normalize padding and replace empty embed option with zeros

This commit is contained in:
Disty0
2024-06-13 03:13:45 +03:00
parent 94276cc5cd
commit 5f41181576
3 changed files with 6 additions and 5 deletions
+1 -1
View File
@@ -68,7 +68,7 @@
add `cli/image-exif.py` that can be used to view/extract metadata from images
- lower overhead on generate calls
- auto-synchronize modernui and core branches
- add option to pad prompt with empty embeds, thanks @Disty
- add option to pad prompt with zeros, thanks @Disty
## Fixes
+4 -3
View File
@@ -237,12 +237,13 @@ def pad_to_same_length(pipe, embeds):
if not hasattr(pipe, 'encode_prompt') and 'StableCascade' not in pipe.__class__.__name__:
return embeds
device = pipe.device if str(pipe.device) != 'meta' else devices.device
if shared.opts.diffusers_empty_prompt_pad:
empty_embed = [torch.empty((1, 77, embeds[0].shape[2]), device=device, dtype=embeds[0].dtype)]
if shared.opts.diffusers_zeros_prompt_pad:
empty_embed = [torch.zeros((1, 77, embeds[0].shape[2]), device=device, dtype=embeds[0].dtype)]
else:
try:
if 'StableCascade' in pipe.__class__.__name__:
empty_embed = [torch.zeros((1, 77, embeds[0].shape[2]), device=device, dtype=embeds[0].dtype)]
empty_embed = pipe.prior_pipe.encode_prompt(device, 1, 1, False, prompt="")
empty_embed = [torch.nn.functional.normalize(empty_embed[0])]
else:
empty_embed = pipe.encode_prompt("")
except TypeError: # SD1.5
+1 -1
View File
@@ -534,7 +534,7 @@ options_templates.update(options_section(('diffusers', "Diffusers Settings"), {
"disable_accelerate": OptionInfo(False, "Disable accelerate"),
"diffusers_force_zeros": OptionInfo(False, "Force zeros for prompts when empty", gr.Checkbox, {"visible": False}),
"diffusers_pooled": OptionInfo("default", "Diffusers SDXL pooled embeds", gr.Radio, {"choices": ['default', 'weighted']}),
"diffusers_empty_prompt_pad": OptionInfo(False, "Use empty values for prompt padding", gr.Checkbox),
"diffusers_zeros_prompt_pad": OptionInfo(False, "Use zeros for prompt padding", gr.Checkbox),
"huggingface_token": OptionInfo('', 'HuggingFace token'),
"onnx_sep": OptionInfo("<h2>ONNX Runtime</h2>", "", gr.HTML),