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 the issue (#2102): Add cast to float32 from float16 into Stable D… #2124

Conversation

ghost
Copy link

@ghost ghost commented Nov 1, 2023

What does this PR do?

This PR fixed Issue #2102 (InvalidArgumentError occurred when I implemeted image generation using mixed float16) .

Fixes # (issue)
#2102

Who can review?

@ianstenbit
@jbischof
Someone who know this problem.

Copy link
Contributor

@ianstenbit ianstenbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@@ -235,6 +235,8 @@ def generate_image(
+ unconditional_guidance_scale * (latent - unconditional_latent)
)
a_t, a_prev = alphas[index], alphas_prev[index]
if latent.dtype == "float16":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to unconditionally cast latent to the dtype of latent_prev, e.g. ops.cast(latent, latent_prev.dtype).

Is there a reason that won't work?

Copy link
Author

@ghost ghost Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianstenbit
Thank you very much for your comment.
I think you are right!
I will try your advice and modify the code!!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianstenbit
I tried your suggestion and modified the code!
Thank you!!
If there is no problem, please approve my modification.

@ghost ghost force-pushed the add_cast_to_fp32_from_fp16_into_stable_diffusion branch from cc214e6 to 3c2f897 Compare November 2, 2023 08:29
Copy link
Contributor

@ianstenbit ianstenbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good -- thanks for the PR!

@ianstenbit
Copy link
Contributor

/gcbrun

@ianstenbit ianstenbit merged commit 2ac0943 into keras-team:master Nov 2, 2023
9 checks passed
ghost pushed a commit to y-vectorfield/keras-cv that referenced this pull request Nov 16, 2023
yuvraj-wale pushed a commit to yuvraj-wale/keras-cv that referenced this pull request Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants