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
2 changes: 1 addition & 1 deletion src/diffusers/schedulers/scheduling_lms_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def step(
self.derivatives.pop(0)

# 3. Compute linear multistep coefficients
order = min(self.step_index + 1, order)
order = min(self.step_index + 1, len(self.derivatives), order)
lms_coeffs = [self.get_lms_coefficient(order, self.step_index, curr_order) for curr_order in range(order)]

# 4. Compute previous sample based on the derivatives path
Expand Down
30 changes: 28 additions & 2 deletions tests/schedulers/test_scheduler_lms.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,34 @@ def test_full_loop_with_noise(self):
result_sum = torch.sum(torch.abs(sample))
result_mean = torch.mean(torch.abs(sample))

assert abs(result_sum.item() - 27663.6895) < 1e-2
assert abs(result_mean.item() - 36.0204) < 1e-3
assert abs(result_sum.item() - 57074.7617) < 1e-2
assert abs(result_mean.item() - 74.3161) < 1e-3

def test_step_order_with_begin_index(self):
scheduler_class = self.scheduler_classes[0]
scheduler_config = self.get_scheduler_config()
scheduler = scheduler_class(**scheduler_config)

scheduler.set_timesteps(self.num_inference_steps)
scheduler.set_begin_index(5)

sample = self.dummy_sample_deter
model_output = self.dummy_noise_deter

# On the first step starting at begin_index, only 1 derivative is available
# so the update must match first-order Euler step (order=1)
sigma_curr = scheduler.sigmas[5]
sigma_next = scheduler.sigmas[6]
derivative = (sample - (sample - sigma_curr * model_output)) / sigma_curr
expected_prev = sample + (sigma_next - sigma_curr) * derivative

output = scheduler.step(model_output, scheduler.timesteps[5], sample)
assert torch.allclose(output.prev_sample, expected_prev, atol=1e-5)
assert len(scheduler.derivatives) == 1

# Second step accumulates a second derivative
scheduler.step(model_output, scheduler.timesteps[6], output.prev_sample)
assert len(scheduler.derivatives) == 2

def test_beta_sigmas(self):
self.check_over_configs(use_beta_sigmas=True)
Expand Down
Loading