





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


snake_case_							=			logging.get_logger(__name__)

snake_case_							=			{
    '''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        snake_case_		(			_A):

		'''simple docstring'''





		lowerCamelCase    :List[str]						=     """bloom"""
		lowerCamelCase    :Any						=     ["""past_key_values"""]
		lowerCamelCase    :Dict						=     {
		    """num_hidden_layers""": """n_layer""",
		    """num_attention_heads""": """n_head""",
		}







		def __init__(		self			,     __lowercase=2_5_0_8_8_0			,     __lowercase=6_4			,     __lowercase=2			,     __lowercase=8			,     __lowercase=1e-5			,     __lowercase=0.0_2			,     __lowercase=True			,     __lowercase=1			,     __lowercase=2			,     __lowercase=False			,     __lowercase=0.0			,     __lowercase=0.0			,     __lowercase=1			,     __lowercase=False			,     **__lowercase			,     )				->   str:
				lowerCamelCase   : Union[str, Any]								=vocab_size
				# Backward compatibility with n_embed kwarg
				lowerCamelCase   : List[Any]								=kwargs.pop('''n_embed'''			,     __lowercase   )
				lowerCamelCase   : Union[str, Any]								=hidden_size if n_embed is None else n_embed
				lowerCamelCase   : int								=n_layer
				lowerCamelCase   : Optional[Any]								=n_head
				lowerCamelCase   : Union[str, Any]								=layer_norm_epsilon
				lowerCamelCase   : str								=initializer_range
				lowerCamelCase   : List[Any]								=use_cache
				lowerCamelCase   : Dict								=pretraining_tp
				lowerCamelCase   : List[str]								=apply_residual_connection_post_layernorm
				lowerCamelCase   : List[str]								=hidden_dropout
				lowerCamelCase   : Union[str, Any]								=attention_dropout

				lowerCamelCase   : Tuple								=bos_token_id
				lowerCamelCase   : Any								=eos_token_id
				lowerCamelCase   : int								=slow_but_exact

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

class        snake_case_		(			_A):

		'''simple docstring'''





		lowerCamelCase    :List[Any]						=     version.parse("1.12")







		def __init__(		self			,     __lowercase			,     __lowercase = "default"			,     __lowercase = None			,     __lowercase = False			,     )				->   Any:
				super().__init__(__lowercase			,     task=__lowercase			,     patching_specs=__lowercase			,     use_past=__lowercase   )
				if not getattr(self._config			,     '''pad_token_id'''			,     __lowercase   ):
						# TODO: how to do that better?
						lowerCamelCase   : Tuple								=0







		@property
		def 			__lowercase   (		self   )				->   Mapping[str, Mapping[int, str]]:
				lowerCamelCase   : int								=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_(__lowercase			,     direction='''inputs'''			,     inverted_values_shape=__lowercase   )
						lowerCamelCase   : List[str]								={0: '''batch''', 1: '''past_sequence + sequence'''}
				else:
						lowerCamelCase   : str								={0: '''batch''', 1: '''sequence'''}

				return common_inputs







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







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







		@property
		def 			__lowercase   (		self   )				->   float:
				return 1e-3







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

				# We need to order the input in the way they appears in the forward()
				lowerCamelCase   : Optional[int]								=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

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

				lowerCamelCase   : Optional[int]								=common_inputs['''attention_mask''']
				if self.use_past:
						lowerCamelCase   : Optional[int]								=ordered_inputs['''attention_mask'''].dtype
						lowerCamelCase   : Union[str, Any]								=torch.cat(
						    [ordered_inputs['''attention_mask'''], torch.ones(__lowercase			,     __lowercase			,     dtype=__lowercase   )]			,     dim=1   )

				return ordered_inputs







		@property
		def 			__lowercase   (		self   )				->   int:
				return 1_3








from abc import ABC, abstractmethod
from typing import Optional, Union

from .. import Dataset, DatasetDict, Features, IterableDataset, IterableDatasetDict, NamedSplit
from ..utils.typing import NestedDataStructureLike, PathLike
class        snake_case_		(			_A):







		def __init__(		self			,     __lowercase = None			,     __lowercase = None			,     __lowercase = None			,     __lowercase = None			,     __lowercase = False			,     __lowercase = False			,     __lowercase = None			,     **__lowercase			,     )				->   List[Any]:
				lowerCamelCase   : Dict								=path_or_paths
				lowerCamelCase   : Optional[int]								=split if split or isinstance(__lowercase			,     __lowercase   ) else '''train'''
				lowerCamelCase   : Tuple								=features
				lowerCamelCase   : Tuple								=cache_dir
				lowerCamelCase   : Optional[Any]								=keep_in_memory
				lowerCamelCase   : Any								=streaming
				lowerCamelCase   : Dict								=num_proc
				lowerCamelCase   : List[Any]								=kwargs







		@abstractmethod
		def 			__lowercase   (		self   )				->   Union[Dataset, DatasetDict, IterableDataset, IterableDatasetDict]:
				pass

class        snake_case_		(			_A):







		def __init__(		self			,     __lowercase = None			,     __lowercase = None			,     __lowercase = False			,     __lowercase = False			,     __lowercase = None			,     **__lowercase			,     )				->   List[str]:
				lowerCamelCase   : Tuple								=features
				lowerCamelCase   : Union[str, Any]								=cache_dir
				lowerCamelCase   : Optional[int]								=keep_in_memory
				lowerCamelCase   : List[str]								=streaming
				lowerCamelCase   : List[str]								=num_proc
				lowerCamelCase   : List[str]								=kwargs







		@abstractmethod
		def 			__lowercase   (		self   )				->   Union[Dataset, IterableDataset]:
				pass

