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)