





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


SCREAMING_SNAKE_CASE__					=   logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__					=   {
    "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 		lowercase					(					_UpperCAmelCase					):
      _SCREAMING_SNAKE_CASE					=      'bloom'
      _SCREAMING_SNAKE_CASE					=      ['past_key_values']
      _SCREAMING_SNAKE_CASE					=      {
          'num_hidden_layers': 'n_layer',
          'num_attention_heads': 'n_head',
      }





      def __init__(       self      ,						lowercase=250_880      ,						lowercase=64      ,						lowercase=2      ,						lowercase=8      ,						lowercase=1e-5      ,						lowercase=0.02      ,						lowercase=True      ,						lowercase=1      ,						lowercase=2      ,						lowercase=False      ,						lowercase=0.0      ,						lowercase=0.0      ,						lowercase=1      ,						lowercase=False      ,						**lowercase      ,						)		->     Tuple:
            lowerCAmelCase  						=       vocab_size
            # Backward compatibility with n_embed kwarg
            lowerCAmelCase  						=       kwargs.pop("""n_embed"""      ,						lowercase )
            lowerCAmelCase  						=       hidden_size if n_embed is None else n_embed
            lowerCAmelCase  						=       n_layer
            lowerCAmelCase  						=       n_head
            lowerCAmelCase  						=       layer_norm_epsilon
            lowerCAmelCase  						=       initializer_range
            lowerCAmelCase  						=       use_cache
            lowerCAmelCase  						=       pretraining_tp
            lowerCAmelCase  						=       apply_residual_connection_post_layernorm
            lowerCAmelCase  						=       hidden_dropout
            lowerCAmelCase  						=       attention_dropout

            lowerCAmelCase  						=       bos_token_id
            lowerCAmelCase  						=       eos_token_id
            lowerCAmelCase  						=       slow_but_exact

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







class 		lowercase					(					_UpperCAmelCase					):
      _SCREAMING_SNAKE_CASE					=      version.parse('1.12'					)





      def __init__(       self      ,						lowercase      ,						lowercase = "default"      ,						lowercase = None      ,						lowercase = False      ,						)		->     List[str]:
            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  						=       0





      @property
      def     _snake_case			(       self )		->     Mapping[str, Mapping[int, str]]:
            lowerCAmelCase  						=       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  						=       {0: """batch""", 1: """past_sequence + sequence"""}
            else:
                  lowerCAmelCase  						=       {0: """batch""", 1: """sequence"""}

            return common_inputs





      @property
      def     _snake_case			(       self )		->     int:
            return self._config.n_layer





      @property
      def     _snake_case			(       self )		->     int:
            return self._config.n_head





      @property
      def     _snake_case			(       self )		->     float:
            return 1e-3





      def     _snake_case			(       self      ,						lowercase      ,						lowercase = -1      ,						lowercase = -1      ,						lowercase = False      ,						lowercase = None      ,						)		->     Mapping[str, Any]:
            lowerCAmelCase  						=       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  						=       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  						=       common_inputs["""input_ids"""].shape
                        # Not using the same length for past_key_values
                        lowerCAmelCase  						=       seqlen + 2
                        lowerCAmelCase  						=       self._config.hidden_size // self.num_attention_heads
                        lowerCAmelCase  						=       (
                            batch * self.num_attention_heads,
                            head_dim,
                            past_key_values_length,
                        )
                        lowerCAmelCase  						=       (
                            batch * self.num_attention_heads,
                            past_key_values_length,
                            head_dim,
                        )
                        lowerCAmelCase  						=       [
                            (torch.zeros(lowercase ), torch.zeros(lowercase )) for _ in range(self.num_layers )
                        ]

            lowerCAmelCase  						=       common_inputs["""attention_mask"""]
            if self.use_past:
                  lowerCAmelCase  						=       ordered_inputs["""attention_mask"""].dtype
                  lowerCAmelCase  						=       torch.cat(
                      [ordered_inputs["""attention_mask"""], torch.ones(lowercase      ,						lowercase      ,						dtype=lowercase )]      ,						dim=1 )

            return ordered_inputs





      @property
      def     _snake_case			(       self )		->     int:
            return 13













"""simple docstring"""





from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


SCREAMING_SNAKE_CASE__					=   {"configuration_focalnet": ["FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP", "FocalNetConfig"]}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       SCREAMING_SNAKE_CASE__					=   [
           "FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST",
           "FocalNetForImageClassification",
           "FocalNetForMaskedImageModeling",
           "FocalNetBackbone",
           "FocalNetModel",
           "FocalNetPreTrainedModel",
       ]

if TYPE_CHECKING:
       from .configuration_focalnet import FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FocalNetConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_focalnet import (
                  FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST,
                  FocalNetBackbone,
                  FocalNetForImageClassification,
                  FocalNetForMaskedImageModeling,
                  FocalNetModel,
                  FocalNetPreTrainedModel,
              )

else:
       import sys

       SCREAMING_SNAKE_CASE__					=   _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






