



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 						UpperCAmelCase_					( a):
							lowerCamelCase__         =	'bloom'
							lowerCamelCase__         =	['past_key_values']
							lowerCamelCase__         =	{
							    'num_hidden_layers': 'n_layer',
							    'num_attention_heads': 'n_head',
							}







							def __init__(     self,    __a=25_0880,    __a=64,    __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,    ):

														'''simple docstring'''

														_lowerCAmelCase  :							Dict				     =					vocab_size
														# Backward compatibility with n_embed kwarg
														_lowerCAmelCase  :							Tuple				     =					kwargs.pop("n_embed",    __a)
														_lowerCAmelCase  :							List[str]				     =					hidden_size if n_embed is None else n_embed
														_lowerCAmelCase  :							Any				     =					n_layer
														_lowerCAmelCase  :							Dict				     =					n_head
														_lowerCAmelCase  :							List[str]				     =					layer_norm_epsilon
														_lowerCAmelCase  :							Tuple				     =					initializer_range
														_lowerCAmelCase  :							Optional[int]				     =					use_cache
														_lowerCAmelCase  :							Tuple				     =					pretraining_tp
														_lowerCAmelCase  :							Optional[Any]				     =					apply_residual_connection_post_layernorm
														_lowerCAmelCase  :							Optional[int]				     =					hidden_dropout
														_lowerCAmelCase  :							str				     =					attention_dropout

														_lowerCAmelCase  :							Optional[int]				     =					bos_token_id
														_lowerCAmelCase  :							str				     =					eos_token_id
														_lowerCAmelCase  :							int				     =					slow_but_exact

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



class 						UpperCAmelCase_					( a):
							lowerCamelCase__         =	version.parse('1.12')







							def __init__(     self,    __a,    __a = "default",    __a = None,    __a = False,    ):

														'''simple docstring'''

														super().__init__(__a,    task=__a,    patching_specs=__a,    use_past=__a)
														if not getattr(self._config,    "pad_token_id",    __a):
																					# TODO: how to do that better?
																					_lowerCAmelCase  :							str				     =					0







							@property
							def      snake_case__   (     self):

														'''simple docstring'''

														_lowerCAmelCase  :							Tuple				     =					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_(__a,    direction="inputs",    inverted_values_shape=__a)
																					_lowerCAmelCase  :							Optional[int]				     =					{0: "batch", 1: "past_sequence + sequence"}
														else:
																					_lowerCAmelCase  :							List[str]				     =					{0: "batch", 1: "sequence"}

														return common_inputs







							@property
							def      snake_case__   (     self):

														'''simple docstring'''

														return self._config.n_layer







							@property
							def      snake_case__   (     self):

														'''simple docstring'''

														return self._config.n_head







							@property
							def      snake_case__   (     self):

														'''simple docstring'''

														return 1E-3







							def      snake_case__   (     self,    __a,    __a = -1,    __a = -1,    __a = False,    __a = None,    ):

														'''simple docstring'''

														_lowerCAmelCase  :							List[Any]				     =					super(__a,    self).generate_dummy_inputs(
														    __a,    batch_size=__a,    seq_length=__a,    is_pair=__a,    framework=__a)

														# We need to order the input in the way they appears in the forward()
														_lowerCAmelCase  :							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

																												_lowerCAmelCase     ,					_lowerCAmelCase  :							Dict				     =					common_inputs["input_ids"].shape
																												# Not using the same length for past_key_values
																												_lowerCAmelCase  :							Union[str, Any]				     =					seqlen + 2
																												_lowerCAmelCase  :							Any				     =					self._config.hidden_size // self.num_attention_heads
																												_lowerCAmelCase  :							Tuple				     =					(
																												    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  :							Optional[Any]				     =					[
																												    (torch.zeros(__a), torch.zeros(__a)) for _ in range(self.num_layers)
																												]

														_lowerCAmelCase  :							Dict				     =					common_inputs["attention_mask"]
														if self.use_past:
																					_lowerCAmelCase  :							List[str]				     =					ordered_inputs["attention_mask"].dtype
																					_lowerCAmelCase  :							Optional[Any]				     =					torch.cat(
																					    [ordered_inputs["attention_mask"], torch.ones(__a,    __a,    dtype=__a)],    dim=1)

														return ordered_inputs







							@property
							def      snake_case__   (     self):

														'''simple docstring'''

														return 13





import baseaa






def        A       (      _lowerCamelCase						):





							'''simple docstring'''




							return baseaa.aaaencode(string.encode("utf-8"						)						)






def        A       (      _lowerCamelCase						):





							'''simple docstring'''




							return baseaa.aaadecode(_lowerCamelCase						).decode("utf-8"						)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
