def tensor_to_numpy(tensor):
  """Convert numpy if not already numpy array."""
  if isinstance(tensor, np.ndarray):
    return tensor
  else:
    return tensor.numpy()
Convert numpy if not already numpy array.
language/mentionmemory/utils/test_utils.py