




# Copyright 2022 The HuggingFace Team and The OpenBMB Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


UpperCamelCase__ :   Optional[int]						=							{
    '''configuration_cpmant''': ['''CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''CpmAntConfig'''],
    '''tokenization_cpmant''': ['''CpmAntTokenizer'''],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						UpperCamelCase__ :   Union[str, Any]						=							[
						    '''CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''CpmAntForCausalLM''',
						    '''CpmAntModel''',
						    '''CpmAntPreTrainedModel''',
						]


if TYPE_CHECKING:
						from .configuration_cpmant import CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP, CpmAntConfig
						from .tokenization_cpmant import CpmAntTokenizer

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_cpmant import (
												    CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    CpmAntForCausalLM,
												    CpmAntModel,
												    CpmAntPreTrainedModel,
												)


else:
						import sys

						UpperCamelCase__ :   Union[str, Any]						=							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)









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


UpperCamelCase__ :   Optional[Any]						=							logging.get_logger(__name__)


UpperCamelCase__ :   int						=							TypeVar('''DatasetType''', Dataset, IterableDataset)





def        __UpperCAmelCase						(							lowerCamelCase_ :     List[DatasetType]  ,							lowerCamelCase_ :     Optional[List[float]] = None  ,							lowerCamelCase_ :     Optional[int] = None  ,							lowerCamelCase_ :     Optional[DatasetInfo] = None  ,							lowerCamelCase_ :     Optional[NamedSplit] = None  ,							lowerCamelCase_ :     Literal["first_exhausted", "all_exhausted"] = "first_exhausted"  ,							)       ->  DatasetType:







			"""simple docstring"""





			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(lowerCamelCase_  ):
						if not isinstance(lowerCamelCase_  ,							(Dataset, IterableDataset)  ):
									if isinstance(lowerCamelCase_  ,							(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(lowerCamelCase_  )}\n'
												    F'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(lowerCamelCase_  )  )}\']'  )
									raise ValueError(
									    F'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(lowerCamelCase_  ).__name__}.'  )
						if i == 0:
									SCREAMING_SNAKE_CASE_  ,    SCREAMING_SNAKE_CASE_   : Dict					  =      (
									    (Dataset, IterableDataset) if isinstance(lowerCamelCase_  ,							lowerCamelCase_  ) else (IterableDataset, Dataset)
									)
						elif not isinstance(lowerCamelCase_  ,							lowerCamelCase_  ):
									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(
						    lowerCamelCase_  ,							lowerCamelCase_  ,							lowerCamelCase_  ,							info=lowerCamelCase_  ,							split=lowerCamelCase_  ,							stopping_strategy=lowerCamelCase_  )
			else:
						return _interleave_iterable_datasets(
						    lowerCamelCase_  ,							lowerCamelCase_  ,							lowerCamelCase_  ,							info=lowerCamelCase_  ,							split=lowerCamelCase_  ,							stopping_strategy=lowerCamelCase_  )





def        __UpperCAmelCase						(							lowerCamelCase_ :     List[DatasetType]  ,							lowerCamelCase_ :     Optional[DatasetInfo] = None  ,							lowerCamelCase_ :     Optional[NamedSplit] = None  ,							lowerCamelCase_ :     int = 0  ,							)       ->  DatasetType:







			"""simple docstring"""





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



