keras icon indicating copy to clipboard operation
keras copied to clipboard

Use the exported `keras.Variable` class throughout code.

Open hertschuh opened this issue 1 year ago • 1 comments

The exported keras.Variable class is a subclass of the backend specific implementation. However, that public class was not used internally to create variables, for instance via add_weight().

There was no convenient way to detect that a tensor really is a variable. This code would print False:

v = self.add_weight(x)
print(isinstance(v, keras.Variable)

This change makes keras.Variable the actual class used internally. The only exception is in SeedGenerator with an overridden backend.

hertschuh avatar Oct 07 '24 16:10 hertschuh

Codecov Report

Attention: Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.

Project coverage is 73.98%. Comparing base (8f5592b) to head (5e108b7).

Files with missing lines Patch % Lines
keras/src/backend/jax/core.py 0.00% 1 Missing :warning:
keras/src/backend/numpy/core.py 75.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20330      +/-   ##
==========================================
- Coverage   78.85%   73.98%   -4.88%     
==========================================
  Files         513      512       -1     
  Lines       49250    49243       -7     
  Branches     9080     7951    -1129     
==========================================
- Hits        38837    36430    -2407     
- Misses       8543    11026    +2483     
+ Partials     1870     1787      -83     
Flag Coverage Δ
keras 73.87% <93.54%> (-4.85%) :arrow_down:
keras-jax ?
keras-numpy 57.42% <83.87%> (+0.04%) :arrow_up:
keras-tensorflow 63.65% <67.74%> (+0.02%) :arrow_up:
keras-torch 62.38% <77.41%> (+0.02%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 07 '24 16:10 codecov-commenter

Updated for all of exports.py

hertschuh avatar Oct 10 '24 21:10 hertschuh