Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

james77777778
Copy link
Contributor

There is a bug in torch's convert_to_tensor when the input is a Variable.

The root cause is that we return x.variable directly without checking its dtype.
This PR fixes the issue.

@codecov-commenter
Copy link

codecov-commenter commented Jul 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.74%. Comparing base (18ab462) to head (81f62b8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21452   +/-   ##
=======================================
  Coverage   82.74%   82.74%           
=======================================
  Files         565      565           
  Lines       55300    55305    +5     
  Branches     8624     8625    +1     
=======================================
+ Hits        45756    45764    +8     
+ Misses       7439     7438    -1     
+ Partials     2105     2103    -2     
Flag Coverage Δ
keras 82.56% <100.00%> (+<0.01%) ⬆️
keras-jax 63.34% <37.50%> (-0.01%) ⬇️
keras-numpy 58.54% <37.50%> (+<0.01%) ⬆️
keras-openvino 33.79% <75.00%> (+<0.01%) ⬆️
keras-tensorflow 63.76% <37.50%> (-0.01%) ⬇️
keras-torch 63.38% <62.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -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)
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants