






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

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







 def __init__(		self :       str							,       SCREAMING_SNAKE_CASE :       List[Any]=25_08_80							,       SCREAMING_SNAKE_CASE :       Dict=64							,       SCREAMING_SNAKE_CASE :       int=2							,       SCREAMING_SNAKE_CASE :       List[str]=8							,       SCREAMING_SNAKE_CASE :       List[str]=1e-5							,       SCREAMING_SNAKE_CASE :       Optional[Any]=0.0_2							,       SCREAMING_SNAKE_CASE :       str=True							,       SCREAMING_SNAKE_CASE :       List[Any]=1							,       SCREAMING_SNAKE_CASE :       Tuple=2							,       SCREAMING_SNAKE_CASE :       List[str]=False							,       SCREAMING_SNAKE_CASE :       str=0.0							,       SCREAMING_SNAKE_CASE :       Optional[Any]=0.0							,       SCREAMING_SNAKE_CASE :       Optional[int]=1							,       SCREAMING_SNAKE_CASE :       Any=False							,       **SCREAMING_SNAKE_CASE :       List[str]							,       ):


      '''simple docstring'''






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

      UpperCamelCase__      :       List[Any]	    =  bos_token_id
      UpperCamelCase__      :       Union[str, Any]	    =  eos_token_id
      UpperCamelCase__      :       Optional[Any]	    =  slow_but_exact

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







class       __a  (   A__	):
 _lowerCAmelCase	:	str				=			version.parse('''1.12'''	)







 def __init__(		self :       int							,       SCREAMING_SNAKE_CASE :       PretrainedConfig							,       SCREAMING_SNAKE_CASE :       str = "default"							,       SCREAMING_SNAKE_CASE :       List[PatchingSpec] = None							,       SCREAMING_SNAKE_CASE :       bool = False							,       ):


      '''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__      :       str	    =  0







 @property
 def  __lowercase (		self :       int						):


      '''simple docstring'''






      UpperCamelCase__      :       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__      :       Dict	    =  {0: "batch", 1: "past_sequence + sequence"}
      else:
           UpperCamelCase__      :       str	    =  {0: "batch", 1: "sequence"}

      return common_inputs







 @property
 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      return self._config.n_layer







 @property
 def  __lowercase (		self :       Dict						):


      '''simple docstring'''






      return self._config.n_head







 @property
 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      return 1e-3







 def  __lowercase (		self :       Optional[int]							,       SCREAMING_SNAKE_CASE :       "PreTrainedTokenizer"							,       SCREAMING_SNAKE_CASE :       int = -1							,       SCREAMING_SNAKE_CASE :       int = -1							,       SCREAMING_SNAKE_CASE :       bool = False							,       SCREAMING_SNAKE_CASE :       Optional["TensorType"] = None							,       ):


      '''simple docstring'''






      UpperCamelCase__      :       List[str]	    =  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__      :       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

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

      UpperCamelCase__      :       str	    =  common_inputs["attention_mask"]
      if self.use_past:
           UpperCamelCase__      :       str	    =  ordered_inputs["attention_mask"].dtype
           UpperCamelCase__      :       Optional[Any]	    =  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  __lowercase (		self :       Any						):


      '''simple docstring'''






      return 13







from __future__ import annotations







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase = None ,   __lowerCAmelCase = None      )			->     None:
     if start is None:
          UpperCamelCase__      :       Union[str, Any]	    =  0

     if end is None:
          UpperCamelCase__      :       List[Any]	    =  len(__lowerCAmelCase      ) - 1

     if start >= end:
          return

     UpperCamelCase__      :       Union[str, Any]	    =  (start + end) // 2

     slowsort(__lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase      )
     slowsort(__lowerCAmelCase ,   mid + 1 ,   __lowerCAmelCase      )

     if sequence[end] < sequence[mid]:
          UpperCamelCase__    ,					UpperCamelCase__      :       Optional[int]	    =  sequence[mid], sequence[end]

     slowsort(__lowerCAmelCase ,   __lowerCAmelCase ,   end - 1      )


if __name__ == "__main__":
 from doctest import testmod

 testmod()