code: def _deduplicate_batch_indexed_slices(
      batched_values: tf.Tensor, indices: tf.Tensor
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Removes duplication of indexed slices by summing them."""
      perm = tf.concat(
          [
              tf.constant([1, 0], dtype=tf.int32),
              tf.range(tf.rank(batched_values))[2:],
          ],
          axis=0,
      )
      batched_values = tf.transpose(batched_values, perm=perm)
      unique_indices, new_pos = tf.unique(indices)
      summed_values = tf.math.unsorted_segment_sum(
          batched_values, new_pos, tf.shape(unique_indices)[0]
      )
      return tf.transpose(summed_values, perm=perm), unique_indices
  
imports: from typing import Any, Dict, List, Optional, Tuple, TypeVar, Union
  import tensorflow
  from tensorflow.python.ops.parallel_for import control_flow_ops
label_desc: Use image node_id 1 for calling a global function with example usage: _deduplicate_batch_indexed_slices(batched_values, indices) and returns: tf,  unique_indices