From cdc8020d13c5eef099c609b0a911ccf3568afc0d Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 19 Nov 2022 12:01:51 +0300 Subject: change StableDiffusionProcessing to internally use sampler name instead of sampler index --- scripts/xy_grid.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'scripts/xy_grid.py') diff --git a/scripts/xy_grid.py b/scripts/xy_grid.py index 417ed0d4..b0b9d84d 100644 --- a/scripts/xy_grid.py +++ b/scripts/xy_grid.py @@ -10,9 +10,9 @@ import numpy as np import modules.scripts as scripts import gradio as gr -from modules import images +from modules import images, sd_samplers from modules.hypernetworks import hypernetwork -from modules.processing import process_images, Processed, get_correct_sampler, StableDiffusionProcessingTxt2Img +from modules.processing import process_images, Processed, StableDiffusionProcessingTxt2Img from modules.shared import opts, cmd_opts, state import modules.shared as shared import modules.sd_samplers @@ -60,9 +60,9 @@ def apply_order(p, x, xs): p.prompt = prompt_tmp + p.prompt -def build_samplers_dict(p): +def build_samplers_dict(): samplers_dict = {} - for i, sampler in enumerate(get_correct_sampler(p)): + for i, sampler in enumerate(sd_samplers.all_samplers): samplers_dict[sampler.name.lower()] = i for alias in sampler.aliases: samplers_dict[alias.lower()] = i @@ -70,7 +70,7 @@ def build_samplers_dict(p): def apply_sampler(p, x, xs): - sampler_index = build_samplers_dict(p).get(x.lower(), None) + sampler_index = build_samplers_dict().get(x.lower(), None) if sampler_index is None: raise RuntimeError(f"Unknown sampler: {x}") @@ -78,7 +78,7 @@ def apply_sampler(p, x, xs): def confirm_samplers(p, xs): - samplers_dict = build_samplers_dict(p) + samplers_dict = build_samplers_dict() for x in xs: if x.lower() not in samplers_dict.keys(): raise RuntimeError(f"Unknown sampler: {x}") -- cgit v1.2.3 From 40ca34b837b5068ec35b8d5681bae32cf28f5816 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 27 Nov 2022 13:17:39 +0300 Subject: fix for broken sampler selection in img2img and xy plot #4860 #4909 --- modules/img2img.py | 2 +- modules/processing.py | 2 +- scripts/xy_grid.py | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'scripts/xy_grid.py') diff --git a/modules/img2img.py b/modules/img2img.py index 9fc5b693..7e58994a 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -99,7 +99,7 @@ def img2img(mode: int, prompt: str, negative_prompt: str, prompt_style: str, pro seed_resize_from_h=seed_resize_from_h, seed_resize_from_w=seed_resize_from_w, seed_enable_extras=seed_enable_extras, - sampler_index=sd_samplers.samplers_for_img2img[sampler_index].name, + sampler_name=sd_samplers.samplers_for_img2img[sampler_index].name, batch_size=batch_size, n_iter=n_iter, steps=steps, diff --git a/modules/processing.py b/modules/processing.py index c310df6a..edceb532 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -74,7 +74,7 @@ class StableDiffusionProcessing(): """ def __init__(self, sd_model=None, outpath_samples=None, outpath_grids=None, prompt: str = "", styles: List[str] = None, seed: int = -1, subseed: int = -1, subseed_strength: float = 0, seed_resize_from_h: int = -1, seed_resize_from_w: int = -1, seed_enable_extras: bool = True, sampler_name: str = None, batch_size: int = 1, n_iter: int = 1, steps: int = 50, cfg_scale: float = 7.0, width: int = 512, height: int = 512, restore_faces: bool = False, tiling: bool = False, do_not_save_samples: bool = False, do_not_save_grid: bool = False, extra_generation_params: Dict[Any, Any] = None, overlay_images: Any = None, negative_prompt: str = None, eta: float = None, do_not_reload_embeddings: bool = False, denoising_strength: float = 0, ddim_discretize: str = None, s_churn: float = 0.0, s_tmax: float = None, s_tmin: float = 0.0, s_noise: float = 1.0, override_settings: Dict[str, Any] = None, sampler_index: int = None): if sampler_index is not None: - warnings.warn("sampler_index argument for StableDiffusionProcessing does not do anything; use sampler_name") + print("sampler_index argument for StableDiffusionProcessing does not do anything; use sampler_name", file=sys.stderr) self.sd_model = sd_model self.outpath_samples: str = outpath_samples diff --git a/scripts/xy_grid.py b/scripts/xy_grid.py index b0b9d84d..2517c47d 100644 --- a/scripts/xy_grid.py +++ b/scripts/xy_grid.py @@ -62,25 +62,25 @@ def apply_order(p, x, xs): def build_samplers_dict(): samplers_dict = {} - for i, sampler in enumerate(sd_samplers.all_samplers): - samplers_dict[sampler.name.lower()] = i + for sampler in sd_samplers.all_samplers: + samplers_dict[sampler.name.lower()] = sampler.name for alias in sampler.aliases: - samplers_dict[alias.lower()] = i + samplers_dict[alias.lower()] = sampler.name return samplers_dict def apply_sampler(p, x, xs): - sampler_index = build_samplers_dict().get(x.lower(), None) - if sampler_index is None: + sampler_name = build_samplers_dict().get(x.lower(), None) + if sampler_name is None: raise RuntimeError(f"Unknown sampler: {x}") - p.sampler_index = sampler_index + p.sampler_name = sampler_name def confirm_samplers(p, xs): samplers_dict = build_samplers_dict() for x in xs: - if x.lower() not in samplers_dict.keys(): + if x.lower() not in samplers_dict: raise RuntimeError(f"Unknown sampler: {x}") -- cgit v1.2.3 From 10923f9b3a10a9af20429e51242614e259fbd434 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 27 Nov 2022 13:43:10 +0300 Subject: calculate dictionary for sampler names only once --- modules/sd_samplers.py | 7 +++++++ scripts/xy_grid.py | 14 ++------------ 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'scripts/xy_grid.py') diff --git a/modules/sd_samplers.py b/modules/sd_samplers.py index 43ce34eb..6f8ccf1d 100644 --- a/modules/sd_samplers.py +++ b/modules/sd_samplers.py @@ -52,6 +52,7 @@ all_samplers_map = {x.name: x for x in all_samplers} samplers = [] samplers_for_img2img = [] +samplers_map = {} def create_sampler(name, model): @@ -77,6 +78,12 @@ def set_samplers(): samplers = [x for x in all_samplers if x.name not in hidden] samplers_for_img2img = [x for x in all_samplers if x.name not in hidden_img2img] + samplers_map.clear() + for sampler in all_samplers: + samplers_map[sampler.name.lower()] = sampler.name + for alias in sampler.aliases: + samplers_map[alias.lower()] = sampler.name + set_samplers() diff --git a/scripts/xy_grid.py b/scripts/xy_grid.py index 2517c47d..0f27deda 100644 --- a/scripts/xy_grid.py +++ b/scripts/xy_grid.py @@ -58,19 +58,10 @@ def apply_order(p, x, xs): prompt_tmp += part prompt_tmp += x[idx] p.prompt = prompt_tmp + p.prompt - - -def build_samplers_dict(): - samplers_dict = {} - for sampler in sd_samplers.all_samplers: - samplers_dict[sampler.name.lower()] = sampler.name - for alias in sampler.aliases: - samplers_dict[alias.lower()] = sampler.name - return samplers_dict def apply_sampler(p, x, xs): - sampler_name = build_samplers_dict().get(x.lower(), None) + sampler_name = sd_samplers.samplers_map.get(x.lower(), None) if sampler_name is None: raise RuntimeError(f"Unknown sampler: {x}") @@ -78,9 +69,8 @@ def apply_sampler(p, x, xs): def confirm_samplers(p, xs): - samplers_dict = build_samplers_dict() for x in xs: - if x.lower() not in samplers_dict: + if x.lower() not in sd_samplers.samplers_map: raise RuntimeError(f"Unknown sampler: {x}") -- cgit v1.2.3