Skip to content

Commit

Permalink
Remove the code that handles serializing raw tf.Tensor values to th…
Browse files Browse the repository at this point in the history
…e `Value` protobuf.

This change brings TFF closer to isolating the TF dependencies in the `tensorflow` package.

PiperOrigin-RevId: 649311211
  • Loading branch information
michaelreneer authored and copybara-github committed Jul 4, 2024
1 parent d2653ff commit d03cf52
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

## Unreleased

### Removed

* Serializing raw `tf.Tensor` values to the `Value` protobuf.

## Release 0.82.0

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ def _serialize_tensor_value(
ValueError: If the value is malformed.
"""
original_value = value
if tf.is_tensor(value):
if isinstance(value, tf.Variable):
value = value.read_value()
if isinstance(value, tf.Tensor) and not tf.is_symbolic_tensor(value):
value = value.numpy()
else:
# Attempt to extract the value using the current graph context.
with tf.compat.v1.Session() as sess:
value = sess.run(value)
# If we got a string or bytes scalar, wrap it in numpy so it has a dtype and
# shape.
if isinstance(value, (np.bytes_, np.str_, bytes, str)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,6 @@ def test_serialize_deserialize_tensor_value_unk_shape_without_hint(self):
self.assertEqual(y.dtype, serialize_type_spec.dtype)
self.assertAllEqual(x, y)

@parameterized.named_parameters(TENSOR_SERIALIZATION_TEST_PARAMS)
def test_serialize_deserialize_tensor_value_without_hint_graph_mode(
self, x, serialize_type_spec
):
# Test serializing non-eager tensors.
with tf.Graph().as_default():
tensor_x = tf.convert_to_tensor(x)
value_proto, value_type = value_serialization.serialize_value(
tensor_x, serialize_type_spec
)
type_test_utils.assert_types_identical(value_type, serialize_type_spec)
y, deserialize_type_spec = value_serialization.deserialize_value(
value_proto
)
type_test_utils.assert_types_identical(
deserialize_type_spec, serialize_type_spec
)
self.assertEqual(y.dtype, serialize_type_spec.dtype)
self.assertAllEqual(x, y)

@parameterized.named_parameters(TENSOR_SERIALIZATION_TEST_PARAMS)
def test_serialize_deserialize_tensor_value_with_hint(
self, x, serialize_type_spec
Expand Down

0 comments on commit d03cf52

Please sign in to comment.