[Fix bugs] pipeline_controlnet_sd_xl.py #6653
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a upcasting bug.
Let's have a quick review here.
Assuming that we set our model to float16. At the first
if
, the vae and latents are upcasted to float32 for avoiding overflow. Then,needs_upcasting
is False as the vae is in float32 now. The image is decoded in float32. Everything works fine.But if we conduct the second inference, the vae is still in float32 while the latents is in float16, then we will encounter
RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same
. Removing the first few lines solves the problem.