From 8350b93a5cb3a7b90ede2608c49a67d8068c492f Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Mon, 15 May 2023 09:32:20 -0400 Subject: [PATCH] add force latent sampler --- modules/devices.py | 2 +- modules/scripts.py | 12 ++++++------ modules/shared.py | 1 + scripts/xyz_grid.py | 4 +++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/devices.py b/modules/devices.py index bc1c8de52..bba06b4d4 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -77,7 +77,7 @@ def torch_gc(): torch.cuda.ipc_collect() except: pass - shared.log.debug(f'gc: {torch.device(get_optimal_device_name())} {memstats.memory_stats()}') + shared.log.debug(f'gc: device={torch.device(get_optimal_device_name())} {memstats.memory_stats()}') def test_fp16(): diff --git a/modules/scripts.py b/modules/scripts.py index 15c37f478..8735a30a7 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -367,55 +367,55 @@ class ScriptRunner: return processed def process(self, p, **kwargs): + log.debug(f'Script process: {[s.title() for s in self.alwayson_scripts]}') for script in self.alwayson_scripts: try: args = p.per_script_args.get(script.title(), p.script_args[script.args_from:script.args_to]) - log.debug(f'Script process: {script.title()}') script.process(p, *args, **kwargs) except Exception as e: errors.display(e, f'Running script process: {script.filename}') def before_process_batch(self, p, **kwargs): + log.debug(f'Script before-process-batch: {[s.title() for s in self.alwayson_scripts]}') for script in self.alwayson_scripts: try: args = p.per_script_args.get(script.title(), p.script_args[script.args_from:script.args_to]) - log.debug(f'Script before-process-batch: {script.title()}') script.before_process_batch(p, *args, **kwargs) except Exception as e: errors.display(e, f'Running script before process batch: {script.filename}') def process_batch(self, p, **kwargs): + log.debug(f'Script process-batch: {[s.title() for s in self.alwayson_scripts]}') for script in self.alwayson_scripts: try: args = p.per_script_args.get(script.title(), p.script_args[script.args_from:script.args_to]) - log.debug(f'Script process-batch: {script.title()}') script.process_batch(p, *args, **kwargs) except Exception as e: errors.display(e, f'Running script process batch: {script.filename}') def postprocess(self, p, processed): + log.debug(f'Script postprocess: {[s.title() for s in self.alwayson_scripts]}') for script in self.alwayson_scripts: try: args = p.per_script_args.get(script.title(), p.script_args[script.args_from:script.args_to]) - log.debug(f'Script postprocess: {script.title()}') script.postprocess(p, processed, *args) except Exception as e: errors.display(e, f'Running script postprocess: {script.filename}') def postprocess_batch(self, p, images, **kwargs): + log.debug(f'Script postprocess-batch: {[s.title() for s in self.alwayson_scripts]}') for script in self.alwayson_scripts: try: args = p.per_script_args.get(script.title(), p.script_args[script.args_from:script.args_to]) - log.debug(f'Script postprocess-batch: {script.title()}') script.postprocess_batch(p, *args, images=images, **kwargs) except Exception as e: errors.display(e, f'Running script before postprocess batch: {script.filename}') def postprocess_image(self, p, pp: PostprocessImageArgs): + log.debug(f'Script postprocess-image: {[s.title() for s in self.alwayson_scripts]}') for script in self.alwayson_scripts: try: args = p.per_script_args.get(script.title(), p.script_args[script.args_from:script.args_to]) - log.debug(f'Script postprocess-image: {script.title()}') script.postprocess_image(p, pp, *args) except Exception as e: errors.display(e, f'Running script postprocess image: {script.filename}') diff --git a/modules/shared.py b/modules/shared.py index e6eb0a9f9..c607b50a3 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -431,6 +431,7 @@ options_templates.update(options_section(('ui', "Live previews"), { options_templates.update(options_section(('sampler-params', "Sampler parameters"), { "show_samplers": OptionInfo(["Euler a", "UniPC", "DDIM", "DPM++ SDE", "DPM++ SDE", "DPM2 Karras", "DPM++ 2M Karras"], "Show samplers in user interface", gr.CheckboxGroup, lambda: {"choices": [x.name for x in list_samplers() if x.name != "PLMS"]}), "fallback_sampler": OptionInfo("Euler a", "Secondary sampler", gr.Dropdown, lambda: {"choices": ["None"] + [x.name for x in list_samplers()]}), + "force_latent_upscaler": OptionInfo("None", "Force latent upscaler sampler", gr.Dropdown, lambda: {"choices": ["None"] + [x.name for x in list_samplers()]}), "eta_ancestral": OptionInfo(1.0, "Noise multiplier for ancestral samplers (eta)", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}), "eta_ddim": OptionInfo(0.0, "Noise multiplier for DDIM (eta)", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}), "ddim_discretize": OptionInfo('uniform', "DDIM discretize img2img", gr.Radio, {"choices": ['uniform', 'quad']}), diff --git a/scripts/xyz_grid.py b/scripts/xyz_grid.py index 45eeda1ce..0fda6b4c5 100644 --- a/scripts/xyz_grid.py +++ b/scripts/xyz_grid.py @@ -350,6 +350,7 @@ class SharedSettingsStackHelper(object): self.token_merging_random = shared.opts.token_merging_random self.sd_model_checkpoint = shared.opts.sd_model_checkpoint self.sd_vae_checkpoint = shared.opts.sd_vae + self.xyz_fallback_sampler = shared.opts.data["xyz_fallback_sampler"] def __exit__(self, exc_type, exc_value, tb): #Restore overriden settings after plot generation. @@ -359,6 +360,7 @@ class SharedSettingsStackHelper(object): shared.opts.data["token_merging_ratio_hr"] = self.token_merging_ratio_hr shared.opts.data["token_merging_ratio"] = self.token_merging_ratio shared.opts.data["token_merging_random"] = self.token_merging_random + shared.opts.data["xyz_fallback_sampler"] = self.xyz_fallback_sampler if self.sd_model_checkpoint != shared.opts.sd_model_checkpoint: shared.opts.data["sd_model_checkpoint"] = self.sd_model_checkpoint sd_models.reload_model_weights() @@ -512,7 +514,7 @@ class Script(scripts.Script): else: valslist_ext.append(val) valslist = valslist_ext - elif opt.type == str_permutations: + elif opt.type == str_permutations: # pylint: disable=comparison-with-callable valslist = list(permutations(valslist)) valslist = [opt.type(x) for x in valslist] # Confirm options are valid before starting