
'''simple docstring'''


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


__lowercase							:   Tuple					=     logging.get_logger(__name__)

__lowercase							:   Optional[Any]					=     {
    '''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 	__lowercase				(  __UpperCAmelCase    ):
			lowerCamelCase			:		Union[str, Any]	      =			"""bloom"""
			lowerCamelCase			:		Any	      =			["""past_key_values"""]
			lowerCamelCase			:		str	      =			{
			    """num_hidden_layers""": """n_layer""",
			    """num_attention_heads""": """n_head""",
			}

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

								lowerCamelCase_					:      int     =		bos_token_id
								lowerCamelCase_					:      List[Any]     =		eos_token_id
								lowerCamelCase_					:      int     =		slow_but_exact

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

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

			def __init__(self			,   A			,   A = "default"			,   A = None			,   A = False			,   ):
								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?
													lowerCamelCase_					:      Optional[Any]     =		0

			@property
			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		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_      )
													lowerCamelCase_					:      str     =		{0: '''batch''', 1: '''past_sequence + sequence'''}
								else:
													lowerCamelCase_					:      List[Any]     =		{0: '''batch''', 1: '''sequence'''}

								return common_inputs

			@property
			def        UpperCAmelCase__ (self      ):
								return self._config.n_layer

			@property
			def        UpperCAmelCase__ (self      ):
								return self._config.n_head

			@property
			def        UpperCAmelCase__ (self      ):
								return 1E-3

			def        UpperCAmelCase__ (self			,   A			,   A = -1			,   A = -1			,   A = False			,   A = None			,   ):
								lowerCamelCase_					:      Optional[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()
								lowerCamelCase_					:      str     =		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_					:      int     =		common_inputs['''input_ids'''].shape
																		# Not using the same length for past_key_values
																		lowerCamelCase_					:      List[str]     =		seqlen + 2
																		lowerCamelCase_					:      Dict     =		self._config.hidden_size // self.num_attention_heads
																		lowerCamelCase_					:      Dict     =		(
																		    batch * self.num_attention_heads,
																		    head_dim,
																		    past_key_values_length,
																		)
																		lowerCamelCase_					:      Union[str, Any]     =		(
																		    batch * self.num_attention_heads,
																		    past_key_values_length,
																		    head_dim,
																		)
																		lowerCamelCase_					:      List[str]     =		[
																		    (torch.zeros(UpperCAmelCase_      ), torch.zeros(UpperCAmelCase_      )) for _ in range(self.num_layers      )
																		]

								lowerCamelCase_					:      Any     =		common_inputs['''attention_mask''']
								if self.use_past:
													lowerCamelCase_					:      Any     =		ordered_inputs['''attention_mask'''].dtype
													lowerCamelCase_					:      List[Any]     =		torch.cat(
													    [ordered_inputs['''attention_mask'''], torch.ones(UpperCAmelCase_			,   UpperCAmelCase_			,   dtype=UpperCAmelCase_      )]			,   dim=1      )

								return ordered_inputs






			@property
			def        UpperCAmelCase__ (self      ):
								return 1_3




'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


__lowercase							:   int					=     {}

try:
					if not is_sentencepiece_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__lowercase							:   Any					=     ['''BartphoTokenizer''']

if TYPE_CHECKING:
					try:
										if not is_sentencepiece_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_bartpho import BartphoTokenizer

else:
					import sys

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


