


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


__UpperCamelCase       :       int						       =				logging.get_logger(__name__)

__UpperCamelCase       :       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       __magic_name__	(     __lowerCAmelCase):
     A:		Tuple			=      "bloom"
     A:		Dict			=      ["past_key_values"]
     A:		List[str]			=      {
         "num_hidden_layers": "n_layer",
         "num_attention_heads": "n_head",
     }


     def __init__(      self							:     Any							,	lowerCamelCase__							:     Union[str, Any]=250880							,	lowerCamelCase__							:     Optional[Any]=64							,	lowerCamelCase__							:     int=2							,	lowerCamelCase__							:     Any=8							,	lowerCamelCase__							:     Optional[int]=1E-5							,	lowerCamelCase__							:     str=0.02							,	lowerCamelCase__							:     List[str]=True							,	lowerCamelCase__							:     Dict=1							,	lowerCamelCase__							:     Tuple=2							,	lowerCamelCase__							:     Optional[Any]=False							,	lowerCamelCase__							:     List[Any]=0.0							,	lowerCamelCase__							:     List[str]=0.0							,	lowerCamelCase__							:     int=1							,	lowerCamelCase__							:     Dict=False							,	**lowerCamelCase__							:     Tuple							,	)  ->      Any:





      '''simple docstring'''






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

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

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



class       __magic_name__	(     __lowerCAmelCase):
     A:		List[str]			=      version.parse("1.12")


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





      '''simple docstring'''






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


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





      '''simple docstring'''






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

      return common_inputs


     @property
     def      UpperCAmelCase__	(      self							:     Union[str, Any]			)  ->      int:





      '''simple docstring'''






      return self._config.n_layer


     @property
     def      UpperCAmelCase__	(      self							:     List[Any]			)  ->      int:





      '''simple docstring'''






      return self._config.n_head


     @property
     def      UpperCAmelCase__	(      self							:     int			)  ->      float:





      '''simple docstring'''






      return 1E-3


     def      UpperCAmelCase__	(      self							:     Optional[Any]							,	lowerCamelCase__							:     "PreTrainedTokenizer"							,	lowerCamelCase__							:     int = -1							,	lowerCamelCase__							:     int = -1							,	lowerCamelCase__							:     bool = False							,	lowerCamelCase__							:     Optional["TensorType"] = None							,	)  ->      Mapping[str, Any]:





      '''simple docstring'''






      UpperCamelCase__					:    List[str]          =   super(lowerCamelCase__							,	self			).generate_dummy_inputs(
          lowerCamelCase__							,	batch_size=lowerCamelCase__							,	seq_length=lowerCamelCase__							,	is_pair=lowerCamelCase__							,	framework=lowerCamelCase__			)

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

      UpperCamelCase__					:    Union[str, Any]          =   common_inputs['''attention_mask''']
      if self.use_past:
       UpperCamelCase__					:    List[Any]          =   ordered_inputs['''attention_mask'''].dtype
       UpperCamelCase__					:    List[str]          =   torch.cat(
           [ordered_inputs['''attention_mask'''], torch.ones(lowerCamelCase__							,	lowerCamelCase__							,	dtype=lowerCamelCase__			)]							,	dim=1			)

      return ordered_inputs


     @property
     def      UpperCAmelCase__	(      self							:     Union[str, Any]			)  ->      int:





      '''simple docstring'''






      return 13






from typing import TYPE_CHECKING

from ..utils import _LazyModule


__UpperCamelCase       :       int						       =				{
    "config": [
        "EXTERNAL_DATA_FORMAT_SIZE_LIMIT",
        "OnnxConfig",
        "OnnxConfigWithPast",
        "OnnxSeq2SeqConfigWithPast",
        "PatchingSpec",
    ],
    "convert": ["export", "validate_model_outputs"],
    "features": ["FeaturesManager"],
    "utils": ["ParameterFormat", "compute_serialized_parameters_size"],
}


if TYPE_CHECKING:
       from .config import (
           EXTERNAL_DATA_FORMAT_SIZE_LIMIT,
           OnnxConfig,
           OnnxConfigWithPast,
           OnnxSeqaSeqConfigWithPast,
           PatchingSpec,
       )
       from .convert import export, validate_model_outputs
       from .features import FeaturesManager
       from .utils import ParameterFormat, compute_serialized_parameters_size

else:
       import sys

       __UpperCamelCase       :       List[str]						       =				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


