mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
Merge branch 'dev' into lora-refactor
This commit is contained in:
@@ -7,7 +7,8 @@ from modules import shared, processing_correction, extra_networks, timer, prompt
|
||||
from modules.lora.networks import network_load
|
||||
|
||||
p = None
|
||||
debug_callback = shared.log.trace if os.environ.get('SD_CALLBACK_DEBUG', None) is not None else lambda *args, **kwargs: None
|
||||
debug = os.environ.get('SD_CALLBACK_DEBUG', None) is not None
|
||||
debug_callback = shared.log.trace if debug else lambda *args, **kwargs: None
|
||||
|
||||
|
||||
def set_callbacks_p(processing):
|
||||
@@ -51,7 +52,8 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = {}
|
||||
if p is None:
|
||||
return kwargs
|
||||
latents = kwargs.get('latents', None)
|
||||
debug_callback(f'Callback: step={step} timestep={timestep} latents={latents.shape if latents is not None else None} kwargs={list(kwargs)}')
|
||||
if debug:
|
||||
debug_callback(f'Callback: step={step} timestep={timestep} latents={latents.shape if latents is not None else None} kwargs={list(kwargs)}')
|
||||
order = getattr(pipe.scheduler, "order", 1) if hasattr(pipe, 'scheduler') else 1
|
||||
shared.state.sampling_step = step // order
|
||||
if shared.state.interrupted or shared.state.skipped:
|
||||
@@ -69,7 +71,7 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = {}
|
||||
return kwargs
|
||||
elif shared.opts.nan_skip:
|
||||
assert not torch.isnan(latents[..., 0, 0]).all(), f'NaN detected at step {step}: Skipping...'
|
||||
if len(getattr(p, 'ip_adapter_names', [])) > 0:
|
||||
if len(getattr(p, 'ip_adapter_names', [])) > 0 and p.ip_adapter_names[0] != 'None':
|
||||
ip_adapter_scales = list(p.ip_adapter_scales)
|
||||
ip_adapter_starts = list(p.ip_adapter_starts)
|
||||
ip_adapter_ends = list(p.ip_adapter_ends)
|
||||
@@ -80,7 +82,7 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = {}
|
||||
debug_callback(f"Callback: IP Adapter scales={ip_adapter_scales}")
|
||||
pipe.set_ip_adapter_scale(ip_adapter_scales)
|
||||
if step != getattr(pipe, 'num_timesteps', 0):
|
||||
kwargs = processing_correction.correction_callback(p, timestep, kwargs)
|
||||
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 "PAG" in shared.sd_model.__class__.__name__:
|
||||
@@ -107,7 +109,5 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = {}
|
||||
if shared.cmd_opts.profile and shared.profiler is not None:
|
||||
shared.profiler.step()
|
||||
t1 = time.time()
|
||||
if 'callback' not in timer.process.records:
|
||||
timer.process.records['callback'] = 0
|
||||
timer.process.records['callback'] += t1 - t0
|
||||
timer.process.add('callback', t1 - t0)
|
||||
return kwargs
|
||||
|
||||
Reference in New Issue
Block a user