move some settings to the new Optimization page

add slider for token merging for img2img
rework StableDiffusionProcessing to have the token_merging_ratio field
fix a bug with applying png optimizations for live previews when they shouldn't be applied
This commit is contained in:
AUTOMATIC
2023-05-17 20:22:38 +03:00
parent f6c06e3ed2
commit 9fd6c1e343
4 changed files with 55 additions and 45 deletions

View File

@@ -583,23 +583,27 @@ def unload_model_weights(sd_model=None, info=None):
return sd_model
def apply_token_merging(sd_model, hr: bool):
def apply_token_merging(sd_model, token_merging_ratio):
"""
Applies speed and memory optimizations from tomesd.
Args:
hr (bool): True if called in the context of a high-res pass
"""
ratio = shared.opts.token_merging_ratio
if hr:
ratio = shared.opts.token_merging_ratio_hr
current_token_merging_ratio = getattr(sd_model, 'applied_token_merged_ratio', 0)
tomesd.apply_patch(
sd_model,
ratio=ratio,
use_rand=False, # can cause issues with some samplers
merge_attn=True,
merge_crossattn=False,
merge_mlp=False
)
if current_token_merging_ratio == token_merging_ratio:
return
if current_token_merging_ratio > 0:
tomesd.remove_patch(sd_model)
if token_merging_ratio > 0:
tomesd.apply_patch(
sd_model,
ratio=token_merging_ratio,
use_rand=False, # can cause issues with some samplers
merge_attn=True,
merge_crossattn=False,
merge_mlp=False
)
sd_model.applied_token_merged_ratio = token_merging_ratio