Skip to content

Commit 098231f

Browse files
qlzh727tensorflower-gardener
authored andcommitted
Remove the usage of assert_splits_match (private TF API) in keras.
PiperOrigin-RevId: 351476101 Change-Id: I0ec178cb91985416066d5a6039064234f6e65e23
1 parent 1b79249 commit 098231f

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

‎tensorflow/python/keras/utils/metrics_utils.py‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from tensorflow.python.ops import nn_ops
3939
from tensorflow.python.ops import weights_broadcast_ops
4040
from tensorflow.python.ops.ragged import ragged_tensor
41-
from tensorflow.python.ops.ragged import ragged_util
4241
from tensorflow.python.tpu import tpu
4342
from tensorflow.python.util import tf_decorator
4443

@@ -513,11 +512,11 @@ def ragged_assert_compatible_and_get_flat_values(values, mask=None):
513512
# tf.TensorShape `assert_is_compatible_with`
514513
# check if both dynamic dimensions are equal and then use the flat_values.
515514
nested_row_split_list = [rt.nested_row_splits for rt in values]
516-
assertion_list = ragged_util.assert_splits_match(nested_row_split_list)
515+
assertion_list = _assert_splits_match(nested_row_split_list)
517516

518517
# if both are ragged sample_weights also should be ragged with same dims.
519518
if isinstance(mask, ragged_tensor.RaggedTensor):
520-
assertion_list_for_mask = ragged_util.assert_splits_match(
519+
assertion_list_for_mask = _assert_splits_match(
521520
[nested_row_split_list[0], mask.nested_row_splits])
522521
tmp = control_flow_ops.with_dependencies(assertion_list_for_mask,
523522
mask.flat_values)
@@ -539,3 +538,31 @@ def ragged_assert_compatible_and_get_flat_values(values, mask=None):
539538
raise TypeError('Ragged mask is not allowed with non-ragged inputs.')
540539

541540
return values, mask
541+
542+
543+
def _assert_splits_match(nested_splits_lists):
544+
"""Checks that the given splits lists are identical.
545+
546+
Performs static tests to ensure that the given splits lists are identical,
547+
and returns a list of control dependency op tensors that check that they are
548+
fully identical.
549+
550+
Args:
551+
nested_splits_lists: A list of nested_splits_lists, where each split_list is
552+
a list of `splits` tensors from a `RaggedTensor`, ordered from outermost
553+
ragged dimension to innermost ragged dimension.
554+
555+
Returns:
556+
A list of control dependency op tensors.
557+
Raises:
558+
ValueError: If the splits are not identical.
559+
"""
560+
error_msg = 'Inputs must have identical ragged splits'
561+
for splits_list in nested_splits_lists:
562+
if len(splits_list) != len(nested_splits_lists[0]):
563+
raise ValueError(error_msg)
564+
return [
565+
check_ops.assert_equal(s1, s2, message=error_msg) # pylint: disable=g-complex-comprehension
566+
for splits_list in nested_splits_lists[1:]
567+
for (s1, s2) in zip(nested_splits_lists[0], splits_list)
568+
]

0 commit comments

Comments
 (0)