def _deep_tuple(x):
  """Converts nested `tuple`, `list`, or `dict` to nested `tuple`."""
  if hasattr(x, 'keys'):
    return _deep_tuple(tuple(x.items()))
  elif isinstance(x, (list, tuple)):
    return tuple(map(_deep_tuple, x))
  return x