



'''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


_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_(				lowerCamelCase_     ):
  '''simple docstring'''




  __lowercase							:      Tuple				=      '''bloom'''
  __lowercase							:      int				=      ['''past_key_values''']
  __lowercase							:      int				=      {
      '''num_hidden_layers''': '''n_layer''',
      '''num_attention_heads''': '''n_head''',
  }




  def __init__(    self  ,__UpperCAmelCase=25_0880  ,__UpperCAmelCase=64  ,__UpperCAmelCase=2  ,__UpperCAmelCase=8  ,__UpperCAmelCase=1E-5  ,__UpperCAmelCase=0.0_2  ,__UpperCAmelCase=True  ,__UpperCAmelCase=1  ,__UpperCAmelCase=2  ,__UpperCAmelCase=False  ,__UpperCAmelCase=0.0  ,__UpperCAmelCase=0.0  ,__UpperCAmelCase=1  ,__UpperCAmelCase=False  ,**__UpperCAmelCase  ,)    ->		Tuple:
      lowerCAmelCase__ :  Union[str, Any]							      =					vocab_size
      # Backward compatibility with n_embed kwarg
      lowerCAmelCase__ :  Union[str, Any]							      =					kwargs.pop("""n_embed"""  ,_lowercase      )
      lowerCAmelCase__ :  Any							      =					hidden_size if n_embed is None else n_embed
      lowerCAmelCase__ :  List[Any]							      =					n_layer
      lowerCAmelCase__ :  Any							      =					n_head
      lowerCAmelCase__ :  Dict							      =					layer_norm_epsilon
      lowerCAmelCase__ :  List[Any]							      =					initializer_range
      lowerCAmelCase__ :  int							      =					use_cache
      lowerCAmelCase__ :  str							      =					pretraining_tp
      lowerCAmelCase__ :  int							      =					apply_residual_connection_post_layernorm
      lowerCAmelCase__ :  List[Any]							      =					hidden_dropout
      lowerCAmelCase__ :  Optional[int]							      =					attention_dropout

      lowerCAmelCase__ :  List[Any]							      =					bos_token_id
      lowerCAmelCase__ :  Dict							      =					eos_token_id
      lowerCAmelCase__ :  Optional[int]							      =					slow_but_exact

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







class        lowerCAmelCase_(				lowerCamelCase_     ):
  '''simple docstring'''




  __lowercase							:      Tuple				=      version.parse('''1.12'''     )




  def __init__(    self  ,__UpperCAmelCase  ,__UpperCAmelCase = "default"  ,__UpperCAmelCase = None  ,__UpperCAmelCase = False  ,)    ->		Optional[int]:
      super().__init__(_lowercase  ,task=_lowercase  ,patching_specs=_lowercase  ,use_past=_lowercase      )
      if not getattr(self._config  ,"""pad_token_id"""  ,_lowercase      ):
          # TODO: how to do that better?
          lowerCAmelCase__ :  int							      =					0




  @property
  def 							UpperCAmelCase_	(    self      )    ->		Optional[int]:
      lowerCAmelCase__ :  List[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_(_lowercase  ,direction="""inputs"""  ,inverted_values_shape=_lowercase      )
          lowerCAmelCase__ :  Optional[int]							      =					{0: """batch""", 1: """past_sequence + sequence"""}
      else:
          lowerCAmelCase__ :  Any							      =					{0: """batch""", 1: """sequence"""}

      return common_inputs




  @property
  def 							UpperCAmelCase_	(    self      )    ->		Tuple:
      return self._config.n_layer




  @property
  def 							UpperCAmelCase_	(    self      )    ->		str:
      return self._config.n_head




  @property
  def 							UpperCAmelCase_	(    self      )    ->		str:
      return 1E-3




  def 							UpperCAmelCase_	(    self  ,__UpperCAmelCase  ,__UpperCAmelCase = -1  ,__UpperCAmelCase = -1  ,__UpperCAmelCase = False  ,__UpperCAmelCase = None  ,)    ->		Any:
      lowerCAmelCase__ :  Dict							      =					super(_lowercase  ,self      ).generate_dummy_inputs(
          _lowercase  ,batch_size=_lowercase  ,seq_length=_lowercase  ,is_pair=_lowercase  ,framework=_lowercase      )

      # We need to order the input in the way they appears in the forward()
      lowerCAmelCase__ :  Dict							      =					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__ :  List[Any]							      =					common_inputs["""input_ids"""].shape
              # Not using the same length for past_key_values
              lowerCAmelCase__ :  List[str]							      =					seqlen + 2
              lowerCAmelCase__ :  str							      =					self._config.hidden_size // self.num_attention_heads
              lowerCAmelCase__ :  Optional[int]							      =					(
                  batch * self.num_attention_heads,
                  head_dim,
                  past_key_values_length,
              )
              lowerCAmelCase__ :  Dict							      =					(
                  batch * self.num_attention_heads,
                  past_key_values_length,
                  head_dim,
              )
              lowerCAmelCase__ :  Tuple							      =					[
                  (torch.zeros(_lowercase      ), torch.zeros(_lowercase      )) for _ in range(self.num_layers      )
              ]

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

      return ordered_inputs






  @property
  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      return 13



__lowerCamelCase			: List[Any]							   =		6_5521



def 	__SCREAMING_SNAKE_CASE  (					__UpperCamelCase    :       str	)							->					int:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__										=      1
  SCREAMING_SNAKE_CASE__										=      0
  for plain_chr in plain_text:
    SCREAMING_SNAKE_CASE__										=      (a + ord(__UpperCamelCase	)) % MOD_ADLER
    SCREAMING_SNAKE_CASE__										=      (b + a) % MOD_ADLER
  return (b << 16) | a
