mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
Merge pull request #3153 from AI-Casanova/CFGend
Fix Guidance (CFG & PAG) End for PAG Pipelines
This commit is contained in:
@@ -144,6 +144,7 @@
|
||||
{"id":"","label":"Batch count","localized":"","hint":"How many batches of images to create (has no impact on generation performance or VRAM usage)"},
|
||||
{"id":"","label":"Batch size","localized":"","hint":"How many image to create in a single batch (increases generation performance at cost of higher VRAM usage)"},
|
||||
{"id":"","label":"cfg scale","localized":"","hint":"Classifier Free Guidance scale: how strongly the image should conform to prompt. Lower values produce more creative results, higher values make it follow the prompt more strictly; recommended values between 5-10"},
|
||||
{"id":"","label":"Guidance End","localized":"","hint":"Ends the effect of CFG and PAG early: A value of 1 acts as normal, 0.5 stops guidance at 50% of steps"},
|
||||
{"id":"","label":"CLIP skip","localized":"","hint":"Clip skip is a feature that allows users to control the level of specificity of the prompt, the higher the CLIP skip value, the less deep the prompt will be interpreted. CLIP Skip 1 is typical while some anime models produce better results at CLIP skip 2"},
|
||||
{"id":"","label":"Initial seed","localized":"","hint":"A value that determines the output of random number generator - if you create an image with same parameters and seed as another image, you'll get the same result"},
|
||||
{"id":"","label":"Variation","localized":"","hint":"Second seed to be mixed with primary seed"},
|
||||
|
||||
@@ -76,9 +76,13 @@ def diffusers_callback(pipe, step: int, timestep: int, kwargs: dict):
|
||||
except Exception as e:
|
||||
shared.log.debug(f"Callback: {e}")
|
||||
if step == int(getattr(pipe, 'num_timesteps', 100) * p.cfg_end) and 'prompt_embeds' in kwargs and 'negative_prompt_embeds' in kwargs:
|
||||
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):
|
||||
kwargs[key] = kwargs[key].chunk(2)[-1]
|
||||
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):
|
||||
kwargs[key] = kwargs[key].chunk(2)[-1]
|
||||
shared.state.current_latent = kwargs['latents']
|
||||
if shared.cmd_opts.profile and shared.profiler is not None:
|
||||
shared.profiler.step()
|
||||
|
||||
@@ -153,7 +153,7 @@ def create_options(tab):
|
||||
def create_cfg_inputs(tab):
|
||||
with gr.Row():
|
||||
cfg_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.1, label='CFG scale', value=6.0, elem_id=f"{tab}_cfg_scale")
|
||||
cfg_end = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='CFG end', value=1.0, elem_id=f"{tab}_cfg_end")
|
||||
cfg_end = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='Guidance end', value=1.0, elem_id=f"{tab}_cfg_end")
|
||||
return cfg_scale, cfg_end
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -234,7 +234,7 @@ axis_options = [
|
||||
AxisOption("Seed", int, apply_field("seed")),
|
||||
AxisOption("Steps", int, apply_field("steps")),
|
||||
AxisOption("CFG Scale", float, apply_field("cfg_scale")),
|
||||
AxisOption("CFG End", float, apply_field("cfg_end")),
|
||||
AxisOption("Guidance End", float, apply_field("cfg_end")),
|
||||
AxisOption("Variation seed", int, apply_field("subseed")),
|
||||
AxisOption("Variation strength", float, apply_field("subseed_strength")),
|
||||
AxisOption("Clip skip", float, apply_clip_skip),
|
||||
|
||||
Reference in New Issue
Block a user