src/transformers/file_utils.py/to_numpy
def to_numpy(obj):
    """
    Convert a TensorFlow tensor, PyTorch tensor, Numpy array or python list to a Numpy array.
    """
    if isinstance(obj, (dict, UserDict)):
        return {k: to_numpy(v) for k, v in obj.items()}
    elif isinstance(obj, (list, tuple)):
        return np.array(obj)
    elif is_tf_available() and _is_tensorflow(obj):
        return obj.numpy()
    elif is_torch_available() and _is_torch(obj):
        return obj.detach().cpu().numpy()
    elif is_flax_available() and _is_jax(obj):
        return np.asarray(obj)
    else:
        return obj