Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/diffusers/modular_pipelines/flux/denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down
25 changes: 24 additions & 1 deletion src/diffusers/modular_pipelines/ltx/denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down