diff options
author | AUTOMATIC <16777216c@gmail.com> | 2023-05-17 17:22:38 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2023-05-17 17:22:54 +0000 |
commit | 9fd6c1e3430f5947add23e2e94ac816c2546481c (patch) | |
tree | f7b19a75a4d15af43765c59b4f9e0f6eaf52210d /modules/sd_models.py | |
parent | f6c06e3ed2fc861e98b2f0e93e0b1fef0ef6e0cf (diff) | |
download | stable-diffusion-webui-gfx803-9fd6c1e3430f5947add23e2e94ac816c2546481c.tar.gz stable-diffusion-webui-gfx803-9fd6c1e3430f5947add23e2e94ac816c2546481c.tar.bz2 stable-diffusion-webui-gfx803-9fd6c1e3430f5947add23e2e94ac816c2546481c.zip |
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
Diffstat (limited to 'modules/sd_models.py')
-rw-r--r-- | modules/sd_models.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/modules/sd_models.py b/modules/sd_models.py index e612be10..4bd8783e 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -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
-
- 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
- )
+ current_token_merging_ratio = getattr(sd_model, 'applied_token_merged_ratio', 0)
+
+ 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
|