From 65aee8cf7bd7262c058182a37d0def62f767d57c Mon Sep 17 00:00:00 2001 From: ljleb Date: Wed, 2 Aug 2023 15:54:41 -0400 Subject: [PATCH] refact --- modules/processing.py | 26 ++++++++++++-------------- modules/scripts.py | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/processing.py b/modules/processing.py index c65f16a5d..a313c89d7 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -648,20 +648,20 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: if shared.state.interrupted: shared.log.debug(f'Process interrupted: {n}/{p.n_iter}') break - prompts = p.all_prompts[n * p.batch_size:(n + 1) * p.batch_size] - negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] - seeds = p.all_seeds[n * p.batch_size:(n + 1) * p.batch_size] - subseeds = p.all_subseeds[n * p.batch_size:(n + 1) * p.batch_size] + p.prompts = p.all_prompts[n * p.batch_size:(n + 1) * p.batch_size] + p.negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] + p.seeds = p.all_seeds[n * p.batch_size:(n + 1) * p.batch_size] + p.subseeds = p.all_subseeds[n * p.batch_size:(n + 1) * p.batch_size] if p.scripts is not None: - p.scripts.before_process_batch(p, batch_number=n, prompts=prompts, seeds=seeds, subseeds=subseeds) - if len(prompts) == 0: + p.scripts.before_process_batch(p, batch_number=n, prompts=p.prompts, seeds=p.seeds, subseeds=p.subseeds) + if len(p.prompts) == 0: break - prompts, extra_network_data = extra_networks.parse_prompts(prompts) + p.prompts, extra_network_data = extra_networks.parse_prompts(p.prompts) if not p.disable_extra_networks: with devices.autocast(): extra_networks.activate(p, extra_network_data) if p.scripts is not None: - p.scripts.process_batch(p, batch_number=n, prompts=prompts, seeds=seeds, subseeds=subseeds) + p.scripts.process_batch(p, batch_number=n, prompts=p.prompts, seeds=p.seeds, subseeds=p.subseeds) if n == 0: with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: processed = Processed(p, [], p.seed, "") @@ -673,13 +673,13 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: shared.state.job = f"Batch {n+1} out of {p.n_iter}" if shared.backend == shared.Backend.ORIGINAL: - uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, negative_prompts, p.steps * step_multiplier, cached_uc) - c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, prompts, p.steps * step_multiplier, cached_c) + uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, p.negative_prompts, p.steps * step_multiplier, cached_uc) + c = get_conds_with_caching(prompt_parser.get_multicond_learned_conditioning, p.prompts, p.steps * step_multiplier, cached_c) if len(model_hijack.comments) > 0: for comment in model_hijack.comments: comments[comment] = 1 with devices.without_autocast() if devices.unet_needs_upcast else devices.autocast(): - samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts) + samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=p.seeds, subseeds=p.subseeds, subseed_strength=p.subseed_strength, prompts=p.prompts) x_samples_ddim = [decode_first_stage(p.sd_model, samples_ddim[i:i+1].to(dtype=devices.dtype_vae))[0].cpu() for i in range(samples_ddim.size(0))] try: for x in x_samples_ddim: @@ -701,7 +701,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: elif shared.backend == shared.Backend.DIFFUSERS: from modules.processing_diffusers import process_diffusers - x_samples_ddim = process_diffusers(p, seeds, prompts, negative_prompts) + x_samples_ddim = process_diffusers(p, p.seeds, p.prompts, p.negative_prompts) else: raise ValueError(f"Unknown backend {shared.backend}") @@ -711,8 +711,6 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: devices.torch_gc() if p.scripts is not None: p.scripts.postprocess_batch(p, x_samples_ddim, batch_number=n) - p.seeds = seeds - p.subseeds = subseeds if p.scripts is not None: p.prompts = p.all_prompts[n * p.batch_size:(n + 1) * p.batch_size] p.negative_prompts = p.all_negative_prompts[n * p.batch_size:(n + 1) * p.batch_size] diff --git a/modules/scripts.py b/modules/scripts.py index 8efc44018..bfd04c30e 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -124,7 +124,6 @@ class Script: - p.negative_prompts - p.seeds - p.subseeds - **kwargs will have same items as process_batch, and also: - batch_number - index of current batch, from 0 to number of batches-1 """