mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
- all guidance values set to -1 to enable using model defaults
- log default values used if not overriden by user - rename inconsistent guidance variables: p.cfg_scale p.image_cfg_scale -> p.cfg_image p.diffusers_guidance_rescale -> p.cfg_rescale p.pag_scale -> p.cfg_true p.pag_adaptive -> p.cfg_adaptive Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
- **Models**
|
||||
- [CircleStone Anima 1.0](https://huggingface.co/circlestone-labs/Anima) in *Base* and *Turbo* (distilled) variants
|
||||
in both original precision and SDNQ-4bit quantiztion
|
||||
- **Changes**
|
||||
- all **Guidance** params are now set to *-1* by default to allow using model defaults and avoid confusion with different model behaviour
|
||||
log will print default values used by model if not set by user
|
||||
- **Features**
|
||||
- **Captioning** new feature: analyze existing images for prompt adherence
|
||||
*tip*: image analysis requires larger VLM model to produce quality output
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"variant": "bf16",
|
||||
"desc": "Stable Cascade is a diffusion model built upon the Würstchen architecture and its main difference to other models like Stable Diffusion is that it is working at a much smaller latent space. Why is this important? The smaller the latent space, the faster you can run inference and the cheaper the training becomes. How small is the latent space? Stable Diffusion uses a compression factor of 8, resulting in a 1024x1024 image being encoded to 128x128. Stable Cascade achieves a compression factor of 42, meaning that it is possible to encode a 1024x1024 image to 24x24, while maintaining crisp reconstructions. The text-conditional model is then trained in the highly compressed latent space. Previous versions of this architecture, achieved a 16x cost reduction over Stable Diffusion 1.5",
|
||||
"preview": "stabilityai--stable-cascade-lite.jpg",
|
||||
"extras": "sampler: Default, cfg_scale: 4.0, image_cfg_scale: 1.0",
|
||||
"extras": "sampler: Default, cfg_scale: 4.0, cfg_image: 1.0",
|
||||
"size": 4.97,
|
||||
"tags": "distilled",
|
||||
"date": "2024 February"
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@
|
||||
"variant": "bf16",
|
||||
"desc": "Stable Cascade is a diffusion model built upon the W\u00fcrstchen architecture and its main difference to other models like Stable Diffusion is that it is working at a much smaller latent space. Why is this important? The smaller the latent space, the faster you can run inference and the cheaper the training becomes. How small is the latent space? Stable Diffusion uses a compression factor of 8, resulting in a 1024x1024 image being encoded to 128x128. Stable Cascade achieves a compression factor of 42, meaning that it is possible to encode a 1024x1024 image to 24x24, while maintaining crisp reconstructions. The text-conditional model is then trained in the highly compressed latent space. Previous versions of this architecture, achieved a 16x cost reduction over Stable Diffusion 1.5",
|
||||
"preview": "stabilityai--stable-cascade.jpg",
|
||||
"extras": "sampler: Default, cfg_scale: 4.0, image_cfg_scale: 1.0",
|
||||
"extras": "sampler: Default, cfg_scale: 4.0, cfg_image: 1.0",
|
||||
"size": 11.82,
|
||||
"date": "2024 February"
|
||||
},
|
||||
@@ -823,7 +823,7 @@
|
||||
"path": "warp-ai/wuerstchen",
|
||||
"desc": "W\u00fcrstchen is a diffusion model whose text-conditional model works in a highly compressed latent space of images. Why is this important? Compressing data can reduce computational costs for both training and inference by magnitudes. Training on 1024x1024 images, is way more expensive than training at 32x32. Usually, other works make use of a relatively small compression, in the range of 4x - 8x spatial compression. W\u00fcrstchen takes this to an extreme. Through its novel design, we achieve a 42x spatial compression. W\u00fcrstchen employs a two-stage compression, what we call Stage A and Stage B. Stage A is a VQGAN, and Stage B is a Diffusion Autoencoder (more details can be found in the paper). A third model, Stage C, is learned in that highly compressed latent space. This training requires fractions of the compute used for current top-performing models, allowing also cheaper and faster inference.",
|
||||
"preview": "warp-ai--wuerstchen.jpg",
|
||||
"extras": "sampler: Default, cfg_scale: 4.0, image_cfg_scale: 0.0",
|
||||
"extras": "sampler: Default, cfg_scale: 4.0, cfg_image: 0.0",
|
||||
"size": 12.16,
|
||||
"date": "2023 August"
|
||||
},
|
||||
|
||||
@@ -383,7 +383,7 @@ def civitai_meta_to_parameters(meta: dict | None) -> str:
|
||||
(('Size',), 'Size'),
|
||||
(('Model',), 'Model'),
|
||||
(('Model hash', 'modelHash'), 'Model hash'),
|
||||
(('clipSkip', 'clip_skip', 'Clip skip'), 'Clip skip'),
|
||||
(('clipSkip', 'clip_skip', 'CLiP-skip'), 'CLiP-skip'),
|
||||
(('denoisingStrength', 'Denoising strength'), 'Denoising strength'),
|
||||
]
|
||||
consumed = {'prompt', 'negativeprompt', 'negative_prompt'}
|
||||
|
||||
@@ -344,7 +344,7 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg
|
||||
steps: int = 20, sampler_index: int | None = None,
|
||||
seed: int = -1, subseed: int = -1, subseed_strength: float = 0, seed_resize_from_h: int = -1, seed_resize_from_w: int = -1,
|
||||
guidance_name: str = 'Default', guidance_scale: float = 6.0, guidance_rescale: float = 0.0, guidance_start: float = 0.0, guidance_stop: float = 1.0,
|
||||
cfg_scale: float = 6.0, clip_skip: float = 1.0, image_cfg_scale: float = 6.0, diffusers_guidance_rescale: float = 0.7, pag_scale: float = 0.0, pag_adaptive: float = 0.5, cfg_end: float = 1.0,
|
||||
cfg_scale: float = 6.0, clip_skip: float = 1.0, cfg_image: float = 6.0, cfg_rescale: float = 0.7, cfg_true: float = 0.0, cfg_adaptive: float = 0.5, cfg_end: float = 1.0,
|
||||
vae_type: str = 'Full', tiling: bool = False, hidiffusion: bool = False,
|
||||
detailer_enabled: bool = False, detailer_prompt: str = '', detailer_negative: str = '', detailer_steps: int = 10, detailer_strength: float = 0.3, detailer_resolution: int = 1024,
|
||||
hdr_mode: int = 0, hdr_brightness: float = 0, hdr_color: float = 0, hdr_sharpen: float = 0, hdr_clamp: bool = False, hdr_boundary: float = 4.0, hdr_threshold: float = 0.95,
|
||||
@@ -470,10 +470,10 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg
|
||||
cfg_scale = cfg_scale,
|
||||
cfg_end = cfg_end,
|
||||
clip_skip = clip_skip,
|
||||
image_cfg_scale = image_cfg_scale,
|
||||
diffusers_guidance_rescale = diffusers_guidance_rescale,
|
||||
pag_scale = pag_scale,
|
||||
pag_adaptive = pag_adaptive,
|
||||
cfg_image = cfg_image,
|
||||
cfg_rescale = cfg_rescale,
|
||||
cfg_true = cfg_true,
|
||||
cfg_adaptive = cfg_adaptive,
|
||||
# advanced
|
||||
vae_type = vae_type,
|
||||
tiling = tiling,
|
||||
|
||||
@@ -101,7 +101,7 @@ def parse_novelai_metadata(data: dict):
|
||||
try:
|
||||
dct = json.loads(data["Comment"])
|
||||
sampler = sd_samplers.samplers_map.get(dct["sampler"], "Euler a")
|
||||
geninfo = f'{data["Description"]} Negative prompt: {dct["uc"]} Steps: {dct["steps"]}, Sampler: {sampler}, CFG scale: {dct["scale"]}, Seed: {dct["seed"]}, Clip skip: 2, ENSD: 31337'
|
||||
geninfo = f'{data["Description"]} Negative prompt: {dct["uc"]} Steps: {dct["steps"]}, Sampler: {sampler}, CFG scale: {dct["scale"]}, Seed: {dct["seed"]}, CLiP-skip: 2, ENSD: 31337'
|
||||
debug(f'Metadata: novelai="{geninfo}"')
|
||||
return geninfo
|
||||
except Exception:
|
||||
|
||||
@@ -58,7 +58,7 @@ class FilenameGenerator:
|
||||
'seed': lambda self: (hasattr(self, "seed") and self.seed and str(self.seed)) or '',
|
||||
'steps': lambda self: self.p and getattr(self.p, 'steps', 0),
|
||||
'cfg': lambda self: self.p and getattr(self.p, 'cfg_scale', 0),
|
||||
'pag': lambda self: self.p and getattr(self.p, 'pag_scale', 0),
|
||||
'pag': lambda self: self.p and getattr(self.p, 'cfg_true', 0),
|
||||
'clip_skip': lambda self: self.p and getattr(self.p, 'clip_skip', 0),
|
||||
'denoising': lambda self: self.p and getattr(self.p, 'denoising_strength', 0),
|
||||
'styles': lambda self: (self.p and ", ".join([style for style in self.p.styles if not style == "None"])) or "None",
|
||||
|
||||
+5
-5
@@ -164,7 +164,7 @@ def img2img(id_task: str, state: str, mode: int,
|
||||
detailer_enabled, detailer_prompt, detailer_negative, detailer_steps, detailer_strength, detailer_resolution,
|
||||
n_iter, batch_size,
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop,
|
||||
cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end,
|
||||
cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end,
|
||||
refiner_start,
|
||||
clip_skip,
|
||||
denoising_strength,
|
||||
@@ -286,10 +286,10 @@ def img2img(id_task: str, state: str, mode: int,
|
||||
resize_context=resize_context,
|
||||
scale_by=scale_by,
|
||||
denoising_strength=denoising_strength,
|
||||
image_cfg_scale=image_cfg_scale,
|
||||
diffusers_guidance_rescale=diffusers_guidance_rescale,
|
||||
pag_scale=pag_scale,
|
||||
pag_adaptive=pag_adaptive,
|
||||
cfg_image=cfg_image,
|
||||
cfg_rescale=cfg_rescale,
|
||||
cfg_true=cfg_true,
|
||||
cfg_adaptive=cfg_adaptive,
|
||||
refiner_start=refiner_start,
|
||||
inpaint_full_res=inpaint_full_res != 0,
|
||||
inpaint_full_res_padding=inpaint_full_res_padding,
|
||||
|
||||
@@ -467,7 +467,7 @@ def run_ltx(task_id,
|
||||
'callback_on_step_end': diffusers_callback,
|
||||
'output_type': 'pil',
|
||||
}
|
||||
if p.cfg_scale is not None and p.cfg_scale > 0:
|
||||
if p.cfg_scale is not None and p.cfg_scale > -1:
|
||||
refine_args['guidance_scale'] = p.cfg_scale
|
||||
if caps.supports_frame_rate_kwarg:
|
||||
refine_args['frame_rate'] = float(mp4_fps)
|
||||
|
||||
@@ -14,7 +14,7 @@ def apply(p: processing.StableDiffusionProcessing): # pylint: disable=arguments-
|
||||
cls = shared.sd_model.__class__ if shared.sd_loaded else None
|
||||
if cls == StableDiffusionPAGPipeline or cls == StableDiffusionXLPAGPipeline:
|
||||
cls = unapply()
|
||||
if p.pag_scale == 0:
|
||||
if p.cfg_true == 0:
|
||||
return
|
||||
if cls is not None and 'PAG' in cls.__name__:
|
||||
pass
|
||||
@@ -31,20 +31,20 @@ def apply(p: processing.StableDiffusionProcessing): # pylint: disable=arguments-
|
||||
orig_pipeline = shared.sd_model
|
||||
shared.sd_model = sd_models.switch_pipe(StableDiffusionXLPAGPipeline, shared.sd_model)
|
||||
elif detect.is_f1(cls):
|
||||
p.task_args['true_cfg_scale'] = p.pag_scale
|
||||
p.task_args['true_cfg_scale'] = p.cfg_true
|
||||
else:
|
||||
# log.warning(f'PAG: pipeline={cls.__name__} required={StableDiffusionPipeline.__name__}')
|
||||
return None
|
||||
|
||||
p.task_args['pag_scale'] = p.pag_scale
|
||||
p.task_args['pag_adaptive_scaling'] = p.pag_adaptive
|
||||
p.task_args['pag_adaptive_scale'] = p.pag_adaptive
|
||||
p.task_args['cfg_true'] = p.cfg_true
|
||||
p.task_args['cfg_adaptive_scaling'] = p.cfg_adaptive
|
||||
p.task_args['cfg_adaptive_scale'] = p.cfg_adaptive
|
||||
pag_applied_layers = shared.opts.pag_apply_layers
|
||||
pag_applied_layers_index = pag_applied_layers.split() if len(pag_applied_layers) > 0 else []
|
||||
pag_applied_layers_index = [p.strip() for p in pag_applied_layers_index]
|
||||
p.task_args['pag_applied_layers_index'] = pag_applied_layers_index if len(pag_applied_layers_index) > 0 else ['m0'] # Available layers: d[0-5], m[0], u[0-8]
|
||||
p.extra_generation_params["CFG true"] = p.pag_scale
|
||||
p.extra_generation_params["CFG adaptive"] = p.pag_adaptive
|
||||
p.extra_generation_params["CFG true"] = p.cfg_true
|
||||
p.extra_generation_params["CFG adaptive"] = p.cfg_adaptive
|
||||
# log.debug(f'{c}: args={p.task_args}')
|
||||
|
||||
|
||||
|
||||
+17
-17
@@ -1034,20 +1034,20 @@ class StableDiffusionPAGPipeline(
|
||||
return self._interrupt
|
||||
|
||||
@property
|
||||
def pag_scale(self):
|
||||
return self._pag_scale
|
||||
def cfg_true(self):
|
||||
return self._cfg_true
|
||||
|
||||
@property
|
||||
def do_perturbed_attention_guidance(self):
|
||||
return self._pag_scale > 0
|
||||
return self._cfg_true > 0
|
||||
|
||||
@property
|
||||
def pag_adaptive_scaling(self):
|
||||
return self._pag_adaptive_scaling
|
||||
def cfg_adaptive_scaling(self):
|
||||
return self._cfg_adaptive_scaling
|
||||
|
||||
@property
|
||||
def do_pag_adaptive_scaling(self):
|
||||
return self._pag_adaptive_scaling > 0
|
||||
def do_cfg_adaptive_scaling(self):
|
||||
return self._cfg_adaptive_scaling > 0
|
||||
|
||||
@property
|
||||
def pag_applied_layers_index(self):
|
||||
@@ -1063,8 +1063,8 @@ class StableDiffusionPAGPipeline(
|
||||
num_inference_steps: int = 50,
|
||||
timesteps: List[int] | None = None,
|
||||
guidance_scale: float = 7.5,
|
||||
pag_scale: float = 0.0,
|
||||
pag_adaptive_scaling: float = 0.0,
|
||||
cfg_true: float = 0.0,
|
||||
cfg_adaptive_scaling: float = 0.0,
|
||||
pag_applied_layers_index: List[str] = ["d4"], # ['d4', 'd5', 'm0']
|
||||
negative_prompt: Optional[Union[str, List[str]]] = None,
|
||||
num_images_per_prompt: Optional[int] = 1,
|
||||
@@ -1202,8 +1202,8 @@ class StableDiffusionPAGPipeline(
|
||||
self._cross_attention_kwargs = cross_attention_kwargs
|
||||
self._interrupt = False
|
||||
|
||||
self._pag_scale = pag_scale
|
||||
self._pag_adaptive_scaling = pag_adaptive_scaling
|
||||
self._cfg_true = cfg_true
|
||||
self._cfg_adaptive_scaling = cfg_adaptive_scaling
|
||||
self._pag_applied_layers_index = pag_applied_layers_index
|
||||
|
||||
# 2. Define call parameters
|
||||
@@ -1372,9 +1372,9 @@ class StableDiffusionPAGPipeline(
|
||||
elif not self.do_classifier_free_guidance and self.do_perturbed_attention_guidance:
|
||||
noise_pred_original, noise_pred_perturb = noise_pred.chunk(2)
|
||||
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000 - t)
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000 - t)
|
||||
if signal_scale < 0:
|
||||
signal_scale = 0
|
||||
|
||||
@@ -1384,9 +1384,9 @@ class StableDiffusionPAGPipeline(
|
||||
elif self.do_classifier_free_guidance and self.do_perturbed_attention_guidance:
|
||||
noise_pred_uncond, noise_pred_text, noise_pred_text_perturb = noise_pred.chunk(3)
|
||||
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000 - t)
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000 - t)
|
||||
if signal_scale < 0:
|
||||
signal_scale = 0
|
||||
|
||||
|
||||
+17
-17
@@ -1048,20 +1048,20 @@ class StableDiffusionXLPAGPipeline(
|
||||
return self._interrupt
|
||||
|
||||
@property
|
||||
def pag_scale(self):
|
||||
return self._pag_scale
|
||||
def cfg_true(self):
|
||||
return self._cfg_true
|
||||
|
||||
@property
|
||||
def do_adversarial_guidance(self):
|
||||
return self._pag_scale > 0
|
||||
return self._cfg_true > 0
|
||||
|
||||
@property
|
||||
def pag_adaptive_scaling(self):
|
||||
return self._pag_adaptive_scaling
|
||||
def cfg_adaptive_scaling(self):
|
||||
return self._cfg_adaptive_scaling
|
||||
|
||||
@property
|
||||
def do_pag_adaptive_scaling(self):
|
||||
return self._pag_adaptive_scaling > 0
|
||||
def do_cfg_adaptive_scaling(self):
|
||||
return self._cfg_adaptive_scaling > 0
|
||||
|
||||
@property
|
||||
def pag_drop_rate(self):
|
||||
@@ -1087,8 +1087,8 @@ class StableDiffusionXLPAGPipeline(
|
||||
timesteps: List[int] | None = None,
|
||||
denoising_end: Optional[float] = None,
|
||||
guidance_scale: float = 5.0,
|
||||
pag_scale: float = 0.0,
|
||||
pag_adaptive_scaling: float = 0.0,
|
||||
cfg_true: float = 0.0,
|
||||
cfg_adaptive_scaling: float = 0.0,
|
||||
pag_drop_rate: float = 0.5,
|
||||
pag_applied_layers: List[str] = ['mid'], #['down', 'mid', 'up']
|
||||
pag_applied_layers_index: List[str] | None = None, #['d4', 'd5', 'm0']
|
||||
@@ -1308,8 +1308,8 @@ class StableDiffusionXLPAGPipeline(
|
||||
self._denoising_end = denoising_end
|
||||
self._interrupt = False
|
||||
|
||||
self._pag_scale = pag_scale
|
||||
self._pag_adaptive_scaling = pag_adaptive_scaling
|
||||
self._cfg_true = cfg_true
|
||||
self._cfg_adaptive_scaling = cfg_adaptive_scaling
|
||||
self._pag_drop_rate = pag_drop_rate
|
||||
self._pag_applied_layers = pag_applied_layers
|
||||
self._pag_applied_layers_index = pag_applied_layers_index
|
||||
@@ -1556,9 +1556,9 @@ class StableDiffusionXLPAGPipeline(
|
||||
elif not self.do_classifier_free_guidance and self.do_adversarial_guidance:
|
||||
noise_pred_original, noise_pred_perturb = noise_pred.chunk(2)
|
||||
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000-t)
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000-t)
|
||||
if signal_scale<0:
|
||||
signal_scale = 0
|
||||
|
||||
@@ -1569,9 +1569,9 @@ class StableDiffusionXLPAGPipeline(
|
||||
|
||||
noise_pred_uncond, noise_pred_text, noise_pred_text_perturb = noise_pred.chunk(3)
|
||||
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000-t)
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000-t)
|
||||
if signal_scale<0:
|
||||
signal_scale = 0
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ class Processed:
|
||||
self.height = p.height if hasattr(p, 'height') else (self.images[0].height if len(self.images) > 0 else 0)
|
||||
|
||||
self.sampler_name = p.sampler_name or ''
|
||||
self.cfg_scale = p.cfg_scale if p.cfg_scale > 1 else None
|
||||
self.cfg_scale = p.cfg_scale if p.cfg_scale > -1 else None
|
||||
self.cfg_end = p.cfg_end if p.cfg_end < 1 else None
|
||||
self.image_cfg_scale = p.image_cfg_scale or 0
|
||||
self.cfg_image = p.cfg_image if p.cfg_image > -1 else None
|
||||
self.steps = p.steps or 0
|
||||
self.batch_size = max(1, p.batch_size)
|
||||
self.denoising_strength = p.denoising_strength
|
||||
|
||||
+27
-10
@@ -179,6 +179,18 @@ def get_params(model):
|
||||
return possible
|
||||
|
||||
|
||||
def get_defaults(model, kwargs):
|
||||
remove = ['return_dict', 'output_type', 'num_images_per_prompt', 'callback', 'callback_on_step_end_tensor_inputs']
|
||||
try:
|
||||
signature = inspect.signature(type(model).__call__, follow_wrapped=True)
|
||||
defaults = {k: v.default for k, v in signature.parameters.items() if v.default is not inspect.Parameter.empty and v.default is not None} # get all defaults
|
||||
defaults = {k: v for k, v in defaults.items() if k not in kwargs} # only log defaults that are not already set by kwargs
|
||||
defaults = {k: v for k, v in defaults.items() if k not in remove} # remove common args that are not useful to log
|
||||
log.debug(f'Pipeline: cls={model.__class__.__name__} defaults={defaults}')
|
||||
except Exception as e:
|
||||
log.error(f'Pipeline defaults: {e}')
|
||||
|
||||
|
||||
def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:list | None=None, negative_prompts_2:list | None=None, prompt_attention:str | None=None, desc:str | None='', **kwargs):
|
||||
t0 = time.time()
|
||||
shared.sd_model = sd_models.apply_balanced_offload(shared.sd_model)
|
||||
@@ -245,17 +257,20 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:l
|
||||
if hasattr(model, 'scheduler') and hasattr(model.scheduler, 'noise_sampler_seed') and hasattr(model.scheduler, 'noise_sampler'):
|
||||
model.scheduler.noise_sampler = None # noise needs to be reset instead of using cached values
|
||||
model.scheduler.noise_sampler_seed = p.seeds # some schedulers have internal noise generator and do not use pipeline generator
|
||||
if 'seed' in possible and p.seed is not None:
|
||||
|
||||
if ('seed' in possible) and (p.seed is not None) and (p.seed > -1):
|
||||
args['seed'] = p.seed
|
||||
if 'noise_sampler_seed' in possible and p.seeds is not None:
|
||||
if ('noise_sampler_seed' in possible) and (p.seeds is not None):
|
||||
args['noise_sampler_seed'] = p.seeds
|
||||
if 'guidance_scale' in possible and p.cfg_scale is not None and p.cfg_scale > 0:
|
||||
if ('guidance_scale' in possible) and (p.cfg_scale is not None) and (p.cfg_scale > -1):
|
||||
args['guidance_scale'] = p.cfg_scale
|
||||
if 'img_guidance_scale' in possible and hasattr(p, 'image_cfg_scale') and p.image_cfg_scale is not None and p.image_cfg_scale > 0:
|
||||
args['img_guidance_scale'] = p.image_cfg_scale
|
||||
if ('img_guidance_scale' in possible) and hasattr(p, 'cfg_image') and (p.cfg_image is not None) and (p.cfg_image > -1):
|
||||
args['img_guidance_scale'] = p.cfg_image
|
||||
|
||||
if getattr(getattr(model, 'config', None), 'is_distilled', False) and args.get('guidance_scale', 0) > 1 and not getattr(p, 'distilled_warned', False):
|
||||
log.warning(f'Pipeline: cls={model.__class__.__name__} distilled=True cfg_scale={args["guidance_scale"]} ignored, forced to 1')
|
||||
p.distilled_warned = True
|
||||
|
||||
if 'generator' in possible:
|
||||
generator = get_generator(p)
|
||||
args['generator'] = generator
|
||||
@@ -272,15 +287,14 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:l
|
||||
if 'Kandinsky' in model.__class__.__name__ or 'Cosmos2' in model.__class__.__name__ or 'OmniGen2' in model.__class__.__name__:
|
||||
kwargs['output_type'] = 'np' # only set latent if model has vae
|
||||
if 'StableCascade' in model.__class__.__name__:
|
||||
kwargs.pop("guidance_scale") # remove
|
||||
kwargs.pop("num_inference_steps") # remove
|
||||
if 'prior_num_inference_steps' in possible:
|
||||
args["prior_num_inference_steps"] = p.steps
|
||||
args["num_inference_steps"] = p.refiner_steps
|
||||
if 'prior_guidance_scale' in possible:
|
||||
if 'prior_guidance_scale' in possible and (p.cfg_scale is not None) and (p.cfg_scale > -1):
|
||||
args["prior_guidance_scale"] = p.cfg_scale
|
||||
if 'decoder_guidance_scale' in possible:
|
||||
args["decoder_guidance_scale"] = p.image_cfg_scale
|
||||
if 'decoder_guidance_scale' in possible and (p.cfg_image is not None) and (p.cfg_image > -1):
|
||||
args["decoder_guidance_scale"] = p.cfg_image
|
||||
if 'Flex2' in model.__class__.__name__:
|
||||
if len(getattr(p, 'init_images', [])) > 0:
|
||||
args['inpaint_image'] = p.init_images[0] if isinstance(p.init_images, list) else p.init_images
|
||||
@@ -334,13 +348,14 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:l
|
||||
if type(kwargs[arg]) == float or type(kwargs[arg]) == int:
|
||||
if kwargs[arg] <= -1: # skip -1 as default value
|
||||
continue
|
||||
if kwargs[arg] is None: # skip None values
|
||||
continue
|
||||
args[arg] = kwargs[arg]
|
||||
|
||||
# optional preprocess
|
||||
if hasattr(model, 'preprocess') and callable(model.preprocess):
|
||||
model.preprocess(p, args)
|
||||
|
||||
|
||||
# handle task specific args
|
||||
if sd_models.get_diffusers_task(model) == sd_models.DiffusersTaskType.MODULAR:
|
||||
task_kwargs = task_modular_kwargs(p, model)
|
||||
@@ -402,6 +417,8 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:l
|
||||
|
||||
sd_hijack_hypertile.hypertile_set(p, hr=len(getattr(p, 'init_images', [])) > 0)
|
||||
|
||||
get_defaults(model, args)
|
||||
|
||||
# debug info
|
||||
clean = args.copy()
|
||||
clean.pop('cross_attention_kwargs', None)
|
||||
|
||||
@@ -117,7 +117,7 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict | No
|
||||
pipe._cfg_end_applied = True # pylint: disable=protected-access
|
||||
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
|
||||
pipe._cfg_true = 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"]:
|
||||
|
||||
@@ -48,9 +48,9 @@ class StableDiffusionProcessing:
|
||||
# legacy guidance
|
||||
cfg_scale: float = 6.0,
|
||||
cfg_end: float = 1,
|
||||
diffusers_guidance_rescale: float = 0.0,
|
||||
pag_scale: float = 0.0,
|
||||
pag_adaptive: float = 0.5,
|
||||
cfg_rescale: float = 0.0,
|
||||
cfg_true: float = 0.0,
|
||||
cfg_adaptive: float = 0.5,
|
||||
# styles
|
||||
styles: list[str] | None = None,
|
||||
# vae
|
||||
@@ -151,7 +151,7 @@ class StableDiffusionProcessing:
|
||||
denoising_strength: float = 0.3,
|
||||
init_images: list | None = None,
|
||||
init_control: list | None = None,
|
||||
image_cfg_scale: float | None = None,
|
||||
cfg_image: float | None = None,
|
||||
initial_noise_multiplier: float | None = None, # pylint: disable=unused-argument # a1111 compatibility
|
||||
# resize
|
||||
scale_by: float = 1,
|
||||
@@ -400,7 +400,7 @@ class StableDiffusionProcessing:
|
||||
self.resize_name = resize_name
|
||||
self.resize_context = resize_context
|
||||
self.denoising_strength = denoising_strength
|
||||
self.image_cfg_scale = image_cfg_scale
|
||||
self.cfg_image = cfg_image
|
||||
self.scale_by = scale_by
|
||||
self.mask = mask
|
||||
self.image_mask = mask # TODO processing: remove duplicate mask params
|
||||
@@ -465,9 +465,9 @@ class StableDiffusionProcessing:
|
||||
self.guidance_stop = guidance_stop
|
||||
self.cfg_scale = cfg_scale
|
||||
self.cfg_end = cfg_end
|
||||
self.diffusers_guidance_rescale = diffusers_guidance_rescale
|
||||
self.pag_scale = pag_scale
|
||||
self.pag_adaptive = pag_adaptive
|
||||
self.cfg_rescale = cfg_rescale
|
||||
self.cfg_true = cfg_true
|
||||
self.cfg_adaptive = cfg_adaptive
|
||||
self.selected_scale_tab = selected_scale_tab
|
||||
self.mask_for_overlay = mask_for_overlay
|
||||
self.paste_to = paste_to
|
||||
|
||||
@@ -156,9 +156,9 @@ def process_base(p: processing.StableDiffusionProcessing):
|
||||
negative_prompts_2=[p.refiner_negative] if len(p.refiner_negative) > 0 else p.negative_prompts,
|
||||
num_inference_steps=calculate_base_steps(p, use_refiner_start=use_refiner_start, use_denoise_start=use_denoise_start),
|
||||
eta=sched_eta,
|
||||
guidance_scale=p.cfg_scale,
|
||||
guidance_rescale=p.diffusers_guidance_rescale,
|
||||
true_cfg_scale=p.pag_scale,
|
||||
guidance_scale=p.cfg_scale if p.cfg_scale is not None and p.cfg_scale > -1 else None,
|
||||
guidance_rescale=p.cfg_rescale if p.cfg_rescale is not None and p.cfg_rescale > -1 else None,
|
||||
true_cfg_scale=p.cfg_true if p.cfg_true is not None and p.cfg_true > -1 else None,
|
||||
denoising_start=0 if use_refiner_start else p.refiner_start if use_denoise_start else None,
|
||||
denoising_end=p.refiner_start if use_refiner_start else 1 if use_denoise_start else None,
|
||||
num_frames=getattr(p, 'frames', 1),
|
||||
@@ -323,8 +323,9 @@ def process_hires(p: processing.StableDiffusionProcessing, output):
|
||||
negative_prompts_2=len(output.images) * [p.refiner_negative] if len(p.refiner_negative) > 0 else p.negative_prompts,
|
||||
num_inference_steps=calculate_hires_steps(p),
|
||||
eta=sched_eta,
|
||||
guidance_scale=p.image_cfg_scale if p.image_cfg_scale is not None else p.cfg_scale,
|
||||
guidance_rescale=p.diffusers_guidance_rescale,
|
||||
guidance_scale=p.cfg_image if p.cfg_image is not None and p.cfg_image > -1 else p.cfg_scale,
|
||||
guidance_rescale=p.cfg_rescale if p.cfg_rescale is not None and p.cfg_rescale > -1 else None,
|
||||
true_cfg_scale=p.cfg_true if p.cfg_true is not None and p.cfg_true > -1 else None,
|
||||
output_type=output_type,
|
||||
clip_skip=p.clip_skip,
|
||||
image=output.images,
|
||||
@@ -411,8 +412,9 @@ def process_refine(p: processing.StableDiffusionProcessing, output):
|
||||
num_inference_steps=calculate_refiner_steps(p),
|
||||
eta=sched_eta,
|
||||
noise_level=noise_level, # StableDiffusionUpscalePipeline only
|
||||
guidance_scale=p.image_cfg_scale if p.image_cfg_scale is not None else p.cfg_scale,
|
||||
guidance_rescale=p.diffusers_guidance_rescale,
|
||||
guidance_scale=p.cfg_image if p.cfg_image is not None and p.cfg_image > -1 else p.cfg_scale,
|
||||
guidance_rescale=p.cfg_rescale if p.cfg_rescale is not None and p.cfg_rescale > -1 else None,
|
||||
true_cfg_scale=p.cfg_true if p.cfg_true is not None and p.cfg_true > -1 else None,
|
||||
denoising_start=p.refiner_start if p.refiner_start > 0 and p.refiner_start < 1 else None,
|
||||
denoising_end=1 if p.refiner_start > 0 and p.refiner_start < 1 else None,
|
||||
image=image,
|
||||
|
||||
+10
-10
@@ -50,12 +50,12 @@ def create_infotext(p: StableDiffusionProcessing, all_prompts=None, all_seeds=No
|
||||
"Scheduler": shared.sd_model.scheduler.__class__.__name__ if getattr(shared.sd_model, 'scheduler', None) is not None else None,
|
||||
"Seed": all_seeds[index],
|
||||
"Seed resize from": None if p.seed_resize_from_w <= 0 or p.seed_resize_from_h <= 0 else f"{p.seed_resize_from_w}x{p.seed_resize_from_h}",
|
||||
"CFG scale": p.cfg_scale if p.cfg_scale > 1.0 else 1.0,
|
||||
"CFG rescale": p.diffusers_guidance_rescale if p.diffusers_guidance_rescale > 0 else None,
|
||||
"CFG scale": p.cfg_scale if p.cfg_scale > -1 else None,
|
||||
"CFG rescale": p.cfg_rescale if p.cfg_rescale > -1 else None,
|
||||
"CFG end": p.cfg_end if p.cfg_end < 1.0 else None,
|
||||
"CFG true": p.pag_scale if p.pag_scale > 0 else None,
|
||||
"CFG adaptive": p.pag_adaptive if p.pag_adaptive != 0.5 else None,
|
||||
"Clip skip": p.clip_skip if p.clip_skip > 1 else None,
|
||||
"CFG true": p.cfg_true if p.cfg_true > 0 else None,
|
||||
"CFG adaptive": p.cfg_adaptive if p.cfg_adaptive != 0.5 else None,
|
||||
"CLiP-skip": p.clip_skip if p.clip_skip > 1 else None,
|
||||
"Batch": f'{p.n_iter}x{p.batch_size}' if p.n_iter > 1 or p.batch_size > 1 else None,
|
||||
"Refiner prompt": p.refiner_prompt if len(p.refiner_prompt) > 0 else None,
|
||||
"Refiner negative": p.refiner_negative if len(p.refiner_negative) > 0 else None,
|
||||
@@ -109,20 +109,20 @@ def create_infotext(p: StableDiffusionProcessing, all_prompts=None, all_seeds=No
|
||||
args["Hires force"] = p.hr_force
|
||||
args["Hires steps"] = p.hr_second_pass_steps
|
||||
args["Hires strength"] = p.hr_denoising_strength
|
||||
args["Hires sampler"] = p.hr_sampler_name
|
||||
args["Hires CFG scale"] = p.image_cfg_scale
|
||||
args["Hires sampler"] = p.hr_sampler_name if p.hr_sampler_name != 'Default' else None
|
||||
args["Hires CFG scale"] = p.cfg_image if p.cfg_image > -1 else None
|
||||
if 'refine' in p.ops:
|
||||
args["Refine"] = p.enable_hr
|
||||
args["Refiner"] = None if (not shared.opts.add_model_name_to_info) or (not shared.sd_refiner) or (not shared.sd_refiner.sd_checkpoint_info.model_name) else shared.sd_refiner.sd_checkpoint_info.model_name.replace(',', '').replace(':', '')
|
||||
args['Hires CFG scale'] = p.image_cfg_scale
|
||||
args['Hires CFG scale'] = p.cfg_image if p.cfg_image > -1 else None
|
||||
args['Refiner steps'] = p.refiner_steps
|
||||
args['Refiner start'] = p.refiner_start
|
||||
args["Hires steps"] = p.hr_second_pass_steps
|
||||
args["Hires sampler"] = p.hr_sampler_name
|
||||
args["Hires sampler"] = p.hr_sampler_name if p.hr_sampler_name != 'Default' else None
|
||||
if ('img2img' in p.ops or 'inpaint' in p.ops) and ('txt2img' not in p.ops and 'hires' not in p.ops): # real img2img/inpaint
|
||||
args["Init image size"] = f"{getattr(p, 'init_img_width', 0)}x{getattr(p, 'init_img_height', 0)}"
|
||||
args["Init image hash"] = getattr(p, 'init_img_hash', None)
|
||||
args['Image CFG scale'] = p.image_cfg_scale
|
||||
args['Image CFG scale'] = p.cfg_image if p.cfg_image > -1 else None
|
||||
args["Mask weight"] = getattr(p, "inpainting_mask_weight", shared.opts.inpainting_mask_weight) if p.is_using_inpainting_conditioning else None
|
||||
args["Denoising strength"] = getattr(p, 'denoising_strength', None)
|
||||
if args["Size"] != args["Init image size"]:
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
def hijack_transformers():
|
||||
# transformers>=4.56 flattened CLIPTextModel internals; diffusers single-file loader still expects `text_model`.
|
||||
return
|
||||
try:
|
||||
import transformers
|
||||
if hasattr(transformers, 'CLIPTextModel') and not hasattr(transformers.CLIPTextModel, 'text_model'):
|
||||
transformers.CLIPTextModel.text_model = property(lambda self: self)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -11,7 +11,7 @@ import diffusers.loaders.single_file_utils
|
||||
import torch
|
||||
import huggingface_hub as hf
|
||||
from modules.logger import log
|
||||
from modules import timer, paths, shared, shared_items, modelloader, devices, script_callbacks, sd_vae, sd_unet, errors, sd_models_compile, sd_detect, model_quant, sd_hijack_te, sd_hijack_accelerate, sd_hijack_safetensors, sd_hijack_hfhub, attention
|
||||
from modules import timer, paths, shared, shared_items, modelloader, devices, script_callbacks, sd_vae, sd_unet, errors, sd_models_compile, sd_detect, model_quant, sd_hijack_te, sd_hijack_accelerate, sd_hijack_safetensors, sd_hijack_transformers, sd_hijack_hfhub, attention
|
||||
from modules.memstats import memory_stats
|
||||
from modules.shared_helpers import walk_files
|
||||
from modules.modeldata import model_data
|
||||
@@ -76,6 +76,7 @@ def set_huggingface_options(quiet=False):
|
||||
else:
|
||||
sd_hijack_safetensors.restore_safetensors()
|
||||
sd_hijack_hfhub.init_hijack()
|
||||
sd_hijack_transformers.hijack_transformers()
|
||||
|
||||
|
||||
def set_caption_load_options():
|
||||
|
||||
@@ -31,7 +31,7 @@ legacy_options = options_section(('legacy_options', "Legacy options"), {
|
||||
"diffusers_move_refiner": LegacyOption(False, "Move refiner model to CPU when not in use", gr.Checkbox, {"visible": False }),
|
||||
"diffusers_extract_ema": LegacyOption(False, "Use model EMA weights when possible", gr.Checkbox, {"visible": False }),
|
||||
"batch_cond_uncond": LegacyOption(True, "Do conditional and unconditional denoising in one batch", gr.Checkbox, {"visible": False}),
|
||||
"CLIP_stop_at_last_layers": LegacyOption(1, "Clip skip", gr.Slider, {"minimum": 1, "maximum": 8, "step": 1, "visible": False}),
|
||||
"CLIP_stop_at_last_layers": LegacyOption(1, "CLiP-skip", gr.Slider, {"minimum": 1, "maximum": 8, "step": 1, "visible": False}),
|
||||
"dataset_filename_join_string": LegacyOption(" ", "Filename join string", gr.Textbox, { "visible": False }),
|
||||
"dataset_filename_word_regex": LegacyOption("", "Filename word regex", gr.Textbox, { "visible": False }),
|
||||
"diffusers_force_zeros": LegacyOption(False, "Force zeros for prompts when empty", gr.Checkbox, {"visible": False}),
|
||||
|
||||
+5
-5
@@ -17,7 +17,7 @@ def txt2img(id_task, state,
|
||||
detailer_enabled, detailer_prompt, detailer_negative, detailer_steps, detailer_strength, detailer_resolution,
|
||||
n_iter, batch_size,
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop,
|
||||
cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end,
|
||||
cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end,
|
||||
clip_skip,
|
||||
seed, subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w,
|
||||
height, width,
|
||||
@@ -68,10 +68,10 @@ def txt2img(id_task, state,
|
||||
guidance_start=guidance_start,
|
||||
guidance_stop=guidance_stop,
|
||||
cfg_scale=cfg_scale,
|
||||
image_cfg_scale=image_cfg_scale,
|
||||
diffusers_guidance_rescale=diffusers_guidance_rescale,
|
||||
pag_scale=pag_scale,
|
||||
pag_adaptive=pag_adaptive,
|
||||
cfg_image=cfg_image,
|
||||
cfg_rescale=cfg_rescale,
|
||||
cfg_true=cfg_true,
|
||||
cfg_adaptive=cfg_adaptive,
|
||||
cfg_end=cfg_end,
|
||||
clip_skip=clip_skip,
|
||||
width=width,
|
||||
|
||||
@@ -128,7 +128,7 @@ def save_files(js_data, files, html_info, index):
|
||||
self.width = getattr(self, 'width', None) or getattr(self, 'Width', None) or getattr(self, 'Size-1', None) or 0
|
||||
self.height = getattr(self, 'height', None) or getattr(self, 'Height', None) or getattr(self, 'Size-2', None) or 0
|
||||
self.cfg_scale = getattr(self, 'cfg_scale', None) or getattr(self, 'CFG scale', None) or 0
|
||||
self.clip_skip = getattr(self, 'clip_skip', None) or getattr(self, 'Clip skip', None) or 1
|
||||
self.clip_skip = getattr(self, 'clip_skip', None) or getattr(self, 'CLiP-skip', None) or 1
|
||||
self.denoising_strength = getattr(self, 'denoising_strength', None) or getattr(self, 'Denoising', None) or 0
|
||||
self.index_of_first_image = getattr(self, 'index_of_first_image', 0)
|
||||
self.subseed = getattr(self, 'subseed', None) or getattr(self, 'Subseed', None)
|
||||
|
||||
@@ -193,7 +193,7 @@ def create_ui(_blocks: gr.Blocks=None):
|
||||
|
||||
mask_controls = masking.create_segment_ui()
|
||||
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop, cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_guidance.create_guidance_inputs('control')
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop, cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end = ui_guidance.create_guidance_inputs('control')
|
||||
vae_type, tiling, hidiffusion, clip_skip = ui_sections.create_advanced_inputs('control')
|
||||
grading_brightness, grading_contrast, grading_saturation, grading_hue, grading_gamma, grading_sharpness, grading_color_temp, grading_shadows, grading_midtones, grading_highlights, grading_clahe_clip, grading_clahe_grid, grading_shadows_tint, grading_highlights_tint, grading_split_tone_balance, grading_vignette, grading_grain, grading_lut_file, grading_lut_strength = ui_sections.create_color_inputs('control')
|
||||
hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundary, hdr_color_picker, hdr_tint_ratio, hdr_apply_hires = ui_sections.create_latent_inputs('control')
|
||||
@@ -309,7 +309,7 @@ def create_ui(_blocks: gr.Blocks=None):
|
||||
steps, sampler_index,
|
||||
seed, subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w,
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop,
|
||||
cfg_scale, clip_skip, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end, vae_type, tiling, hidiffusion,
|
||||
cfg_scale, clip_skip, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end, vae_type, tiling, hidiffusion,
|
||||
detailer_enabled, detailer_prompt, detailer_negative, detailer_steps, detailer_strength, detailer_resolution,
|
||||
hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundary, hdr_color_picker, hdr_tint_ratio, hdr_apply_hires,
|
||||
grading_brightness, grading_contrast, grading_saturation, grading_hue, grading_gamma, grading_sharpness, grading_color_temp,
|
||||
@@ -404,10 +404,10 @@ def create_ui(_blocks: gr.Blocks=None):
|
||||
# advanced
|
||||
(cfg_scale, "CFG scale"),
|
||||
(cfg_end, "CFG end"),
|
||||
(clip_skip, "Clip skip"),
|
||||
(image_cfg_scale, "Image CFG scale"),
|
||||
(image_cfg_scale, "Hires CFG scale"),
|
||||
(diffusers_guidance_rescale, "CFG rescale"),
|
||||
(clip_skip, "CLiP-skip"),
|
||||
(cfg_image, "Image CFG scale"),
|
||||
(cfg_image, "Hires CFG scale"),
|
||||
(cfg_rescale, "CFG rescale"),
|
||||
(vae_type, "VAE type"),
|
||||
(tiling, "Tiling"),
|
||||
(hidiffusion, "HiDiffusion"),
|
||||
@@ -438,8 +438,8 @@ def create_ui(_blocks: gr.Blocks=None):
|
||||
(refiner_prompt, "Refiner prompt"),
|
||||
(refiner_negative, "Refiner negative"),
|
||||
# pag
|
||||
(pag_scale, "CFG true"),
|
||||
(pag_adaptive, "CFG adaptive"),
|
||||
(cfg_true, "CFG true"),
|
||||
(cfg_adaptive, "CFG adaptive"),
|
||||
# hidden
|
||||
(seed_resize_from_w, "Seed resize from-1"),
|
||||
(seed_resize_from_h, "Seed resize from-2"),
|
||||
|
||||
+10
-10
@@ -15,8 +15,8 @@ def create_guidance_inputs(tab):
|
||||
guidance_btn = ui_components.ToolButton(value=ui_symbols.book, elem_id=f"{tab}_guider_docs")
|
||||
guidance_btn.click(fn=None, _js='getGuidanceDocs', inputs=[guidance_name], outputs=[])
|
||||
with gr.Row(visible=shared.opts.model_modular_enable):
|
||||
guidance_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.1, label='_Guidance scale', value=4.0, elem_id=f"{tab}_guidance_scale")
|
||||
guidance_rescale = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='_Guidance rescale', value=0.0, elem_id=f"{tab}_guidance_rescale")
|
||||
guidance_scale = gr.Slider(minimum=-1.0, maximum=30.0, step=0.1, label='_Guidance scale', value=-1.0, elem_id=f"{tab}_guidance_scale")
|
||||
guidance_rescale = gr.Slider(minimum=-1.0, maximum=1.0, step=0.05, label='_Guidance rescale', value=-1.0, elem_id=f"{tab}_guidance_rescale")
|
||||
with gr.Row(visible=shared.opts.model_modular_enable):
|
||||
guidance_start = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='_Guidance start', value=0.0, elem_id=f"{tab}_guidance_start")
|
||||
guidance_stop = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='_Guidance stop', value=1.0, elem_id=f"{tab}_guidance_stop")
|
||||
@@ -55,12 +55,12 @@ def create_guidance_inputs(tab):
|
||||
|
||||
pag_group = gr.Accordion(open=True, label='Advanced guidance params', elem_classes=["small-accordion"], visible=False)
|
||||
with pag_group:
|
||||
guidance_pag_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.05, label='PAG scale', value=2.8)
|
||||
guidance_cfg_true = gr.Slider(minimum=0.0, maximum=30.0, step=0.05, label='PAG scale', value=2.8)
|
||||
guidance_pag_start = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='PAG start', value=0.01)
|
||||
guidance_pag_stop = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='PAG stop', value=0.2)
|
||||
guidance_pag_layers = gr.Textbox(label='PAG layers', value='7, 8, 9', placeholder='Comma-separated layer indices, e.g. 7,8,9')
|
||||
guidance_pag_config = gr.Dropdown(choices=[None, 'config1', 'config2'], value=None, label='PAG config')
|
||||
guidance_pag_args = [guidance_pag_scale, guidance_pag_start, guidance_pag_stop, guidance_pag_layers, guidance_pag_config]
|
||||
guidance_pag_args = [guidance_cfg_true, guidance_pag_start, guidance_pag_stop, guidance_pag_layers, guidance_pag_config]
|
||||
|
||||
apg_group = gr.Accordion(open=True, label='Advanced guidance params', elem_classes=["small-accordion"], visible=False)
|
||||
with apg_group:
|
||||
@@ -114,15 +114,15 @@ def create_guidance_inputs(tab):
|
||||
|
||||
gr.HTML(value='<br><h2>Fallback guidance</h2>', visible=shared.opts.model_modular_enable, elem_id=f"{tab}_guidance_note")
|
||||
with gr.Row(elem_id=f"{tab}_cfg_row", elem_classes=['flexbox']):
|
||||
cfg_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.1, label='Guidance scale', value=6.0, elem_id=f"{tab}_cfg_scale")
|
||||
cfg_scale = gr.Slider(minimum=-1.0, maximum=30.0, step=0.1, label='Guidance scale', value=-1.0, elem_id=f"{tab}_cfg_scale")
|
||||
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")
|
||||
with gr.Row():
|
||||
diffusers_guidance_rescale = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Guidance rescale', value=0.0, elem_id=f"{tab}_image_cfg_rescale")
|
||||
image_cfg_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.1, label='Refine guidance', value=6.0, elem_id=f"{tab}_image_cfg_scale")
|
||||
cfg_rescale = gr.Slider(minimum=-1.0, maximum=1.0, step=0.05, label='Guidance rescale', value=-1.0, elem_id=f"{tab}_image_cfg_rescale")
|
||||
cfg_image = gr.Slider(minimum=-1.0, maximum=30.0, step=0.1, label='Refine guidance', value=-1.0, elem_id=f"{tab}_cfg_image")
|
||||
with gr.Row():
|
||||
diffusers_pag_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.05, label='Attention guidance', value=0.0, elem_id=f"{tab}_pag_scale")
|
||||
diffusers_pag_adaptive = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Adaptive scaling', value=0.5, elem_id=f"{tab}_pag_adaptive")
|
||||
cfg_true = gr.Slider(minimum=-1.0, maximum=30.0, step=0.05, label='Attention guidance', value=-1.0, elem_id=f"{tab}_cfg_true")
|
||||
cfg_adaptive = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Adaptive scaling', value=0.5, elem_id=f"{tab}_cfg_adaptive")
|
||||
|
||||
_modular_args = guidance_args + lsc_args + guidance_auto_args + guidance_zero_args + guidance_pag_args + guidance_apg_args + guidance_slg_args + guidance_seg_args + guidance_fdg_args
|
||||
standard_args = [cfg_scale, image_cfg_scale, diffusers_guidance_rescale, diffusers_pag_scale, diffusers_pag_adaptive, cfg_end]
|
||||
standard_args = [cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end]
|
||||
return guidance_args + standard_args
|
||||
|
||||
@@ -137,7 +137,7 @@ def create_ui():
|
||||
denoising_strength = gr.Slider(minimum=0.00, maximum=0.99, step=0.01, label='Denoising strength', value=0.30, elem_id="img2img_denoising_strength")
|
||||
refiner_start = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Denoise start', value=0.0, elem_id="img2img_refiner_start")
|
||||
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop, cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_guidance.create_guidance_inputs('img2img')
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop, cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end = ui_guidance.create_guidance_inputs('img2img')
|
||||
vae_type, tiling, hidiffusion, clip_skip = ui_sections.create_advanced_inputs('img2img')
|
||||
grading_brightness, grading_contrast, grading_saturation, grading_hue, grading_gamma, grading_sharpness, grading_color_temp, grading_shadows, grading_midtones, grading_highlights, grading_clahe_clip, grading_clahe_grid, grading_shadows_tint, grading_highlights_tint, grading_split_tone_balance, grading_vignette, grading_grain, grading_lut_file, grading_lut_strength = ui_sections.create_color_inputs('img2img')
|
||||
hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundary, hdr_color_picker, hdr_tint_ratio, hdr_apply_hires = ui_sections.create_latent_inputs('img2img')
|
||||
@@ -184,7 +184,7 @@ def create_ui():
|
||||
detailer_enabled, detailer_prompt, detailer_negative, detailer_steps, detailer_strength, detailer_resolution,
|
||||
batch_count, batch_size,
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop,
|
||||
cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end,
|
||||
cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end,
|
||||
refiner_start,
|
||||
clip_skip,
|
||||
denoising_strength,
|
||||
@@ -273,10 +273,10 @@ def create_ui():
|
||||
# advanced
|
||||
(cfg_scale, "CFG scale"),
|
||||
(cfg_end, "CFG end"),
|
||||
(image_cfg_scale, "Image CFG scale"),
|
||||
(image_cfg_scale, "Hires CFG scale"),
|
||||
(clip_skip, "Clip skip"),
|
||||
(diffusers_guidance_rescale, "CFG rescale"),
|
||||
(cfg_image, "Image CFG scale"),
|
||||
(cfg_image, "Hires CFG scale"),
|
||||
(clip_skip, "CLiP-skip"),
|
||||
(cfg_rescale, "CFG rescale"),
|
||||
(vae_type, "VAE type"),
|
||||
(tiling, "Tiling"),
|
||||
(hidiffusion, "HiDiffusion"),
|
||||
@@ -308,8 +308,8 @@ def create_ui():
|
||||
(refiner_prompt, "refiner prompt"),
|
||||
(refiner_negative, "Refiner negative"),
|
||||
# pag
|
||||
(pag_scale, "CFG true"),
|
||||
(pag_adaptive, "CFG adaptive"),
|
||||
(cfg_true, "CFG true"),
|
||||
(cfg_adaptive, "CFG adaptive"),
|
||||
# inpaint
|
||||
(mask_blur, "Mask blur"),
|
||||
(mask_alpha, "Mask alpha"),
|
||||
|
||||
@@ -33,7 +33,7 @@ def create_ui():
|
||||
with gr.Accordion(open=False, label="Samplers", elem_classes=["small-accordion"], elem_id="txt2img_sampler_group"):
|
||||
ui_sections.create_sampler_options('txt2img')
|
||||
seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w = ui_sections.create_seed_inputs('txt2img')
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop, cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_guidance.create_guidance_inputs('txt2img')
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop, cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end = ui_guidance.create_guidance_inputs('txt2img')
|
||||
vae_type, tiling, hidiffusion, clip_skip = ui_sections.create_advanced_inputs('txt2img')
|
||||
grading_brightness, grading_contrast, grading_saturation, grading_hue, grading_gamma, grading_sharpness, grading_color_temp, grading_shadows, grading_midtones, grading_highlights, grading_clahe_clip, grading_clahe_grid, grading_shadows_tint, grading_highlights_tint, grading_split_tone_balance, grading_vignette, grading_grain, grading_lut_file, grading_lut_strength = ui_sections.create_color_inputs('txt2img')
|
||||
hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundary, hdr_color_picker, hdr_tint_ratio, hdr_apply_hires = ui_sections.create_latent_inputs('txt2img')
|
||||
@@ -59,7 +59,7 @@ def create_ui():
|
||||
detailer_enabled, detailer_prompt, detailer_negative, detailer_steps, detailer_strength, detailer_resolution,
|
||||
batch_count, batch_size,
|
||||
guidance_name, guidance_scale, guidance_rescale, guidance_start, guidance_stop,
|
||||
cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end,
|
||||
cfg_scale, cfg_image, cfg_rescale, cfg_true, cfg_adaptive, cfg_end,
|
||||
clip_skip,
|
||||
seed, subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w,
|
||||
height, width,
|
||||
@@ -121,10 +121,10 @@ def create_ui():
|
||||
# advanced
|
||||
(cfg_scale, "CFG scale"),
|
||||
(cfg_end, "CFG end"),
|
||||
(clip_skip, "Clip skip"),
|
||||
(image_cfg_scale, "Image CFG scale"),
|
||||
(image_cfg_scale, "Hires CFG scale"),
|
||||
(diffusers_guidance_rescale, "CFG rescale"),
|
||||
(clip_skip, "CLiP-skip"),
|
||||
(cfg_image, "Image CFG scale"),
|
||||
(cfg_image, "Hires CFG scale"),
|
||||
(cfg_rescale, "CFG rescale"),
|
||||
(vae_type, "VAE type"),
|
||||
(tiling, "Tiling"),
|
||||
(hidiffusion, "HiDiffusion"),
|
||||
@@ -155,8 +155,8 @@ def create_ui():
|
||||
(refiner_prompt, "refiner prompt"),
|
||||
(refiner_negative, "Refiner negative"),
|
||||
# pag
|
||||
(pag_scale, "CFG true"),
|
||||
(pag_adaptive, "CFG adaptive"),
|
||||
(cfg_true, "CFG true"),
|
||||
(cfg_adaptive, "CFG adaptive"),
|
||||
# hidden
|
||||
(seed_resize_from_w, "Seed resize from-1"),
|
||||
(seed_resize_from_h, "Seed resize from-2"),
|
||||
|
||||
@@ -46,7 +46,7 @@ def generate(*args, **kwargs):
|
||||
denoising_strength=float(init_strength),
|
||||
init_image=init_image,
|
||||
cfg_scale=float(guidance_scale),
|
||||
pag_scale=float(guidance_true),
|
||||
cfg_true=float(guidance_true),
|
||||
vae_type=vae_type,
|
||||
vae_tile_frames=int(vae_tile_frames),
|
||||
override_settings=override_settings,
|
||||
|
||||
@@ -1047,20 +1047,20 @@ class PixelSmithXLPipeline(
|
||||
#+#
|
||||
|
||||
@property
|
||||
def pag_scale(self):
|
||||
return self._pag_scale
|
||||
def cfg_true(self):
|
||||
return self._cfg_true
|
||||
|
||||
@property
|
||||
def do_adversarial_guidance(self):
|
||||
return self._pag_scale > 0
|
||||
return self._cfg_true > 0
|
||||
|
||||
@property
|
||||
def pag_adaptive_scaling(self):
|
||||
return self._pag_adaptive_scaling
|
||||
def cfg_adaptive_scaling(self):
|
||||
return self._cfg_adaptive_scaling
|
||||
|
||||
@property
|
||||
def do_pag_adaptive_scaling(self):
|
||||
return self._pag_adaptive_scaling > 0
|
||||
def do_cfg_adaptive_scaling(self):
|
||||
return self._cfg_adaptive_scaling > 0
|
||||
|
||||
@property
|
||||
def pag_drop_rate(self):
|
||||
@@ -1097,8 +1097,8 @@ class PixelSmithXLPipeline(
|
||||
denoising_end: Optional[float] = None,
|
||||
guidance_scale: float = 5.0,
|
||||
#+#
|
||||
pag_scale: float = 0.0, # longer inference time if used (https://ku-cvlab.github.io/Perturbed-Attention-Guidance/)
|
||||
pag_adaptive_scaling: float = 0.0,
|
||||
cfg_true: float = 0.0, # longer inference time if used (https://ku-cvlab.github.io/Perturbed-Attention-Guidance/)
|
||||
cfg_adaptive_scaling: float = 0.0,
|
||||
pag_drop_rate: float = 0.5,
|
||||
pag_applied_layers: List[str] = ['mid'], #['down', 'mid', 'up']
|
||||
pag_applied_layers_index: List[str] | None = None, #['d4', 'd5', 'm0']
|
||||
@@ -1325,8 +1325,8 @@ class PixelSmithXLPipeline(
|
||||
self._interrupt = False
|
||||
|
||||
#+#
|
||||
self._pag_scale = pag_scale
|
||||
self._pag_adaptive_scaling = pag_adaptive_scaling
|
||||
self._cfg_true = cfg_true
|
||||
self._cfg_adaptive_scaling = cfg_adaptive_scaling
|
||||
self._pag_drop_rate = pag_drop_rate
|
||||
self._pag_applied_layers = pag_applied_layers
|
||||
self._pag_applied_layers_index = pag_applied_layers_index
|
||||
@@ -1571,18 +1571,18 @@ class PixelSmithXLPipeline(
|
||||
# pag
|
||||
elif not self.do_classifier_free_guidance and self.do_adversarial_guidance:
|
||||
noise_pred_original, noise_pred_perturb = noise_pred.chunk(2)
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000-t)
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000-t)
|
||||
if signal_scale<0:
|
||||
signal_scale = 0
|
||||
noise_pred = noise_pred_original + signal_scale * (noise_pred_original - noise_pred_perturb)
|
||||
# both
|
||||
elif self.do_classifier_free_guidance and self.do_adversarial_guidance:
|
||||
noise_pred_uncond, noise_pred_text, noise_pred_text_perturb = noise_pred.chunk(3)
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000-t)
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000-t)
|
||||
if signal_scale<0:
|
||||
signal_scale = 0
|
||||
noise_pred = noise_pred_text + (self.guidance_scale-1.0) * (noise_pred_text - noise_pred_uncond) + signal_scale * (noise_pred_text - noise_pred_text_perturb)
|
||||
@@ -1776,18 +1776,18 @@ class PixelSmithXLPipeline(
|
||||
# pag
|
||||
elif not self.do_classifier_free_guidance and self.do_adversarial_guidance:
|
||||
noise_pred_original, noise_pred_perturb = noise_pred.chunk(2)
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000-sub_time.max().item())
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000-sub_time.max().item())
|
||||
if signal_scale<0:
|
||||
signal_scale = 0
|
||||
noise_pred = noise_pred_original + signal_scale * (noise_pred_original - noise_pred_perturb)
|
||||
# both
|
||||
elif self.do_classifier_free_guidance and self.do_adversarial_guidance:
|
||||
noise_pred_uncond, noise_pred_text, noise_pred_text_perturb = noise_pred.chunk(3)
|
||||
signal_scale = self.pag_scale
|
||||
if self.do_pag_adaptive_scaling:
|
||||
signal_scale = self.pag_scale - self.pag_adaptive_scaling * (1000-sub_time.max().item())
|
||||
signal_scale = self.cfg_true
|
||||
if self.do_cfg_adaptive_scaling:
|
||||
signal_scale = self.cfg_true - self.cfg_adaptive_scaling * (1000-sub_time.max().item())
|
||||
if signal_scale<0:
|
||||
signal_scale = 0
|
||||
noise_pred = noise_pred_text + (self.guidance_scale-1.0) * (noise_pred_text - noise_pred_uncond) + signal_scale * (noise_pred_text - noise_pred_text_perturb)
|
||||
|
||||
@@ -212,7 +212,7 @@ axis_options = [
|
||||
AxisOption("[Param] Steps", int, apply_field("steps")),
|
||||
AxisOption("[Param] Variation seed", int, apply_field("subseed")),
|
||||
AxisOption("[Param] Variation strength", float, apply_field("subseed_strength")),
|
||||
AxisOption("[Param] Clip skip", float, apply_clip_skip),
|
||||
AxisOption("[Param] CLiP-skip", float, apply_clip_skip),
|
||||
AxisOption("[Param] Denoising strength", float, apply_field("denoising_strength")),
|
||||
AxisOptionImg2Img("[Param] Mask weight", float, apply_field("inpainting_mask_weight")),
|
||||
AxisOption("[Process] Model args", str, apply_task_args),
|
||||
@@ -235,8 +235,8 @@ axis_options = [
|
||||
AxisOption("[Sampler] ETA multiplier", float, apply_setting("scheduler_eta")),
|
||||
AxisOption("[Guidance] Scale", float, apply_field("cfg_scale")),
|
||||
AxisOption("[Guidance] End", float, apply_field("cfg_end")),
|
||||
AxisOption("[Guidance] Image scale", float, apply_field("image_cfg_scale")),
|
||||
AxisOption("[Guidance] Rescale", float, apply_field("diffusers_guidance_rescale")),
|
||||
AxisOption("[Guidance] Image scale", float, apply_field("cfg_image")),
|
||||
AxisOption("[Guidance] Rescale", float, apply_field("cfg_rescale")),
|
||||
AxisOption("[Guidance] Modular name", str, apply_guidance, choices=lambda: ['Default', 'CFG', 'Auto', 'Zero', 'PAG', 'APG', 'SLG', 'SEG', 'TCFG', 'FDG']),
|
||||
AxisOption("[Refine] Upscaler", str, apply_field("hr_upscaler"), cost=0.3, choices=lambda: [x.name for x in shared.sd_upscalers]),
|
||||
AxisOption("[Refine] Sampler", str, apply_hr_sampler_name, fmt=format_value_add_label, confirm=confirm_samplers, choices=lambda: [x.name for x in sd_samplers.samplers]),
|
||||
@@ -279,8 +279,8 @@ axis_options = [
|
||||
AxisOption("[HiDiffusion] T1", float, apply_override('hidiffusion_t1')),
|
||||
AxisOption("[HiDiffusion] T2", float, apply_override('hidiffusion_t2')),
|
||||
AxisOption("[HiDiffusion] Agression step", float, apply_field('hidiffusion_steps')),
|
||||
AxisOption("[PAG] Attention scale", float, apply_field('pag_scale')),
|
||||
AxisOption("[PAG] Adaptive scaling", float, apply_field('pag_adaptive')),
|
||||
AxisOption("[PAG] Attention scale", float, apply_field('cfg_true')),
|
||||
AxisOption("[PAG] Adaptive scaling", float, apply_field('cfg_adaptive')),
|
||||
AxisOption("[PAG] Applied layers", str, apply_setting('pag_apply_layers')),
|
||||
AxisOption("[IY] Scale", float, apply_task_arg('infusenet_conditioning_scale')),
|
||||
AxisOption("[IY] Start", float, apply_task_arg('infusenet_guidance_start')),
|
||||
|
||||
Reference in New Issue
Block a user