





"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__magic_name__       :					Any						=			{
    """configuration_ctrl""": ["""CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP""", """CTRLConfig"""],
    """tokenization_ctrl""": ["""CTRLTokenizer"""],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__magic_name__       :					Tuple						=			[
		    """CTRL_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """CTRLForSequenceClassification""",
		    """CTRLLMHeadModel""",
		    """CTRLModel""",
		    """CTRLPreTrainedModel""",
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__magic_name__       :					int						=			[
		    """TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """TFCTRLForSequenceClassification""",
		    """TFCTRLLMHeadModel""",
		    """TFCTRLModel""",
		    """TFCTRLPreTrainedModel""",
		]


if TYPE_CHECKING:
		from .configuration_ctrl import CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP, CTRLConfig
		from .tokenization_ctrl import CTRLTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_ctrl import (
				    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
				    CTRLForSequenceClassification,
				    CTRLLMHeadModel,
				    CTRLModel,
				    CTRLPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_ctrl import (
				    TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFCTRLForSequenceClassification,
				    TFCTRLLMHeadModel,
				    TFCTRLModel,
				    TFCTRLPreTrainedModel,
				)

else:
		import sys

		__magic_name__       :					str						=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)








"""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


a_							=    logging.get_logger(__name__)


a_							=    TypeVar("""DatasetType""", Dataset, IterableDataset)

def     UpperCAmelCase_					(				__a   :			List[DatasetType]      ,							__a   :			Optional[List[float]] = None      ,							__a   :			Optional[int] = None      ,							__a   :			Optional[DatasetInfo] = None      ,							__a   :			Optional[NamedSplit] = None      ,							__a   :			Literal["first_exhausted", "all_exhausted"] = "first_exhausted"      ,							):




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



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




			'''simple docstring'''



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





