
"""simple docstring"""


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


_lowercase							   =				logging.get_logger(__name__)


_lowercase							   =				TypeVar('''DatasetType''', Dataset, IterableDataset)






def       _snake_case				(		snake_case__   :     List[DatasetType]	,      snake_case__   :     Optional[List[float]] = None	,      snake_case__   :     Optional[int] = None	,      snake_case__   :     Optional[DatasetInfo] = None	,      snake_case__   :     Optional[NamedSplit] = None	,      snake_case__   :     Literal["first_exhausted", "all_exhausted"] = "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(snake_case__     ):
  if not isinstance(snake_case__	,      (Dataset, IterableDataset)     ):
   if isinstance(snake_case__	,      (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(snake_case__     )}\n'
        F'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(snake_case__     )     )}\']'     )
   raise ValueError(
       F'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(snake_case__     ).__name__}.'     )
  if i == 0:
   A   ,      A						   =   (
       (Dataset, IterableDataset) if isinstance(snake_case__	,      snake_case__     ) else (IterableDataset, Dataset)
   )
  elif not isinstance(snake_case__	,      snake_case__     ):
   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(
      snake_case__	,      snake_case__	,      snake_case__	,      info=snake_case__	,      split=snake_case__	,      stopping_strategy=snake_case__     )
 else:
  return _interleave_iterable_datasets(
      snake_case__	,      snake_case__	,      snake_case__	,      info=snake_case__	,      split=snake_case__	,      stopping_strategy=snake_case__     )






def       _snake_case				(		snake_case__   :     List[DatasetType]	,      snake_case__   :     Optional[DatasetInfo] = None	,      snake_case__   :     Optional[NamedSplit] = None	,      snake_case__   :     int = 0	,      ):

 if not dsets:
  raise ValueError('Unable to concatenate an empty list of datasets.'     )
 for i, dataset in enumerate(snake_case__     ):
  if not isinstance(snake_case__	,      (Dataset, IterableDataset)     ):
   if isinstance(snake_case__	,      (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(snake_case__     )}\n'
        F'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(snake_case__     )     )}\']'     )
   raise ValueError(
       F'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(snake_case__     ).__name__}.'     )
  if i == 0:
   A   ,      A						   =   (
       (Dataset, IterableDataset) if isinstance(snake_case__	,      snake_case__     ) else (IterableDataset, Dataset)
   )
  elif not isinstance(snake_case__	,      snake_case__     ):
   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(snake_case__	,      info=snake_case__	,      split=snake_case__	,      axis=snake_case__     )
 else:
  return _concatenate_iterable_datasets(snake_case__	,      info=snake_case__	,      split=snake_case__	,      axis=snake_case__     )

"""simple docstring"""


from argparse import ArgumentParser

from . import BaseTransformersCLICommand






def       _snake_case				(		snake_case__   :     Optional[int]     ):
	return DownloadCommand(args.model	,      args.cache_dir	,      args.force	,      args.trust_remote_code     )







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						@staticmethod
						def 						_SCREAMING_SNAKE_CASE      ( A_     :      ArgumentParser      )     ->   Any:
							A						   =   parser.add_parser('download'      )
							download_parser.add_argument(
							    '--cache-dir'  ,type=A_  ,default=A_  ,help='Path to location to store the models'      )
							download_parser.add_argument(
							    '--force'  ,action='store_true'  ,help='Force the model to be download even if already in cache-dir'      )
							download_parser.add_argument(
							    '--trust-remote-code'  ,action='store_true'  ,help='Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you\'ve reviewed the code as it will execute on your local machine'  ,)
							download_parser.add_argument('model'  ,type=A_  ,help='Name of the model to download'      )
							download_parser.set_defaults(func=A_      )


						def __init__( self     :      Dict  ,A_     :      str  ,A_     :      str  ,A_     :      bool  ,A_     :      bool      )     ->   Union[str, Any]:
							A						   =   model
							A						   =   cache
							A						   =   force
							A						   =   trust_remote_code




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   Optional[int]:
							from ..models.auto import AutoModel, AutoTokenizer

							AutoModel.from_pretrained(
							    self._model  ,cache_dir=self._cache  ,force_download=self._force  ,trust_remote_code=self._trust_remote_code      )
							AutoTokenizer.from_pretrained(
							    self._model  ,cache_dir=self._cache  ,force_download=self._force  ,trust_remote_code=self._trust_remote_code      )