Repository navigation
fix(fx): FuseBiasInLinear must preserve input dtype for float16/bfloat16 - #2548
Closed
davrens101 wants to merge 1 commit into
Closed
davrens101 wants to merge 1 commit into
davrens101 wants to merge 1 commit into
Conversation
The fused constant ones tensor was created with torch.ones(shape, device=...) using the default float32 dtype. Concatenating it with a float16/bfloat16 linear input upcasts the input and raises RuntimeError: expected m1 and m2 to have the same dtype (or silently corrupts the result). Pass dtype=linear_input.dtype so the fused constant matches the input, keeping the transformation dtype-transparent and bit-exact. Fixes huggingface#2532 Signed-off-by: Davis Rens <166565828+davrens101@users.noreply.github.com>
2 of 4 tasks
Author
|
Closing this PR. gorkadabo1 opened #2533 on October 17 to fix the same issue with regression tests, and I missed it before opening this one. Apologies for the duplicate work. |
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.
Fixes #2532
Summary
The fused constant ones tensor was created with torch.ones(shape, device=...)
using the default float32 dtype. Concatenating it with a float16/bfloat16
linear input raises RuntimeError: expected m1 and m2 to have the same dtype
(or silently corrupts the result).
Pass dtype=linear_input.dtype so the fused constant matches the input,
keeping the transformation dtype-transparent and bit-exact.
Verification
bit-exact vs original).