



a_      :      Union[str, Any]    =     {
    'Pillow': 'Pillow',
    'accelerate': 'accelerate>=0.11.0',
    'compel': 'compel==0.1.8',
    'black': 'black~=23.1',
    'datasets': 'datasets',
    'filelock': 'filelock',
    'flax': 'flax>=0.4.1',
    'hf-doc-builder': 'hf-doc-builder>=0.3.0',
    'huggingface-hub': 'huggingface-hub>=0.13.2',
    'requests-mock': 'requests-mock==1.10.0',
    'importlib_metadata': 'importlib_metadata',
    'invisible-watermark': 'invisible-watermark',
    'isort': 'isort>=5.5.4',
    'jax': 'jax>=0.2.8,!=0.3.2',
    'jaxlib': 'jaxlib>=0.1.65',
    'Jinja2': 'Jinja2',
    'k-diffusion': 'k-diffusion>=0.0.12',
    'torchsde': 'torchsde',
    'note_seq': 'note_seq',
    'librosa': 'librosa',
    'numpy': 'numpy',
    'omegaconf': 'omegaconf',
    'parameterized': 'parameterized',
    'protobuf': 'protobuf>=3.20.3,<4',
    'pytest': 'pytest',
    'pytest-timeout': 'pytest-timeout',
    'pytest-xdist': 'pytest-xdist',
    'ruff': 'ruff>=0.0.241',
    'safetensors': 'safetensors',
    'sentencepiece': 'sentencepiece>=0.1.91,!=0.1.92',
    'scipy': 'scipy',
    'onnx': 'onnx',
    'regex': 'regex!=2019.12.17',
    'requests': 'requests',
    'tensorboard': 'tensorboard',
    'torch': 'torch>=1.4',
    'torchvision': 'torchvision',
    'transformers': 'transformers>=4.25.1',
    'urllib3': 'urllib3<=2.0.0',
}










from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


a_      :      Any    =     logging.get_logger(__name__)


a_      :      str    =     TypeVar('DatasetType', Dataset, IterableDataset)






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase = None							,  __UpperCAmelCase = None							,  __UpperCAmelCase = None							,  __UpperCAmelCase = None							,  __UpperCAmelCase = "first_exhausted"							,  ):
 from .arrow_dataset import Dataset
 from .iterable_dataset import IterableDataset

 if not datasets:
  raise ValueError('''Unable to interleave an empty list of datasets.'''       )
 for i, dataset in enumerate(__UpperCAmelCase       ):
  if not isinstance(__UpperCAmelCase							,  (Dataset, IterableDataset)       ):
   if isinstance(__UpperCAmelCase							,  (DatasetDict, IterableDatasetDict)       ):
    if not dataset:
     raise ValueError(
         f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
         '''is an empty dataset dictionary.'''       )
    raise ValueError(
        f"Dataset at position {i} has at least one split: {list(__UpperCAmelCase       )}\n"
        f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCAmelCase       )       )}']"       )
   raise ValueError(
       f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCAmelCase       ).__name__}."       )
  if i == 0:
   a__							,			a__												= (
       (Dataset, IterableDataset) if isinstance(__UpperCAmelCase							,  __UpperCAmelCase       ) else (IterableDataset, Dataset)
   )
  elif not isinstance(__UpperCAmelCase							,  __UpperCAmelCase       ):
   raise ValueError(
       f"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."       )
 if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
  raise ValueError(f"{stopping_strategy} is not supported. Please enter a valid stopping_strategy."       )
 if dataset_type is Dataset:
  return _interleave_map_style_datasets(
      __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  info=__UpperCAmelCase							,  split=__UpperCAmelCase							,  stopping_strategy=__UpperCAmelCase       )
 else:
  return _interleave_iterable_datasets(
      __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  info=__UpperCAmelCase							,  split=__UpperCAmelCase							,  stopping_strategy=__UpperCAmelCase       )






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase = None							,  __UpperCAmelCase = None							,  __UpperCAmelCase = 0							,  ):

 if not dsets:
  raise ValueError('''Unable to concatenate an empty list of datasets.'''       )
 for i, dataset in enumerate(__UpperCAmelCase       ):
  if not isinstance(__UpperCAmelCase							,  (Dataset, IterableDataset)       ):
   if isinstance(__UpperCAmelCase							,  (DatasetDict, IterableDatasetDict)       ):
    if not dataset:
     raise ValueError(
         f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
         '''is an empty dataset dictionary.'''       )
    raise ValueError(
        f"Dataset at position {i} has at least one split: {list(__UpperCAmelCase       )}\n"
        f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCAmelCase       )       )}']"       )
   raise ValueError(
       f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCAmelCase       ).__name__}."       )
  if i == 0:
   a__							,			a__												= (
       (Dataset, IterableDataset) if isinstance(__UpperCAmelCase							,  __UpperCAmelCase       ) else (IterableDataset, Dataset)
   )
  elif not isinstance(__UpperCAmelCase							,  __UpperCAmelCase       ):
   raise ValueError(
       f"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."       )
 if dataset_type is Dataset:
  return _concatenate_map_style_datasets(__UpperCAmelCase							,  info=__UpperCAmelCase							,  split=__UpperCAmelCase							,  axis=__UpperCAmelCase       )
 else:
  return _concatenate_iterable_datasets(__UpperCAmelCase							,  info=__UpperCAmelCase							,  split=__UpperCAmelCase							,  axis=__UpperCAmelCase       )





