Skip to content

Fix wrong param types, docs, and handles noise=None in scale_noise of FlowMatching schedulers #11669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def set_shift(self, shift: float):
def scale_noise(
self,
sample: torch.FloatTensor,
timestep: Union[float, torch.FloatTensor],
timestep: torch.FloatTensor,
noise: Optional[torch.FloatTensor] = None,
) -> torch.FloatTensor:
"""
Expand All @@ -180,8 +180,10 @@ def scale_noise(
Args:
sample (`torch.FloatTensor`):
The input sample.
timestep (`int`, *optional*):
timestep (`torch.FloatTensor`):
The current timestep in the diffusion chain.
noise (`torch.FloatTensor`, *optional*):
The noise tensor.

Returns:
`torch.FloatTensor`:
Expand Down Expand Up @@ -212,6 +214,9 @@ def scale_noise(
while len(sigma.shape) < len(sample.shape):
sigma = sigma.unsqueeze(-1)

if noise is None:
noise = torch.randn_like(sample)

sample = sigma * noise + (1.0 - sigma) * sample

return sample
Expand Down
10 changes: 8 additions & 2 deletions src/diffusers/schedulers/scheduling_flow_match_heun_discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def set_begin_index(self, begin_index: int = 0):
def scale_noise(
self,
sample: torch.FloatTensor,
timestep: Union[float, torch.FloatTensor],
timestep: torch.FloatTensor,
noise: Optional[torch.FloatTensor] = None,
) -> torch.FloatTensor:
"""
Expand All @@ -119,8 +119,10 @@ def scale_noise(
Args:
sample (`torch.FloatTensor`):
The input sample.
timestep (`int`, *optional*):
timestep (`torch.FloatTensor`):
The current timestep in the diffusion chain.
noise (`torch.FloatTensor`, *optional*):
The noise tensor.

Returns:
`torch.FloatTensor`:
Expand All @@ -130,6 +132,10 @@ def scale_noise(
self._init_step_index(timestep)

sigma = self.sigmas[self.step_index]

if noise is None:
noise = torch.randn_like(sample)

sample = sigma * noise + (1.0 - sigma) * sample

return sample
Expand Down
9 changes: 7 additions & 2 deletions src/diffusers/schedulers/scheduling_flow_match_lcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def set_scale_factors(self, scale_factors: list, upscale_mode):
def scale_noise(
self,
sample: torch.FloatTensor,
timestep: Union[float, torch.FloatTensor],
timestep: torch.FloatTensor,
noise: Optional[torch.FloatTensor] = None,
) -> torch.FloatTensor:
"""
Expand All @@ -201,8 +201,10 @@ def scale_noise(
Args:
sample (`torch.FloatTensor`):
The input sample.
timestep (`int`, *optional*):
timestep (`torch.FloatTensor`):
The current timestep in the diffusion chain.
noise (`torch.FloatTensor`, *optional*):
The noise tensor.

Returns:
`torch.FloatTensor`:
Expand Down Expand Up @@ -233,6 +235,9 @@ def scale_noise(
while len(sigma.shape) < len(sample.shape):
sigma = sigma.unsqueeze(-1)

if noise is None:
noise = torch.randn_like(sample)

sample = sigma * noise + (1.0 - sigma) * sample

return sample
Expand Down