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


__magic_name__								=logging.get_logger(__name__)

__magic_name__								={
    '''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							):
  SCREAMING_SNAKE_CASE_	:	str						="bloom"
  SCREAMING_SNAKE_CASE_	:	Optional[Any]						=["past_key_values"]
  SCREAMING_SNAKE_CASE_	:	Dict						={
      "num_hidden_layers": "n_layer",
      "num_attention_heads": "n_head",
  }






  def __init__(self   ,				SCREAMING_SNAKE_CASE_=25_0880   ,				SCREAMING_SNAKE_CASE_=64   ,				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_   ,				)		->      int:





       '''simple docstring'''





       UpperCamelCase__										=      vocab_size
       # Backward compatibility with n_embed kwarg
       UpperCamelCase__										=      kwargs.pop('''n_embed'''   ,				SCREAMING_SNAKE_CASE_	)
       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=SCREAMING_SNAKE_CASE_   ,				eos_token_id=SCREAMING_SNAKE_CASE_   ,				**SCREAMING_SNAKE_CASE_	)



class     _A   (    __UpperCamelCase							):
  SCREAMING_SNAKE_CASE_	:	Optional[Any]						=version.parse("1.12"							)






  def __init__(self   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_ = "default"   ,				SCREAMING_SNAKE_CASE_ = None   ,				SCREAMING_SNAKE_CASE_ = False   ,				)		->      Union[str, 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__										=      0






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





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

       return common_inputs






  @property
  def 		_a					(self	)		->      int:





       '''simple docstring'''





       return self._config.n_layer






  @property
  def 		_a					(self	)		->      int:





       '''simple docstring'''





       return self._config.n_head






  @property
  def 		_a					(self	)		->      float:





       '''simple docstring'''





       return 1E-3






  def 		_a					(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__										=      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__										=      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(SCREAMING_SNAKE_CASE_	), torch.zeros(SCREAMING_SNAKE_CASE_	)) 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(SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_   ,				dtype=SCREAMING_SNAKE_CASE_	)]   ,				dim=1	)

       return ordered_inputs






  @property
  def 		_a					(self	)		->      int:





       '''simple docstring'''





       return 13




import math

import tensorflow as tf
from packaging import version







def  __UpperCamelCase    (						A							):
     UpperCamelCase__										=      tf.convert_to_tensor(A							)
     UpperCamelCase__										=      0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0							) ,							x.dtype							)							))

     return x * cdf







def  __UpperCamelCase    (						A							):
     UpperCamelCase__										=      tf.convert_to_tensor(A							)
     UpperCamelCase__										=      tf.cast(math.pi ,							x.dtype							)
     UpperCamelCase__										=      tf.cast(0.04_47_15 ,							x.dtype							)
     UpperCamelCase__										=      0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi							) * (x + coeff * tf.pow(A ,							3							))							))

     return x * cdf







def  __UpperCamelCase    (						A							):
     UpperCamelCase__										=      tf.convert_to_tensor(A							)

     return x * tf.tanh(tf.math.softplus(A							)							)







def  __UpperCamelCase    (						A							):
     UpperCamelCase__										=      tf.convert_to_tensor(A							)
     UpperCamelCase__										=      tf.cast(0.04_47_15 ,							x.dtype							)
     UpperCamelCase__										=      tf.cast(0.79_78_84_56_08 ,							x.dtype							)

     return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)							))







def  __UpperCamelCase    (						A							):
     UpperCamelCase__										=      tf.convert_to_tensor(A							)
     UpperCamelCase__										=      tf.cast(1.7_02 ,							x.dtype							)
     return x * tf.math.sigmoid(coeff * x							)







def  __UpperCamelCase    (						A							):
     return tf.clip_by_value(_gelu(A							) ,							-10 ,							10							)







def  __UpperCamelCase    (						A ,							A=-1							):
     UpperCamelCase__						,       UpperCamelCase__										=      tf.split(A ,							2 ,							axis=A							)
     return a * tf.math.sigmoid(A							)


if version.parse(tf.version.VERSION) >= version.parse('''2.4'''):







     def  __UpperCamelCase    (						A							):
          return tf.keras.activations.gelu(A ,							approximate=A							)

     __magic_name__								=tf.keras.activations.gelu



     __magic_name__								=approximate_gelu_wrap
else:
     __magic_name__								=_gelu
     __magic_name__								=_gelu_new


__magic_name__								={
    '''gelu''': gelu,
    '''gelu_10''': gelu_aa,
    '''gelu_fast''': gelu_fast,
    '''gelu_new''': gelu_new,
    '''glu''': glu,
    '''mish''': mish,
    '''quick_gelu''': quick_gelu,
    '''relu''': tf.keras.activations.relu,
    '''sigmoid''': tf.keras.activations.sigmoid,
    '''silu''': tf.keras.activations.swish,
    '''swish''': tf.keras.activations.swish,
    '''tanh''': tf.keras.activations.tanh,
}







def  __UpperCamelCase    (						A							):
     if activation_string in ACTaFN:
          return ACTaFN[activation_string]
     else:
          raise KeyError(f"function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()							)}"							)



