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
26 changes: 18 additions & 8 deletions src/diffusers/pipelines/ltx/pipeline_ltx_i2v_long_multi_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,22 @@ def prepare_latents(

return latents, negative_index_latents, latent_num_frames, latent_height, latent_width

def _prepare_timesteps(
self, num_inference_steps: int, sigmas: list[float] | torch.Tensor | None, device: torch.device
) -> torch.Tensor:
if sigmas is not None:
sigmas = torch.tensor(sigmas, dtype=torch.float32) if not isinstance(sigmas, torch.Tensor) else sigmas
self.scheduler.set_timesteps(sigmas=sigmas, device=device)
else:
self.scheduler.set_timesteps(num_inference_steps=num_inference_steps, device=device)

timesteps = self.scheduler.timesteps
# Auto-generated schedules already keep the terminal sigma out of timesteps.
if sigmas is not None and len(sigmas) > 0 and sigmas[-1] == 0:
timesteps = timesteps[:-1]
self._num_timesteps = len(timesteps)
return timesteps

# TODO: refactor this out
@torch.no_grad()
def vae_decode_tiled(
Expand Down Expand Up @@ -1176,13 +1192,7 @@ def __call__(
prompt_attention_mask = torch.cat([negative_prompt_attention_mask, prompt_attention_mask], dim=0)

# 6.2 Window-level timesteps reset: fresh sampling for each temporal window
if sigmas is not None:
s = torch.tensor(sigmas, dtype=torch.float32) if not isinstance(sigmas, torch.Tensor) else sigmas
self.scheduler.set_timesteps(sigmas=s, device=device)
self._num_timesteps = len(sigmas)
else:
self.scheduler.set_timesteps(num_inference_steps=num_inference_steps, device=device)
self._num_timesteps = num_inference_steps
timesteps = self._prepare_timesteps(num_inference_steps, sigmas, device)

# 6.3 Extract window latents [B,C,T,H,W]
window_latents = latents[:, :, w_start:w_end]
Expand Down Expand Up @@ -1266,7 +1276,7 @@ def __call__(
# 6.6 Denoising loop per full window (no spatial tiling)
sigmas_current = self.scheduler.sigmas.to(device=latents_packed.device)
if sigmas_current.shape[0] >= 2:
for i, t in enumerate(self.progress_bar(self.scheduler.timesteps[:-1])):
for i, t in enumerate(self.progress_bar(timesteps)):
if self.interrupt:
break
# Skip semantics: if sigma exceeds threshold, skip this step (do not call scheduler.step)
Expand Down
52 changes: 52 additions & 0 deletions tests/pipelines/ltx/test_ltx_i2v_long_multi_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2026 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import torch

from diffusers import FlowMatchEulerDiscreteScheduler, LTXEulerAncestralRFScheduler, LTXI2VLongMultiPromptPipeline


@pytest.mark.parametrize("scheduler_cls", [FlowMatchEulerDiscreteScheduler, LTXEulerAncestralRFScheduler])
@pytest.mark.parametrize(
"sigmas", [None, [1.0, 0.5, 0.0], torch.tensor([1.0, 0.5, 0.0])], ids=["auto", "list", "tensor"]
)
def test_denoising_schedule_reaches_zero(scheduler_cls, sigmas):
scheduler = scheduler_cls()
pipe = LTXI2VLongMultiPromptPipeline(
scheduler=scheduler, vae=None, text_encoder=None, tokenizer=None, transformer=None
)
device = torch.device("cpu")
num_inference_steps = 2 if sigmas is None else 3

timesteps = pipe._prepare_timesteps(num_inference_steps, sigmas, device)

sample = torch.ones(1, device=device)
generator = torch.Generator(device=device).manual_seed(0)
for timestep in timesteps:
sample = scheduler.step(torch.ones_like(sample), timestep, sample, generator=generator, return_dict=False)[0]

assert scheduler.sigmas[scheduler.step_index].item() == 0.0
assert len(timesteps) == pipe.num_timesteps == 2


def test_flow_match_explicit_sigmas_without_terminal_zero():
scheduler = FlowMatchEulerDiscreteScheduler()
pipe = LTXI2VLongMultiPromptPipeline(
scheduler=scheduler, vae=None, text_encoder=None, tokenizer=None, transformer=None
)

timesteps = pipe._prepare_timesteps(3, [1.0, 0.5], torch.device("cpu"))

torch.testing.assert_close(timesteps, scheduler.timesteps)