Skip to content

Commit

Permalink
Same issue affects image2image, so do the same again
Browse files Browse the repository at this point in the history
  • Loading branch information
Vargol committed Oct 28, 2024
1 parent fa0612f commit 81e3001
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions invokeai/backend/flux/modules/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ def encode(self, x: Tensor, sample: bool = True, generator: torch.Generator | No
Tensor: Encoded latent tensor. Shape: (batch_size, z_channels, latent_height, latent_width).
"""

# VAE is broken in float16, use same logic in model loading to pick bfloat16 or float32
if x.dtype == torch.float16:
try:
x = x.to(torch.bfloat16)
except TypeError:
x = x.to(torch.float32)
z = self.reg(self.encoder(x), sample=sample, generator=generator)
z = self.scale_factor * (z - self.shift_factor)
return z
Expand Down

0 comments on commit 81e3001

Please sign in to comment.