def _serialize_op_attr(op_attr):
  """Deterministicly serializes tf.Operation attrs since it is a map."""
  sorted_attributes = sorted(op_attr.items(), key=lambda kv: kv[0])
  if 'f' in op_attr:
    # This is a tf.Function node, and it includes attributes that are
    # inconsistent across runs such as _gradient_op_type, config_proto, so we
    # only keep input and output types since other information will arrive from
    # the FuncGraph attributes.
    sorted_attributes = [
        kv for kv in sorted_attributes if kv[0] in ('Tin', 'Tout')
    ]
  result = []
  for key, attr_value in sorted_attributes:
    result.append(key)
    attr_value = copy.deepcopy(attr_value)
    if attr_value.list.func:
      raise ValueError(
          'Unable to serialize op attributes that contain a `list.func` field')
    if attr_value.HasField('func'):
      # There should be a separate call for the FuncGraph attributes.
      attr_value.ClearField('func')
    result.append(attr_value.SerializeToString())
  return result
Deterministicly serializes tf.Operation attrs since it is a map.
tensorflow_transform/graph_tools.py