mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-08-04 11:12:35 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user