def _hashable_var_key(var):
  """Returns a hashable key to identify the given Variable."""

  # In TF 2, Variables themselves are not hashable, so cannot be dict keys.
  # Error is "Tensor is unhashable if Tensor equality is enabled. Instead, use
  # tensor.experimental_ref() as the key". For a related issue, see:
  # https://github.com/tensorflow/tensorflow/issues/32139
  ref_op = getattr(var, "experimental_ref", None)
  if callable(ref_op):
    return ref_op()
  return var