Skip to content

Wrap tf variables in keras variables for TFSMLayer #20995

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

Merged
merged 1 commit into from
Mar 8, 2025

Conversation

mattdangerw
Copy link
Member

Fixes #20955

@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.43%. Comparing base (b36a9ac) to head (7ac025c).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20995      +/-   ##
==========================================
- Coverage   82.45%   82.43%   -0.02%     
==========================================
  Files         562      562              
  Lines       53316    53404      +88     
  Branches     8259     8275      +16     
==========================================
+ Hits        43960    44023      +63     
- Misses       7340     7361      +21     
- Partials     2016     2020       +4     
Flag Coverage Δ
keras 82.25% <100.00%> (-0.02%) ⬇️
keras-jax 63.93% <33.33%> (-0.11%) ⬇️
keras-numpy 58.87% <33.33%> (+0.02%) ⬆️
keras-openvino 32.64% <0.00%> (-0.05%) ⬇️
keras-tensorflow 64.37% <100.00%> (-0.11%) ⬇️
keras-torch 63.98% <33.33%> (-0.11%) ⬇️

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.

Copy link
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@@ -124,6 +127,8 @@ def _map_aggregation(self, aggregation):


def convert_to_tensor(x, dtype=None, sparse=None, ragged=None):
if isinstance(x, tf.Variable):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shortcut needs to make sure the dtype matches or is None, otherwise it's incorrect.

I think you'll have to move this up:

if dtype is not None:
        dtype = standardize_dtype(dtype)

and then do:

if isinstance(x, tf.Variable) and (dtype is None or x.dtype == dtype):
  return x

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that's why the unit tests are failing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Actually looks like we can just stick to the main path in convert_to_tensor, as tf.is_tensor(variable) == True. I think we were missing a conversion when comparing dtypes though, we were comparing tf dtype, to standardized string dtype in one spot.

Trying a fix.

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Mar 8, 2025
@fchollet fchollet merged commit 2ebe3d6 into keras-team:master Mar 8, 2025
10 checks passed
@google-ml-butler google-ml-butler bot removed awaiting review ready to pull Ready to be merged into the codebase labels Mar 8, 2025
11happy pushed a commit to 11happy/keras that referenced this pull request Mar 9, 2025
Hmm-1224 pushed a commit to Hmm-1224/keras that referenced this pull request Apr 5, 2025
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.

Error with variable.regularizer in keras.layers.TFSMLayer
6 participants