Fix AuraFlow VAE dtype mismatch on pipeline reuse#14184
Open
IvenHsu01 wants to merge 1 commit into
Open
Conversation
upcast_vae() upcasts the whole VAE to float32 in place, so on a second __call__ needs_upcasting is False and the latents cast guarded by that branch is skipped, feeding fp16 latents to the fp32 VAE. Cast the latents to the VAE dtype inline at the decode call so it always runs, matching the fix applied to pixart_sigma in huggingface#8391.
Contributor
|
Hi @IvenHsu01, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 VAE dtype-mismatch
RuntimeErrorinAuraFlowPipelinethat occurs whenthe same pipeline instance is called more than once.
upcast_vae()upcasts the whole VAE to float32 in place, so on the second callneeds_upcastingisFalseand thelatents.to(...)cast (guarded by thatif) is skipped, feeding fp16 latents to the fp32 VAE. This applies the samepattern already merged for
pixart_sigmain #8391 — cast the latents to the VAEdtype inline at the decode call so it always runs.
if needs_upcasting: self.upcast_vae() - latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype) - image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0] + image = self.vae.decode(latents.to(self.vae.dtype) / self.vae.config.scaling_factor, return_dict=False)[0]Companion PR to #14183, which has the full analysis and verification.
Happy to adjust the scope or approach based on maintainer feedback there.
Coordination
Tests run
Applied this exact change, no other patches, ran warmup + 1 run (the 2nd call
triggers the bug) at 512x512, 50 steps, guidance 3.5, seed 42:
Before submitting
Who can review?
@yiyixuxu @sayakpaul