mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
Fixed guidance end
This commit is contained in:
@@ -93,15 +93,28 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = {}
|
||||
if step != getattr(pipe, 'num_timesteps', 0):
|
||||
kwargs = processing_correction.correction_callback(p, timestep, kwargs, initial=step == 0)
|
||||
kwargs = prompt_callback(step, kwargs) # monkey patch for diffusers callback issues
|
||||
if step == int(getattr(pipe, 'num_timesteps', 100) * p.cfg_end) and 'prompt_embeds' in kwargs and 'negative_prompt_embeds' in kwargs:
|
||||
|
||||
if step == 0:
|
||||
setattr(pipe, "_cfg_end_applied", False)
|
||||
|
||||
cfg_end = getattr(p, "cfg_end", 1.0) or 1.0
|
||||
total_steps = getattr(pipe, "num_timesteps", 0)
|
||||
target_step = int(total_steps * cfg_end) if total_steps else 0
|
||||
if (
|
||||
cfg_end < 1.0
|
||||
and not getattr(pipe, "_cfg_end_applied", False)
|
||||
and step >= target_step
|
||||
):
|
||||
setattr(pipe, "_cfg_end_applied", True)
|
||||
if "PAG" in shared.sd_model.__class__.__name__:
|
||||
pipe._guidance_scale = 1.001 if pipe._guidance_scale > 1 else pipe._guidance_scale # pylint: disable=protected-access
|
||||
pipe._pag_scale = 0.001 # pylint: disable=protected-access
|
||||
else:
|
||||
pipe._guidance_scale = 0.0 # pylint: disable=protected-access
|
||||
for key in {"prompt_embeds", "negative_prompt_embeds", "add_text_embeds", "add_time_ids"} & set(kwargs):
|
||||
if kwargs[key] is not None:
|
||||
kwargs[key] = kwargs[key].chunk(2)[-1]
|
||||
for key in {"prompt_embeds", "negative_prompt_embeds", "add_text_embeds", "add_time_ids"}:
|
||||
tensor = kwargs.get(key, None)
|
||||
if tensor is not None and hasattr(tensor, "chunk") and tensor.shape[0] % 2 == 0:
|
||||
kwargs[key] = tensor.chunk(2)[-1]
|
||||
try:
|
||||
current_noise_pred = kwargs.get("noise_pred", None)
|
||||
if current_noise_pred is None:
|
||||
|
||||
Reference in New Issue
Block a user