



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


lowerCAmelCase_  :							Tuple             =    logging.get_logger(__name__)


lowerCAmelCase_  :							Dict             =    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"       ,		):
							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(_SCREAMING_SNAKE_CASE					):
														if not isinstance(_SCREAMING_SNAKE_CASE       ,		(Dataset, IterableDataset)					):
																					if isinstance(_SCREAMING_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(_SCREAMING_SNAKE_CASE					)}\n"""
																												    F"""Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(_SCREAMING_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(_SCREAMING_SNAKE_CASE					).__name__}."""					)
														if i == 0:
																					SCREAMING_SNAKE_CASE       :   Dict         =      (
																					    (Dataset, IterableDataset) if isinstance(_SCREAMING_SNAKE_CASE       ,		_SCREAMING_SNAKE_CASE					) else (IterableDataset, Dataset)
																					)
														elif not isinstance(_SCREAMING_SNAKE_CASE       ,		_SCREAMING_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(
														    _SCREAMING_SNAKE_CASE       ,		_SCREAMING_SNAKE_CASE       ,		_SCREAMING_SNAKE_CASE       ,		info=_SCREAMING_SNAKE_CASE       ,		split=_SCREAMING_SNAKE_CASE       ,		stopping_strategy=_SCREAMING_SNAKE_CASE					)
							else:
														return _interleave_iterable_datasets(
														    _SCREAMING_SNAKE_CASE       ,		_SCREAMING_SNAKE_CASE       ,		_SCREAMING_SNAKE_CASE       ,		info=_SCREAMING_SNAKE_CASE       ,		split=_SCREAMING_SNAKE_CASE       ,		stopping_strategy=_SCREAMING_SNAKE_CASE					)






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

							if not dsets:
														raise ValueError('''Unable to concatenate an empty list of datasets.'''					)
							for i, dataset in enumerate(_SCREAMING_SNAKE_CASE					):
														if not isinstance(_SCREAMING_SNAKE_CASE       ,		(Dataset, IterableDataset)					):
																					if isinstance(_SCREAMING_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(_SCREAMING_SNAKE_CASE					)}\n"""
																												    F"""Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(_SCREAMING_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(_SCREAMING_SNAKE_CASE					).__name__}."""					)
														if i == 0:
																					SCREAMING_SNAKE_CASE       :   List[Any]         =      (
																					    (Dataset, IterableDataset) if isinstance(_SCREAMING_SNAKE_CASE       ,		_SCREAMING_SNAKE_CASE					) else (IterableDataset, Dataset)
																					)
														elif not isinstance(_SCREAMING_SNAKE_CASE       ,		_SCREAMING_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(_SCREAMING_SNAKE_CASE       ,		info=_SCREAMING_SNAKE_CASE       ,		split=_SCREAMING_SNAKE_CASE       ,		axis=_SCREAMING_SNAKE_CASE					)
							else:
														return _concatenate_iterable_datasets(_SCREAMING_SNAKE_CASE       ,		info=_SCREAMING_SNAKE_CASE       ,		split=_SCREAMING_SNAKE_CASE       ,		axis=_SCREAMING_SNAKE_CASE					)





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, List, Mapping, Optional

from packaging import version


if TYPE_CHECKING:
	from ... import PreTrainedTokenizer, TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import is_torch_available, logging


SCREAMING_SNAKE_CASE		:     List[str]         =	logging.get_logger(__name__)

SCREAMING_SNAKE_CASE		:     str         =	{
    "bigscience/bloom": "https://huggingface.co/bigscience/bloom/resolve/main/config.json",
    "bigscience/bloom-560m": "https://huggingface.co/bigscience/bloom-560m/blob/main/config.json",
    "bigscience/bloom-1b1": "https://huggingface.co/bigscience/bloom-1b1/blob/main/config.json",
    "bigscience/bloom-1b7": "https://huggingface.co/bigscience/bloom-1b7/blob/main/config.json",
    "bigscience/bloom-3b": "https://huggingface.co/bigscience/bloom-3b/blob/main/config.json",
    "bigscience/bloom-7b1": "https://huggingface.co/bigscience/bloom-7b1/blob/main/config.json",
}

class        UpperCamelCase						(				__a				):
						a__		:Any      =			'''bloom'''
						a__		:Optional[int]      =			['''past_key_values''']
						a__		:Tuple      =			{
						    '''num_hidden_layers''': '''n_layer''',
						    '''num_attention_heads''': '''n_head''',
						}





						def __init__(self			,     __UpperCamelCase=250_880			,     __UpperCamelCase=64			,     __UpperCamelCase=2			,     __UpperCamelCase=8			,     __UpperCamelCase=1E-5			,     __UpperCamelCase=0.02			,     __UpperCamelCase=True			,     __UpperCamelCase=1			,     __UpperCamelCase=2			,     __UpperCamelCase=False			,     __UpperCamelCase=0.0			,     __UpperCamelCase=0.0			,     __UpperCamelCase=1			,     __UpperCamelCase=False			,     **__UpperCamelCase			,     )				->				List[Any]:
												UpperCamelCase_		:							Dict  =		vocab_size
												# Backward compatibility with n_embed kwarg
												UpperCamelCase_		:							Optional[Any]  =		kwargs.pop("""n_embed"""			,     __UpperCamelCase						)
												UpperCamelCase_		:							List[Any]  =		hidden_size if n_embed is None else n_embed
												UpperCamelCase_		:							List[Any]  =		n_layer
												UpperCamelCase_		:							Optional[Any]  =		n_head
												UpperCamelCase_		:							List[str]  =		layer_norm_epsilon
												UpperCamelCase_		:							int  =		initializer_range
												UpperCamelCase_		:							List[str]  =		use_cache
												UpperCamelCase_		:							List[Any]  =		pretraining_tp
												UpperCamelCase_		:							Optional[int]  =		apply_residual_connection_post_layernorm
												UpperCamelCase_		:							Any  =		hidden_dropout
												UpperCamelCase_		:							Optional[Any]  =		attention_dropout

												UpperCamelCase_		:							List[str]  =		bos_token_id
												UpperCamelCase_		:							Optional[Any]  =		eos_token_id
												UpperCamelCase_		:							str  =		slow_but_exact

												super().__init__(bos_token_id=__UpperCamelCase			,     eos_token_id=__UpperCamelCase			,     **__UpperCamelCase						)


class        UpperCamelCase						(				__a				):
						a__		:Dict      =			version.parse('''1.12'''				)





						def __init__(self			,     __UpperCamelCase			,     __UpperCamelCase = "default"			,     __UpperCamelCase = None			,     __UpperCamelCase = False			,     )				->				List[str]:
												super().__init__(__UpperCamelCase			,     task=__UpperCamelCase			,     patching_specs=__UpperCamelCase			,     use_past=__UpperCamelCase						)
												if not getattr(self._config			,     """pad_token_id"""			,     __UpperCamelCase						):
																		# TODO: how to do that better?
																		UpperCamelCase_		:							Optional[Any]  =		0





						@property
						def        A_							(self						)				->				Mapping[str, Mapping[int, str]]:
												UpperCamelCase_		:							str  =		OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}						)
												if self.use_past:
																		# BLOOM stores values on dynamic axis 2. For more details see: https://github.com/huggingface/transformers/pull/18344
																		self.fill_with_past_key_values_(__UpperCamelCase			,     direction="""inputs"""			,     inverted_values_shape=__UpperCamelCase						)
																		UpperCamelCase_		:							int  =		{0: """batch""", 1: """past_sequence + sequence"""}
												else:
																		UpperCamelCase_		:							Dict  =		{0: """batch""", 1: """sequence"""}

												return common_inputs





						@property
						def        A_							(self						)				->				int:
												return self._config.n_layer





						@property
						def        A_							(self						)				->				int:
												return self._config.n_head





						@property
						def        A_							(self						)				->				float:
												return 1E-3





						def        A_							(self			,     __UpperCamelCase			,     __UpperCamelCase = -1			,     __UpperCamelCase = -1			,     __UpperCamelCase = False			,     __UpperCamelCase = None			,     )				->				Mapping[str, Any]:
												UpperCamelCase_		:							Union[str, Any]  =		super(__UpperCamelCase			,     self						).generate_dummy_inputs(
												    __UpperCamelCase			,     batch_size=__UpperCamelCase			,     seq_length=__UpperCamelCase			,     is_pair=__UpperCamelCase			,     framework=__UpperCamelCase						)

												# We need to order the input in the way they appears in the forward()
												UpperCamelCase_		:							List[Any]  =		OrderedDict({"""input_ids""": common_inputs["""input_ids"""]}						)

												# Need to add the past_keys
												if self.use_past:
																		if not is_torch_available():
																								raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""						)
																		else:
																								import torch

																								UpperCamelCase_,UpperCamelCase_		:							List[str]  =		common_inputs["""input_ids"""].shape
																								# Not using the same length for past_key_values
																								UpperCamelCase_		:							List[str]  =		seqlen + 2
																								UpperCamelCase_		:							Tuple  =		self._config.hidden_size // self.num_attention_heads
																								UpperCamelCase_		:							List[Any]  =		(
																								    batch * self.num_attention_heads,
																								    head_dim,
																								    past_key_values_length,
																								)
																								UpperCamelCase_		:							str  =		(
																								    batch * self.num_attention_heads,
																								    past_key_values_length,
																								    head_dim,
																								)
																								UpperCamelCase_		:							Any  =		[
																								    (torch.zeros(__UpperCamelCase						), torch.zeros(__UpperCamelCase						)) for _ in range(self.num_layers						)
																								]

												UpperCamelCase_		:							int  =		common_inputs["""attention_mask"""]
												if self.use_past:
																		UpperCamelCase_		:							List[str]  =		ordered_inputs["""attention_mask"""].dtype
																		UpperCamelCase_		:							Any  =		torch.cat(
																		    [ordered_inputs["""attention_mask"""], torch.ones(__UpperCamelCase			,     __UpperCamelCase			,     dtype=__UpperCamelCase						)]			,     dim=1						)

												return ordered_inputs





						@property
						def        A_							(self						)				->				int:
												return 13






