Skip to content
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

[Mochi-1] ensuring to compute the fourier features in FP32 in Mochi encoder #10031

Merged
merged 6 commits into from
Nov 29, 2024
Merged
Changes from 5 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
5 changes: 3 additions & 2 deletions src/diffusers/models/autoencoders/autoencoder_kl_mochi.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ def __init__(self, start: int = 6, stop: int = 8, step: int = 1):

def forward(self, inputs: torch.Tensor) -> torch.Tensor:
r"""Forward method of the `FourierFeatures` class."""

original_dtype = inputs.dtype
inputs = inputs.to(torch.float32)
num_channels = inputs.shape[1]
num_freqs = (self.stop - self.start) // self.step

Expand All @@ -450,7 +451,7 @@ def forward(self, inputs: torch.Tensor) -> torch.Tensor:
# Scale channels by frequency.
h = w * h

return torch.cat([inputs, torch.sin(h), torch.cos(h)], dim=1)
return torch.cat([inputs, torch.sin(h), torch.cos(h)], dim=1).to(original_dtype)


class MochiEncoder3D(nn.Module):
Expand Down
Loading