From f20f14ab9131c61ef872282a362281edfcf6f741 Mon Sep 17 00:00:00 2001 From: Ann Mathew Date: Fri, 20 Nov 2026 10:35:19 +0530 Subject: [PATCH] fix(modular): pass generator to scheduler.step in Flux and LTX denoising blocks (#15163) FluxLoopAfterDenoiser, LTXLoopAfterDenoiser, and LTXImage2VideoLoopAfterDenoiser called scheduler.step without forwarding the generator argument, so stochastic sampling (s_churn > 0) ignored the user-supplied seed and varied with global RNG across runs. Add an inputs property declaring InputParam("generator") and a prepare_extra_kwargs helper (matching the pattern used by StableDiffusionXLLoopAfterDenoiser) to conditionally forward generator only when the active scheduler accepts it. --- .../modular_pipelines/flux/denoise.py | 14 +++++++++++ .../modular_pipelines/ltx/denoise.py | 25 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/diffusers/modular_pipelines/flux/denoise.py b/src/diffusers/modular_pipelines/flux/denoise.py index 7ca1c47bbfb1..f7f4dd6839da 100644 --- a/src/diffusers/modular_pipelines/flux/denoise.py +++ b/src/diffusers/modular_pipelines/flux/denoise.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import inspect from typing import Any import torch @@ -216,20 +217,33 @@ def description(self) -> str: "object (e.g. `FluxDenoiseLoopWrapper`)" ) + @property + def inputs(self) -> list[InputParam]: + return [InputParam("generator")] + @property def intermediate_outputs(self) -> list[OutputParam]: return [OutputParam("latents", type_hint=torch.Tensor, description="The denoised latents")] + @staticmethod + def prepare_extra_kwargs(func, **kwargs): + accepted = set(inspect.signature(func).parameters.keys()) + return {k: v for k, v in kwargs.items() if k in accepted} + @torch.no_grad() def __call__( self, components: FluxModularPipeline, block_state: BlockState, i: int, t: torch.Tensor ) -> tuple[FluxModularPipeline, BlockState]: + extra_step_kwargs = self.prepare_extra_kwargs( + components.scheduler.step, generator=block_state.generator + ) # Perform scheduler step using the predicted output latents_dtype = block_state.latents.dtype block_state.latents = components.scheduler.step( block_state.noise_pred, t, block_state.latents, + **extra_step_kwargs, return_dict=False, )[0] diff --git a/src/diffusers/modular_pipelines/ltx/denoise.py b/src/diffusers/modular_pipelines/ltx/denoise.py index 313e21240048..5210d1a3603e 100644 --- a/src/diffusers/modular_pipelines/ltx/denoise.py +++ b/src/diffusers/modular_pipelines/ltx/denoise.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import inspect from typing import Any import torch @@ -172,15 +173,28 @@ def description(self) -> str: "object (e.g. `LTXDenoiseLoopWrapper`)" ) + @property + def inputs(self) -> list[InputParam]: + return [InputParam("generator")] + + @staticmethod + def prepare_extra_kwargs(func, **kwargs): + accepted = set(inspect.signature(func).parameters.keys()) + return {k: v for k, v in kwargs.items() if k in accepted} + @torch.no_grad() def __call__( self, components: LTXModularPipeline, block_state: BlockState, i: int, t: torch.Tensor ) -> tuple[LTXModularPipeline, BlockState]: + extra_step_kwargs = self.prepare_extra_kwargs( + components.scheduler.step, generator=block_state.generator + ) latents_dtype = block_state.latents.dtype block_state.latents = components.scheduler.step( block_state.noise_pred, t, block_state.latents, + **extra_step_kwargs, return_dict=False, )[0] @@ -416,8 +430,14 @@ def inputs(self) -> list[InputParam]: InputParam.template("height"), InputParam.template("width"), InputParam("num_frames", type_hint=int), + InputParam("generator"), ] + @staticmethod + def prepare_extra_kwargs(func, **kwargs): + accepted = set(inspect.signature(func).parameters.keys()) + return {k: v for k, v in kwargs.items() if k in accepted} + @torch.no_grad() def __call__( self, components: LTXModularPipeline, block_state: BlockState, i: int, t: torch.Tensor @@ -433,9 +453,12 @@ def __call__( block_state.latents, latent_num_frames, latent_height, latent_width ) + extra_step_kwargs = self.prepare_extra_kwargs( + components.scheduler.step, generator=block_state.generator + ) noise_pred = noise_pred[:, :, 1:] noise_latents = latents[:, :, 1:] - pred_latents = components.scheduler.step(noise_pred, t, noise_latents, return_dict=False)[0] + pred_latents = components.scheduler.step(noise_pred, t, noise_latents, **extra_step_kwargs, return_dict=False)[0] latents = torch.cat([latents[:, :, :1], pred_latents], dim=2) block_state.latents = components.pachifier.pack_latents(latents)