def _update_legacy_signature(signature):
  """Update a legacy name-mangled signature in-place.

  Note this code will not work if there are clashes between the old and new
  names, e.g. if x$dense_tensor$dense_tensor and x$dense_tensor are both
  features, but this is an edge case that we do not expect to ever happen.

  Args:
    signature: A SignatureDef.
  """
  for tensor_info_map in [signature.inputs, signature.outputs]:
    # It is necessary to make a copy of tensor_info_map.items() since we need to
    # modify tensor_info_map while iterating it.
    for original_name, original_tensor_info in list(tensor_info_map.items()):
      match = _MANGLED_TENSOR_NAME_RE.match(original_name)
      if not match:
        continue
      tf.compat.v1.logging.warn(
          'Converting feature %s from legacy signature.  New models will '
          'be written without name-mangling in the signature', original_name)
      name = match.group(1)
      if name == 'dense_shape':
        assert name not in tensor_info_map
      else:
        assert (name not in tensor_info_map or
                tensor_info_map[name].WhichOneof('encoding') == 'coo_sparse')
      new_tensor_info = tensor_info_map[name]
      original_tensor_type = match.group(2)
      if original_tensor_type == 'indices':
        new_tensor_info.coo_sparse.indices_tensor_name = (
            original_tensor_info.name)
      elif original_tensor_type == 'values':
        new_tensor_info.dtype = original_tensor_info.dtype
        new_tensor_info.coo_sparse.values_tensor_name = (
            original_tensor_info.name)
      elif original_tensor_type == 'dense_shape':
        new_tensor_info.coo_sparse.dense_shape_tensor_name = (
            original_tensor_info.name)
      else:
        new_tensor_info.CopyFrom(tensor_info_map[original_name])
      del tensor_info_map[original_name]
Update a legacy name-mangled signature in-place.

  Note this code will not work if there are clashes between the old and new
  names, e.g. if x$dense_tensor$dense_tensor and x$dense_tensor are both
  features, but this is an edge case that we do not expect to ever happen.

  Args:
    signature: A SignatureDef.
  
tensorflow_transform/saved/saved_transform_io.py