



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     :							Any  							=				logging.get_logger(__name__)

__lowerCamelCase     :							Union[str, 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__   (							A__						):
		lowercase      :       Tuple          ='''bloom'''
		lowercase      :       Union[str, Any]          =['''past_key_values''']
		lowercase      :       str          ={
		    '''num_hidden_layers''': '''n_layer''',
		    '''num_attention_heads''': '''n_head''',
		}






		def __init__(						self      :     Tuple				,		UpperCamelCase__      :     Union[str, Any]=25_08_80				,		UpperCamelCase__      :     Optional[int]=64				,		UpperCamelCase__      :     Tuple=2				,		UpperCamelCase__      :     Any=8				,		UpperCamelCase__      :     Optional[int]=1e-5				,		UpperCamelCase__      :     Optional[Any]=0.02				,		UpperCamelCase__      :     Union[str, Any]=True				,		UpperCamelCase__      :     List[str]=1				,		UpperCamelCase__      :     Tuple=2				,		UpperCamelCase__      :     int=False				,		UpperCamelCase__      :     int=0.0				,		UpperCamelCase__      :     Optional[int]=0.0				,		UpperCamelCase__      :     Tuple=1				,		UpperCamelCase__      :     int=False				,		**UpperCamelCase__      :     List[str]				,		)				->					Tuple:
								'''simple docstring'''







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





class  __magic_name__   (							A__						):
		lowercase      :       Optional[Any]          =version.parse('''1.12'''						)






		def __init__(						self      :     List[Any]				,		UpperCamelCase__      :     PretrainedConfig				,		UpperCamelCase__      :     str = "default"				,		UpperCamelCase__      :     List[PatchingSpec] = None				,		UpperCamelCase__      :     bool = False				,		)				->					Optional[Any]:
								'''simple docstring'''







								super().__init__(UpperCamelCase__				,		task=UpperCamelCase__				,		patching_specs=UpperCamelCase__				,		use_past=UpperCamelCase__      )
								if not getattr(self._config				,		"pad_token_id"				,		UpperCamelCase__      ):
														# TODO: how to do that better?
														UpperCAmelCase         =     0






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

								return common_inputs






		@property
		def SCREAMING_SNAKE_CASE_			(						self      :     int      )				->					int:
								'''simple docstring'''







								return self._config.n_layer






		@property
		def SCREAMING_SNAKE_CASE_			(						self      :     Optional[Any]      )				->					int:
								'''simple docstring'''







								return self._config.n_head






		@property
		def SCREAMING_SNAKE_CASE_			(						self      :     int      )				->					float:
								'''simple docstring'''







								return 1e-3






		def SCREAMING_SNAKE_CASE_			(						self      :     Union[str, Any]				,		UpperCamelCase__      :     "PreTrainedTokenizer"				,		UpperCamelCase__      :     int = -1				,		UpperCamelCase__      :     int = -1				,		UpperCamelCase__      :     bool = False				,		UpperCamelCase__      :     Optional["TensorType"] = None				,		)				->					Mapping[str, Any]:
								'''simple docstring'''







								UpperCAmelCase         =     super(UpperCamelCase__				,		self      ).generate_dummy_inputs(
								    UpperCamelCase__				,		batch_size=UpperCamelCase__				,		seq_length=UpperCamelCase__				,		is_pair=UpperCamelCase__				,		framework=UpperCamelCase__      )

								# 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(UpperCamelCase__      ), torch.zeros(UpperCamelCase__      )) 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(UpperCamelCase__				,		UpperCamelCase__				,		dtype=UpperCamelCase__      )]				,		dim=1      )

								return ordered_inputs







		@property
		def SCREAMING_SNAKE_CASE_			(						self      :     int      )				->					int:
								'''simple docstring'''







								return 13








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__lowerCamelCase     :							Any  							=				{
    "configuration_mega": ["MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP", "MegaConfig", "MegaOnnxConfig"],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase     :							Optional[int]  							=				[
		    "MEGA_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "MegaForCausalLM",
		    "MegaForMaskedLM",
		    "MegaForMultipleChoice",
		    "MegaForQuestionAnswering",
		    "MegaForSequenceClassification",
		    "MegaForTokenClassification",
		    "MegaModel",
		    "MegaPreTrainedModel",
		]

if TYPE_CHECKING:
		from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mega import (
				    MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    MegaForCausalLM,
				    MegaForMaskedLM,
				    MegaForMultipleChoice,
				    MegaForQuestionAnswering,
				    MegaForSequenceClassification,
				    MegaForTokenClassification,
				    MegaModel,
				    MegaPreTrainedModel,
				)

else:
		import sys

		__lowerCamelCase     :							int  							=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



