mirror of
https://github.com/vladmandic/automatic
synced 2026-09-18 16:54:33 +02:00
+8
-7
@@ -14,8 +14,7 @@ class Script(scripts.Script):
|
||||
def show(self, is_img2img):
|
||||
return not is_img2img if shared.native else False
|
||||
|
||||
# return signature is array of gradio components
|
||||
def ui(self, _is_img2img):
|
||||
def ui(self, _is_img2img): # ui elements
|
||||
with gr.Row():
|
||||
gr.HTML('<a href="https://arxiv.org/abs/2410.02416">  APG: Adaptive projected guidance</a><br>')
|
||||
with gr.Row():
|
||||
@@ -24,7 +23,7 @@ class Script(scripts.Script):
|
||||
threshold = gr.Slider(label="Threshold", value=0.0, minimum=0.0, maximum=5.0, step=0.01)
|
||||
return [eta, momentum, threshold]
|
||||
|
||||
def register(self):
|
||||
def register(self): # register xyz grid elements
|
||||
def apply_field(field):
|
||||
def fun(p, x, xs): # pylint: disable=unused-argument
|
||||
setattr(p, field, x)
|
||||
@@ -42,16 +41,18 @@ class Script(scripts.Script):
|
||||
shared.log.warning(f'APG: pipeline={shared.sd_model_type} required=sdxl')
|
||||
return None
|
||||
from modules import apg
|
||||
apg.eta = getattr(p, 'apg_eta', eta)
|
||||
apg.eta = getattr(p, 'apg_eta', eta) # use values set by xyz grid or via ui
|
||||
apg.momentum = getattr(p, 'apg_momentum', momentum)
|
||||
apg.threshold = getattr(p, 'apg_threshold', threshold)
|
||||
apg.buffer = apg.MomentumBuffer(apg.momentum)
|
||||
apg.buffer = apg.MomentumBuffer(apg.momentum) # recreate buffer
|
||||
self.orig_pipe = shared.sd_model
|
||||
shared.sd_model = sd_models.switch_pipe(apg.StableDiffusionXLPipelineAPG, shared.sd_model)
|
||||
shared.sd_model = sd_models.switch_pipe(apg.StableDiffusionXLPipelineAPG, shared.sd_model) # sdxl pipeline with call to apg.normalized_guidance instead of default
|
||||
shared.log.info(f'APG apply: guidance={p.cfg_scale} momentum={apg.momentum} eta={apg.eta} threshold={apg.threshold} class={shared.sd_model.__class__.__name__}')
|
||||
p.extra_generation_params["APG"] = f'ETA={apg.eta} Momentum={apg.momentum} Threshold={apg.threshold}'
|
||||
# processed = processing.process_images(p)
|
||||
|
||||
def after(self, p: processing.StableDiffusionProcessing, processed: processing.Processed, eta, momentum, threshold): # pylint: disable=arguments-differ, unused-argument
|
||||
shared.sd_model = self.orig_pipe
|
||||
from modules import apg
|
||||
shared.sd_model = self.orig_pipe # restore pipeline
|
||||
apg.buffer = None
|
||||
return processed
|
||||
|
||||
Reference in New Issue
Block a user