From 0f14d311e0d02107cd2addadbd34d74b1eee4645 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Mon, 27 May 2024 17:29:08 -0400 Subject: [PATCH] fix timesteps --- modules/processing_args.py | 18 +++++++++--------- modules/sd_samplers_diffusers.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/processing_args.py b/modules/processing_args.py index 4880ec21e..b3bc69c35 100644 --- a/modules/processing_args.py +++ b/modules/processing_args.py @@ -92,20 +92,20 @@ def set_pipeline_args(p, model, prompts: list, negative_prompts: list, prompts_2 steps = kwargs.get("num_inference_steps", None) or len(getattr(p, 'timesteps', ['1'])) if 'timesteps' in possible: - if hasattr(model.scheduler, 'set_timesteps') and "timesteps" in set(inspect.signature(model.scheduler.set_timesteps).parameters.keys()): - try: - timesteps = re.split(',| ', shared.opts.schedulers_timesteps) - timesteps = [int(x) for x in timesteps if x.isdigit()] - if len(timesteps) > 0: + timesteps = re.split(',| ', shared.opts.schedulers_timesteps) + timesteps = [int(x) for x in timesteps if x.isdigit()] + if len(timesteps) > 0: + if hasattr(model.scheduler, 'set_timesteps') and "timesteps" in set(inspect.signature(model.scheduler.set_timesteps).parameters.keys()): + try: args['timesteps'] = timesteps p.steps = len(timesteps) p.timesteps = timesteps steps = p.steps shared.log.debug(f'Sampler: steps={len(timesteps)} timesteps={timesteps}') - except Exception as e: - shared.log.error(f'Sampler timesteps: {e}') - else: - shared.log.warning(f'Sampler: sampler={model.scheduler.__class__.__name__} timesteps not supported') + except Exception as e: + shared.log.error(f'Sampler timesteps: {e}') + else: + shared.log.warning(f'Sampler: sampler={model.scheduler.__class__.__name__} timesteps not supported') if shared.opts.prompt_attention != 'Fixed attention' and ('StableDiffusion' in model.__class__.__name__ or 'StableCascade' in model.__class__.__name__) and 'Onnx' not in model.__class__.__name__: try: prompt_parser_diffusers.encode_prompts(model, p, prompts, negative_prompts, steps=steps, clip_skip=clip_skip) diff --git a/modules/sd_samplers_diffusers.py b/modules/sd_samplers_diffusers.py index 81c05776d..be6aedb42 100644 --- a/modules/sd_samplers_diffusers.py +++ b/modules/sd_samplers_diffusers.py @@ -146,7 +146,7 @@ class DiffusionSampler: self.config['beta_end'] = shared.opts.schedulers_beta_end if 'rescale_betas_zero_snr' in self.config: self.config['rescale_betas_zero_snr'] = shared.opts.schedulers_rescale_betas - if 'timestep_spacing' in self.config and shared.opts.schedulers_timestep_spacing != 'default': + if 'timestep_spacing' in self.config and shared.opts.schedulers_timestep_spacing != 'default' and shared.opts.schedulers_timestep_spacing is not None: self.config['timestep_spacing'] = shared.opts.schedulers_timestep_spacing if 'num_train_timesteps' in self.config: self.config['num_train_timesteps'] = shared.opts.schedulers_timesteps_range