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

Fix latents.dtype before vae.decode() at ROCm devices in StableDiffusionPipelines #7886

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/diffusers/pipelines/controlnet/pipeline_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down Expand Up @@ -1048,6 +1050,8 @@ def __call__(
xm.mark_step()

if not output_type == "latent":
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False, generator=generator)[
0
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ def decode_latents(self, latents):
deprecate("decode_latents", "1.0.0", deprecation_message, standard_warn=False)

latents = 1 / self.vae.config.scaling_factor * latents
if torch.cuda.is_available() and torch.version.hip:
latents = latents.to(dtype=self.vae.dtype)
image = self.vae.decode(latents, return_dict=False)[0]
image = (image / 2 + 0.5).clamp(0, 1)
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
Expand Down