





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    : List[Any]    	=  logging.get_logger(__name__)

lowercase    : List[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  __A(						__UpperCAmelCase ):
     __A	  =       "bloom"
     __A	  =       ["past_key_values"]
     __A	  =       {
         "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"""

            _UpperCamelCase              =						vocab_size
            # Backward compatibility with n_embed kwarg
            _UpperCamelCase              =						kwargs.pop('''n_embed''',       A      )
            _UpperCamelCase              =						hidden_size if n_embed is None else n_embed
            _UpperCamelCase              =						n_layer
            _UpperCamelCase              =						n_head
            _UpperCamelCase              =						layer_norm_epsilon
            _UpperCamelCase              =						initializer_range
            _UpperCamelCase              =						use_cache
            _UpperCamelCase              =						pretraining_tp
            _UpperCamelCase              =						apply_residual_connection_post_layernorm
            _UpperCamelCase              =						hidden_dropout
            _UpperCamelCase              =						attention_dropout

            _UpperCamelCase              =						bos_token_id
            _UpperCamelCase              =						eos_token_id
            _UpperCamelCase              =						slow_but_exact

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






class  __A(						__UpperCAmelCase ):
     __A	  =       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?
                   _UpperCamelCase              =						0

     @property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						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      )
                   _UpperCamelCase              =						{0: '''batch''', 1: '''past_sequence + sequence'''}
            else:
                   _UpperCamelCase              =						{0: '''batch''', 1: '''sequence'''}

            return common_inputs

     @property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return self._config.n_layer

     @property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return self._config.n_head

     @property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return 1E-3

     def 	_UpperCamelCase     (      self,       A,       A = -1,       A = -1,       A = False,       A = None,       ):





            """simple docstring"""

            _UpperCamelCase              =						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()
            _UpperCamelCase              =						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              =						common_inputs['''input_ids'''].shape
                          # Not using the same length for past_key_values
                          _UpperCamelCase              =						seqlen + 2
                          _UpperCamelCase              =						self._config.hidden_size // self.num_attention_heads
                          _UpperCamelCase              =						(
                              batch * self.num_attention_heads,
                              head_dim,
                              past_key_values_length,
                          )
                          _UpperCamelCase              =						(
                              batch * self.num_attention_heads,
                              past_key_values_length,
                              head_dim,
                          )
                          _UpperCamelCase              =						[
                              (torch.zeros(A      ), torch.zeros(A      )) for _ in range(self.num_layers      )
                          ]

            _UpperCamelCase              =						common_inputs['''attention_mask''']
            if self.use_past:
                   _UpperCamelCase              =						ordered_inputs['''attention_mask'''].dtype
                   _UpperCamelCase              =						torch.cat(
                       [ordered_inputs['''attention_mask'''], torch.ones(A,       A,       dtype=A      )],       dim=1      )

            return ordered_inputs



     @property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return 13













def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase    ,       lowerCAmelCase    ,       lowerCAmelCase = 0    ,       lowerCAmelCase = 0					):
       _UpperCamelCase              =						right or len(lowerCAmelCase					) - 1
       if left > right:
              return -1
       elif list_data[left] == key:
              return left
       elif list_data[right] == key:
              return right
       else:
              return search(lowerCAmelCase    ,       lowerCAmelCase    ,       left + 1    ,       right - 1					)


if __name__ == "__main__":
       import doctest

       doctest.testmod()






