From b15cf4adaee75d17797e1e4b0560ca447998fa8f Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 22 Dec 2024 17:38:51 -0500 Subject: [PATCH] fix pag with batch count Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 2 ++ modules/pag/__init__.py | 21 +++++++++++---------- scripts/animatediff.py | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88a738a86..703804ab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -220,6 +220,8 @@ All-in-all, we're around ~160 commits worth of updates, check changelog for full - fix svd image2video - fix gallery display during generate - fix wildcards replacement to be unique +- fix animatediff-xl +- fix pag with batch count ## Update for 2024-11-21 diff --git a/modules/pag/__init__.py b/modules/pag/__init__.py index b7a56c40d..a72f7825d 100644 --- a/modules/pag/__init__.py +++ b/modules/pag/__init__.py @@ -12,29 +12,29 @@ def apply(p: processing.StableDiffusionProcessing): # pylint: disable=arguments- global orig_pipeline # pylint: disable=global-statement if not shared.native: return None - c = shared.sd_model.__class__ if shared.sd_loaded else None - if c == StableDiffusionPAGPipeline or c == StableDiffusionXLPAGPipeline: - unapply() + cls = shared.sd_model.__class__ if shared.sd_loaded else None + if cls == StableDiffusionPAGPipeline or cls == StableDiffusionXLPAGPipeline: + cls = unapply() if p.pag_scale == 0: return - if 'PAG' in shared.sd_model.__class__.__name__: + if 'PAG' in cls.__name__: pass - elif detect.is_sd15(c): + elif detect.is_sd15(cls): if sd_models.get_diffusers_task(shared.sd_model) != sd_models.DiffusersTaskType.TEXT_2_IMAGE: - shared.log.warning(f'PAG: pipeline={c} not implemented') + shared.log.warning(f'PAG: pipeline={cls.__name__} not implemented') return None orig_pipeline = shared.sd_model shared.sd_model = sd_models.switch_pipe(StableDiffusionPAGPipeline, shared.sd_model) - elif detect.is_sdxl(c): + elif detect.is_sdxl(cls): if sd_models.get_diffusers_task(shared.sd_model) != sd_models.DiffusersTaskType.TEXT_2_IMAGE: - shared.log.warning(f'PAG: pipeline={c} not implemented') + shared.log.warning(f'PAG: pipeline={cls.__name__} not implemented') return None orig_pipeline = shared.sd_model shared.sd_model = sd_models.switch_pipe(StableDiffusionXLPAGPipeline, shared.sd_model) - elif detect.is_f1(c): + elif detect.is_f1(cls): p.task_args['true_cfg_scale'] = p.pag_scale else: - shared.log.warning(f'PAG: pipeline={c} required={StableDiffusionPipeline.__name__}') + shared.log.warning(f'PAG: pipeline={cls.__name__} required={StableDiffusionPipeline.__name__}') return None p.task_args['pag_scale'] = p.pag_scale @@ -54,3 +54,4 @@ def unapply(): if orig_pipeline is not None: shared.sd_model = orig_pipeline orig_pipeline = None + return shared.sd_model.__class__ diff --git a/scripts/animatediff.py b/scripts/animatediff.py index 6c29f3fa5..f44c85bb7 100644 --- a/scripts/animatediff.py +++ b/scripts/animatediff.py @@ -182,7 +182,7 @@ def set_free_init(method, iters, order, spatial, temporal): def set_free_noise(frames): context_length = 16 context_stride = 4 - if frames >= context_length: + if frames >= context_length and hasattr(shared.sd_model, 'enable_free_noise'): shared.log.debug(f'AnimateDiff free noise: frames={frames} context={context_length} stride={context_stride}') shared.sd_model.enable_free_noise(context_length=context_length, context_stride=context_stride)