diff --git a/invokeai/app/invocations/denoise_latents.py b/invokeai/app/invocations/denoise_latents.py index d5e705ea28..5f00da6dad 100644 --- a/invokeai/app/invocations/denoise_latents.py +++ b/invokeai/app/invocations/denoise_latents.py @@ -669,6 +669,18 @@ class DenoiseLatentsInvocation(BaseInvocation): def prepare_noise_and_latents( context: InvocationContext, noise_field: LatentsField | None, latents_field: LatentsField | None ) -> Tuple[int, torch.Tensor | None, torch.Tensor]: + """Depending on the workflow, we expect different combinations of noise and latents to be provided. This + function handles preparing these values accordingly. + + Expected workflows: + - Text-to-Image Denoising: `noise` is provided, `latents` is not. `latents` is initialized to zeros. + - Image-to-Image Denoising: `noise` and `latents` are both provided. + - Text-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not. + - Image-to-Image SDXL Refiner Denoising: `latents` is provided, `noise` is not. + + NOTE(ryand): I wrote this docstring, but I am not the original author of this code. There may be other workflows + I haven't considered. + """ noise = None if noise_field is not None: noise = context.tensors.load(noise_field.latents_name) diff --git a/invokeai/backend/stable_diffusion/diffusers_pipeline.py b/invokeai/backend/stable_diffusion/diffusers_pipeline.py index d5a37a2054..9c532cec3e 100644 --- a/invokeai/backend/stable_diffusion/diffusers_pipeline.py +++ b/invokeai/backend/stable_diffusion/diffusers_pipeline.py @@ -298,8 +298,7 @@ class StableDiffusionGeneratorPipeline(StableDiffusionPipeline): batch_size = latents.shape[0] batched_t = init_timestep.expand(batch_size) - # NOTE(ryand): noise will be None if we are running the SDXL refiner. I can't think of any other reason that - # we'd want noise to be None, but I didn't write this logic, so there might be a reason I haven't thought of. + # noise can be None if the latents have already been noised (e.g. when running the SDXL refiner). if noise is not None: # latents = noise * self.scheduler.init_noise_sigma # it's like in t2l according to diffusers latents = self.scheduler.add_noise(latents, noise, batched_t)