diff --git a/modules/processing_callbacks.py b/modules/processing_callbacks.py index 3c0a81848..a491dc7e1 100644 --- a/modules/processing_callbacks.py +++ b/modules/processing_callbacks.py @@ -75,7 +75,7 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = No time.sleep(0.1) if latents is None: return kwargs - elif shared.opts.nan_skip: + elif (getattr(p, 'nan_skip', None) if (p is not None and getattr(p, 'nan_skip', None) is not None) else shared.opts.nan_skip): assert not torch.isnan(latents[..., 0, 0]).all(), f'NaN detected at step {step}: Skipping...' if p is None: return kwargs @@ -93,7 +93,7 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = No 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, initial=step == 0) + kwargs = processing_correction.correction_callback(p, timestep, kwargs, pipe=pipe, initial=step == 0) kwargs = prompt_callback(step, kwargs) # monkey patch for diffusers callback issues if step == 0: @@ -164,13 +164,27 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = No shared.state.current_latent = kwargs['latents'] shared.state.current_noise_pred = current_noise_pred + # Video latent preview: extract middle frame from 5D [B,C,T,H,W] to 4D [B,C,H,W] + if shared.state.current_latent is not None and shared.state.current_latent.ndim == 5: + _b, _c, t, _h, _w = shared.state.current_latent.shape + shared.state.current_latent = shared.state.current_latent[:, :, t // 2, :, :] + if hasattr(pipe, "scheduler") and hasattr(pipe.scheduler, "sigmas") and hasattr(pipe.scheduler, "step_index") and pipe.scheduler.step_index is not None: try: shared.state.current_sigma = pipe.scheduler.sigmas[pipe.scheduler.step_index-1] shared.state.current_sigma_next = pipe.scheduler.sigmas[pipe.scheduler.step_index] - if (shared.opts.schedulers_sigma_adjust != 1.0) and (timestep > 1000 * shared.opts.schedulers_sigma_adjust_min) and (timestep < 1000 * shared.opts.schedulers_sigma_adjust_max): - pipe.scheduler.sigmas[pipe.scheduler.step_index+1] = pipe.scheduler.sigmas[pipe.scheduler.step_index+1] * shared.opts.schedulers_sigma_adjust - p.extra_generation_params["Sigma adjust"] = shared.opts.schedulers_sigma_adjust + _sigma_adjust = getattr(p, 'schedulers_sigma_adjust', None) if p is not None else None + if _sigma_adjust is None: + _sigma_adjust = shared.opts.schedulers_sigma_adjust + _sigma_adjust_min = getattr(p, 'schedulers_sigma_adjust_min', None) if p is not None else None + if _sigma_adjust_min is None: + _sigma_adjust_min = shared.opts.schedulers_sigma_adjust_min + _sigma_adjust_max = getattr(p, 'schedulers_sigma_adjust_max', None) if p is not None else None + if _sigma_adjust_max is None: + _sigma_adjust_max = shared.opts.schedulers_sigma_adjust_max + if (_sigma_adjust != 1.0) and (timestep > 1000 * _sigma_adjust_min) and (timestep < 1000 * _sigma_adjust_max): + pipe.scheduler.sigmas[pipe.scheduler.step_index+1] = pipe.scheduler.sigmas[pipe.scheduler.step_index+1] * _sigma_adjust + p.extra_generation_params["Sigma adjust"] = _sigma_adjust except Exception: pass except Exception as e: