



"""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 			__A			(      A_       ):







		'''simple docstring'''





		lowerCAmelCase     :   int        =							"bloom"
		lowerCAmelCase     :   int        =							["past_key_values"]
		lowerCAmelCase     :   Union[str, Any]        =							{
		    "num_hidden_layers": "n_layer",
		    "num_attention_heads": "n_head",
		}







		def __init__(      self		:    int     ,_snake_case		:    Any=250_880     ,_snake_case		:    Union[str, Any]=64     ,_snake_case		:    str=2     ,_snake_case		:    int=8     ,_snake_case		:    List[Any]=1e-5     ,_snake_case		:    Any=0.02     ,_snake_case		:    Union[str, Any]=True     ,_snake_case		:    Any=1     ,_snake_case		:    Dict=2     ,_snake_case		:    int=False     ,_snake_case		:    List[str]=0.0     ,_snake_case		:    Dict=0.0     ,_snake_case		:    Dict=1     ,_snake_case		:    List[str]=False     ,**_snake_case		:    str     ,)   ->						str:






				"""simple docstring"""



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

				lowercase__  :       List[str]												=     bos_token_id
				lowercase__  :       Tuple												=     eos_token_id
				lowercase__  :       Any												=     slow_but_exact

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





class 			__A			(      A_       ):







		'''simple docstring'''





		lowerCAmelCase     :   Optional[int]        =							version.parse("1.12"       )







		def __init__(      self		:    List[Any]     ,_snake_case		:    List[str]     ,_snake_case		:    Union[str, Any] = "default"     ,_snake_case		:    Tuple = None     ,_snake_case		:    str = False     ,)   ->						Optional[int]:






				"""simple docstring"""



				super().__init__(_snake_case     ,task=_snake_case     ,patching_specs=_snake_case     ,use_past=_snake_case		)
				if not getattr(self._config     ,'''pad_token_id'''     ,_snake_case		):
						# TODO: how to do that better?
						lowercase__  :       Dict												=     0







		@property
		def    UpperCAmelCase       (      self		:    int		)   ->						Tuple:






				"""simple docstring"""



				lowercase__  :       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_(_snake_case     ,direction='''inputs'''     ,inverted_values_shape=_snake_case		)
						lowercase__  :       Any												=     {0: "batch", 1: "past_sequence + sequence"}
				else:
						lowercase__  :       Tuple												=     {0: "batch", 1: "sequence"}

				return common_inputs







		@property
		def    UpperCAmelCase       (      self		:    str		)   ->						Optional[Any]:






				"""simple docstring"""



				return self._config.n_layer







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






				"""simple docstring"""



				return self._config.n_head







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






				"""simple docstring"""



				return 1e-3







		def    UpperCAmelCase       (      self		:    Optional[Any]     ,_snake_case		:    Dict     ,_snake_case		:    List[Any] = -1     ,_snake_case		:    List[Any] = -1     ,_snake_case		:    Dict = False     ,_snake_case		:    Dict = None     ,)   ->						Optional[int]:






				"""simple docstring"""



				lowercase__  :       Union[str, Any]												=     super(_snake_case     ,self		).generate_dummy_inputs(
				    _snake_case     ,batch_size=_snake_case     ,seq_length=_snake_case     ,is_pair=_snake_case     ,framework=_snake_case		)

				# We need to order the input in the way they appears in the forward()
				lowercase__  :       Optional[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

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

				lowercase__  :       int												=     common_inputs["attention_mask"]
				if self.use_past:
						lowercase__  :       Optional[int]												=     ordered_inputs["attention_mask"].dtype
						lowercase__  :       Any												=     torch.cat(
						    [ordered_inputs['''attention_mask'''], torch.ones(_snake_case     ,_snake_case     ,dtype=_snake_case		)]     ,dim=1		)

				return ordered_inputs







		@property
		def    UpperCAmelCase       (      self		:    Tuple		)   ->						int:






				"""simple docstring"""



				return 13




'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


_UpperCamelCase 							=  {"""configuration_vit""": ["""VIT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ViTConfig""", """ViTOnnxConfig"""]}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _UpperCamelCase 							=  ["""ViTFeatureExtractor"""]
      _UpperCamelCase 							=  ["""ViTImageProcessor"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _UpperCamelCase 							=  [
          """VIT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """ViTForImageClassification""",
          """ViTForMaskedImageModeling""",
          """ViTModel""",
          """ViTPreTrainedModel""",
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _UpperCamelCase 							=  [
          """TFViTForImageClassification""",
          """TFViTModel""",
          """TFViTPreTrainedModel""",
      ]

try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _UpperCamelCase 							=  [
          """FlaxViTForImageClassification""",
          """FlaxViTModel""",
          """FlaxViTPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_vit import VIT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTConfig, ViTOnnxConfig

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_vit import ViTFeatureExtractor
            from .image_processing_vit import ViTImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_vit import (
                VIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                ViTForImageClassification,
                ViTForMaskedImageModeling,
                ViTModel,
                ViTPreTrainedModel,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel

      try:
            if not is_flax_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel


else:
      import sys

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

