Skip to content

[BUG] FlowMatchEulerDiscreteScheduler.__init__ computes sigma_min/sigma_max after shift, causing duplicate shift in set_timesteps #13243

Description

@Xilluill

Describe the bug

There is an initialization order issue in the FlowMatchEulerDiscreteScheduler class that causes set_timesteps to apply timestep shifting twice, resulting in different sigma values for the same timestep settings.

sigmas = shift * sigmas / (1 + (shift - 1) * sigmas)
self.timesteps = sigmas * num_train_timesteps
self._step_index = None
self._begin_index = None
self._shift = shift
self.sigmas = sigmas.to("cpu") # to avoid too much CPU/GPU communication
self.sigma_min = self.sigmas[-1].item()
self.sigma_max = self.sigmas[0].item()

Then in the set_timesteps method:
if sigmas is None:
if timesteps is None:
timesteps = np.linspace(
self._sigma_to_t(self.sigma_max),
self._sigma_to_t(self.sigma_min),
num_inference_steps,
)
sigmas = timesteps / self.config.num_train_timesteps
else:
sigmas = np.array(sigmas).astype(np.float32)
num_inference_steps = len(sigmas)
# 2. Perform timestep shifting. Either no shifting is applied, or resolution-dependent shifting of
# "exponential" or "linear" type is applied
if self.config.use_dynamic_shifting:
sigmas = self.time_shift(mu, 1.0, sigmas)
else:
sigmas = self.shift * sigmas / (1 + (self.shift - 1) * sigmas)

sigma_min will be saved after shift and used to generate a new list of sigma, then there is another shift happening :).

Reproduction

scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(
os.path.join(model_path, "scheduler"),
)

default scheduler.num_train_timesteps=1000,shift=3.0

print(scheduler.sigmas)
scheduler.set_timesteps(1000)
print(scheduler.sigmas)

Logs

System Info

Environment
diffusers version
Python 3.13
Affected file: diffusers/schedulers/scheduling_flow_match_euler_discrete.py

Who can help?

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions