fix: preserve original dtype in Upsample instead of hardcoding bfloat16#233
Open
Mr-Neutr0n wants to merge 1 commit into
Open
fix: preserve original dtype in Upsample instead of hardcoding bfloat16#233Mr-Neutr0n wants to merge 1 commit into
Mr-Neutr0n wants to merge 1 commit into
Conversation
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.
Summary
The
Upsample.forwardmethod injanus/models/vq_model.pyhardcodes a cast totorch.bfloat16after interpolation when the input is not float32:This causes a problem when the input tensor is
float16(common on GPUs without native bfloat16 support, e.g. older NVIDIA architectures). The tensor is silently converted fromfloat16tobfloat16after interpolation, leading to dtype mismatches with downstream convolution layers that still expectfloat16weights.Fix
Store the original dtype before casting to float32 for interpolation, then cast back to it afterward:
This preserves whatever dtype the input originally had (float16, bfloat16, etc.) instead of always forcing bfloat16.
Test plan
float16input dtype through the upsample operationbfloat16inputs continue to work as before (orig_dtype would be bfloat16, matching the previous behavior)float32inputs (the else branch is unchanged)