
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


lowerCamelCase      =logging.get_logger(__name__)

lowerCamelCase      ={
    "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 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  """bloom"""
     SCREAMING_SNAKE_CASE_		   =  ["""past_key_values"""]
     SCREAMING_SNAKE_CASE_		   =  {
         """num_hidden_layers""": """n_layer""",
         """num_attention_heads""": """n_head""",
     }






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=2_5_0_8_8_0						,						__SCREAMING_SNAKE_CASE=6_4						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=8						,						__SCREAMING_SNAKE_CASE=1e-5						,						__SCREAMING_SNAKE_CASE=0.02						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=1						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=False						,						__SCREAMING_SNAKE_CASE=0.0						,						__SCREAMING_SNAKE_CASE=0.0						,						__SCREAMING_SNAKE_CASE=1						,						__SCREAMING_SNAKE_CASE=False						,						**__SCREAMING_SNAKE_CASE						,						)  ->   str:




           """simple docstring"""







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

           UpperCamelCase__    :   List[str]					=				bos_token_id
           UpperCamelCase__    :   str					=				eos_token_id
           UpperCamelCase__    :   List[Any]					=				slow_but_exact

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




class 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  version.parse('''1.12''' )






     def __init__(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE = "default"						,						__SCREAMING_SNAKE_CASE = None						,						__SCREAMING_SNAKE_CASE = False						,						)  ->   Any:




           """simple docstring"""







           super().__init__(__SCREAMING_SNAKE_CASE						,						task=__SCREAMING_SNAKE_CASE						,						patching_specs=__SCREAMING_SNAKE_CASE						,						use_past=__SCREAMING_SNAKE_CASE  )
           if not getattr(self._config						,						'''pad_token_id'''						,						__SCREAMING_SNAKE_CASE  ):
                 # TODO: how to do that better?
                 UpperCamelCase__    :   Tuple					=				0






     @property
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Mapping[str, Mapping[int, str]]:




           """simple docstring"""







           UpperCamelCase__    :   List[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_(__SCREAMING_SNAKE_CASE						,						direction='''inputs'''						,						inverted_values_shape=__SCREAMING_SNAKE_CASE  )
                 UpperCamelCase__    :   Optional[Any]					=				{0: '''batch''', 1: '''past_sequence + sequence'''}
           else:
                 UpperCamelCase__    :   Optional[Any]					=				{0: '''batch''', 1: '''sequence'''}

           return common_inputs






     @property
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   int:




           """simple docstring"""







           return self._config.n_layer






     @property
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   int:




           """simple docstring"""







           return self._config.n_head






     @property
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   float:




           """simple docstring"""







           return 1e-3






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE = -1						,						__SCREAMING_SNAKE_CASE = -1						,						__SCREAMING_SNAKE_CASE = False						,						__SCREAMING_SNAKE_CASE = None						,						)  ->   Mapping[str, Any]:




           """simple docstring"""







           UpperCamelCase__    :   int					=				super(__SCREAMING_SNAKE_CASE						,						self  ).generate_dummy_inputs(
               __SCREAMING_SNAKE_CASE						,						batch_size=__SCREAMING_SNAKE_CASE						,						seq_length=__SCREAMING_SNAKE_CASE						,						is_pair=__SCREAMING_SNAKE_CASE						,						framework=__SCREAMING_SNAKE_CASE  )

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

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

           UpperCamelCase__    :   int					=				common_inputs['''attention_mask''']
           if self.use_past:
                 UpperCamelCase__    :   Optional[Any]					=				ordered_inputs['''attention_mask'''].dtype
                 UpperCamelCase__    :   Tuple					=				torch.cat(
                     [ordered_inputs['''attention_mask'''], torch.ones(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						dtype=__SCREAMING_SNAKE_CASE  )]						,						dim=1  )

           return ordered_inputs






     @property
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   int:




           """simple docstring"""







           return 1_3




lowerCamelCase      ={
    "Pillow": "Pillow",
    "accelerate": "accelerate>=0.11.0",
    "compel": "compel==0.1.8",
    "black": "black~=23.1",
    "datasets": "datasets",
    "filelock": "filelock",
    "flax": "flax>=0.4.1",
    "hf-doc-builder": "hf-doc-builder>=0.3.0",
    "huggingface-hub": "huggingface-hub>=0.13.2",
    "requests-mock": "requests-mock==1.10.0",
    "importlib_metadata": "importlib_metadata",
    "invisible-watermark": "invisible-watermark",
    "isort": "isort>=5.5.4",
    "jax": "jax>=0.2.8,!=0.3.2",
    "jaxlib": "jaxlib>=0.1.65",
    "Jinja2": "Jinja2",
    "k-diffusion": "k-diffusion>=0.0.12",
    "torchsde": "torchsde",
    "note_seq": "note_seq",
    "librosa": "librosa",
    "numpy": "numpy",
    "omegaconf": "omegaconf",
    "parameterized": "parameterized",
    "protobuf": "protobuf>=3.20.3,<4",
    "pytest": "pytest",
    "pytest-timeout": "pytest-timeout",
    "pytest-xdist": "pytest-xdist",
    "ruff": "ruff>=0.0.241",
    "safetensors": "safetensors",
    "sentencepiece": "sentencepiece>=0.1.91,!=0.1.92",
    "scipy": "scipy",
    "onnx": "onnx",
    "regex": "regex!=2019.12.17",
    "requests": "requests",
    "tensorboard": "tensorboard",
    "torch": "torch>=1.4",
    "torchvision": "torchvision",
    "transformers": "transformers>=4.25.1",
    "urllib3": "urllib3<=2.0.0",
}


