-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Fix torch's convert_to_tensor
not respecting dtype
when input is a Variable
#21452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix torch's convert_to_tensor
not respecting dtype
when input is a Variable
#21452
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #21452 +/- ##
=======================================
Coverage 82.74% 82.74%
=======================================
Files 565 565
Lines 55300 55302 +2
Branches 8624 8625 +1
=======================================
+ Hits 45756 45761 +5
+ Misses 7439 7438 -1
+ Partials 2105 2103 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
keras/src/ops/nn.py
Outdated
@@ -2816,7 +2816,8 @@ def _rms_normalization(x, scale=None, axis=-1, epsilon=None): | |||
|
|||
x = backend.convert_to_tensor(x, dtype=compute_dtype) | |||
if scale is not None: | |||
scale = backend.convert_to_tensor(scale, x.dtype) | |||
scale = backend.convert_to_tensor(scale) | |||
scale = backend.cast(scale, x.dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would 2 separate lines be necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I was testing the behavior and forgot to revert them.
Fixed. I also modified the tests in nn_test.py
to use variables as inputs to verify the changes.
There is a bug in torch's
convert_to_tensor
when the input is aVariable
.The root cause is that we return
x.variable
directly without checking its dtype.This PR fixes the issue.