Skip to content

Conversation

@leisuzz
Copy link
Contributor

@leisuzz leisuzz commented Aug 19, 2024

What does this PR do?

Fixes #6879, and #9200

I fixed the RuntimeError: expected mat1 and mat2 to have the same dtype, as well as the similar issues when processing model_pred by fixing the same dtype.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@yiyixuxu yiyixuxu requested a review from sayakpaul August 19, 2024 18:15
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

# Add noise to the model input according to the noise magnitude at each timestep
# (this is the forward diffusion process)
noisy_model_input = noise_scheduler.add_noise(model_input, noise, timesteps)
noisy_model_input = noise_scheduler.add_noise(model_input, noise, timesteps).to(dtype=weight_dtype)
Copy link
Member

Choose a reason for hiding this comment

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

Let's do this conditionally if the dtype of noisy_model_input doesn't match with vae.dtype?

Copy link
Contributor Author

@leisuzz leisuzz Aug 20, 2024

Choose a reason for hiding this comment

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

Thanks for your feedback, actually I tested several times, and I found the dtype error actually happens in:

model_pred = unet(
                    noisy_model_input,
                    timesteps,
                    prompt_embeds,
                    added_cond_kwargs=unet_added_conditions,
                    return_dict=False,
                )[0]

So I think it may not affect the vae. Further, the model_pred will be model_pred.float() in the loss part.

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Thank you! Just a single comment.

@sayakpaul sayakpaul merged commit eda36c4 into huggingface:main Aug 20, 2024
sayakpaul added a commit that referenced this pull request Dec 23, 2024
Fix dtype error

Co-authored-by: 蒋硕 <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
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.

Custom Diffusion: RuntimeError: expected mat1 and mat2 to have the same dtype, but got: c10::Half != float

3 participants