


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							(      UpperCamelCase__      ):
							_lowercase     :      List[str]  				=			'''bloom'''
							_lowercase     :      Tuple  				=			['''past_key_values''']
							_lowercase     :      Tuple  				=			{
							    '''num_hidden_layers''': '''n_layer''',
							    '''num_attention_heads''': '''n_head''',
							}

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





									"""simple docstring"""







									lowercase__						=				vocab_size
									# Backward compatibility with n_embed kwarg
									lowercase__						=				kwargs.pop('''n_embed'''   ,						UpperCamelCase_							)
									lowercase__						=				hidden_size if n_embed is None else n_embed
									lowercase__						=				n_layer
									lowercase__						=				n_head
									lowercase__						=				layer_norm_epsilon
									lowercase__						=				initializer_range
									lowercase__						=				use_cache
									lowercase__						=				pretraining_tp
									lowercase__						=				apply_residual_connection_post_layernorm
									lowercase__						=				hidden_dropout
									lowercase__						=				attention_dropout

									lowercase__						=				bos_token_id
									lowercase__						=				eos_token_id
									lowercase__						=				slow_but_exact

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


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      List[Any]  				=			version.parse('''1.12'''      )

							def __init__(							self:     Optional[int]   ,						UpperCamelCase_:     PretrainedConfig   ,						UpperCamelCase_:     str = "default"   ,						UpperCamelCase_:     List[PatchingSpec] = None   ,						UpperCamelCase_:     bool = False   ,						)      ->       Union[str, 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?
											lowercase__						=				0

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





									"""simple docstring"""







									lowercase__						=				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_							)
											lowercase__						=				{0: '''batch''', 1: '''past_sequence + sequence'''}
									else:
											lowercase__						=				{0: '''batch''', 1: '''sequence'''}

									return common_inputs

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





									"""simple docstring"""







									return self._config.n_layer

							@property
							def 				lowerCamelCase_			(							self:     Any							)      ->       int:





									"""simple docstring"""







									return self._config.n_head

							@property
							def 				lowerCamelCase_			(							self:     Any							)      ->       float:





									"""simple docstring"""







									return 1E-3

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





									"""simple docstring"""







									lowercase__						=				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()
									lowercase__						=				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__					,		lowercase__						=				common_inputs['''input_ids'''].shape
													# Not using the same length for past_key_values
													lowercase__						=				seqlen + 2
													lowercase__						=				self._config.hidden_size // self.num_attention_heads
													lowercase__						=				(
													    batch * self.num_attention_heads,
													    head_dim,
													    past_key_values_length,
													)
													lowercase__						=				(
													    batch * self.num_attention_heads,
													    past_key_values_length,
													    head_dim,
													)
													lowercase__						=				[
													    (torch.zeros(UpperCamelCase_							), torch.zeros(UpperCamelCase_							)) for _ in range(self.num_layers							)
													]

									lowercase__						=				common_inputs['''attention_mask''']
									if self.use_past:
											lowercase__						=				ordered_inputs['''attention_mask'''].dtype
											lowercase__						=				torch.cat(
											    [ordered_inputs['''attention_mask'''], torch.ones(UpperCamelCase_   ,						UpperCamelCase_   ,						dtype=UpperCamelCase_							)]   ,						dim=1							)

									return ordered_inputs


							@property
							def 				lowerCamelCase_			(							self:     Any							)      ->       int:





									"""simple docstring"""







									return 13






from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase	=							logging.get_logger(__name__)

lowerCAmelCase	=							{
    'unc-nlp/lxmert-base-uncased': 'https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json',
}


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      List[Any]  				=			'''lxmert'''
							_lowercase     :      Any  				=			{}

							def __init__(							self:     Any   ,						UpperCamelCase_:     List[Any]=30_522   ,						UpperCamelCase_:     int=768   ,						UpperCamelCase_:     Optional[Any]=12   ,						UpperCamelCase_:     Dict=9_500   ,						UpperCamelCase_:     List[Any]=1_600   ,						UpperCamelCase_:     List[Any]=400   ,						UpperCamelCase_:     List[str]=3_072   ,						UpperCamelCase_:     int="gelu"   ,						UpperCamelCase_:     Any=0.1   ,						UpperCamelCase_:     int=0.1   ,						UpperCamelCase_:     List[str]=512   ,						UpperCamelCase_:     Optional[int]=2   ,						UpperCamelCase_:     Union[str, Any]=0.02   ,						UpperCamelCase_:     Dict=1E-1_2   ,						UpperCamelCase_:     List[Any]=9   ,						UpperCamelCase_:     List[Any]=5   ,						UpperCamelCase_:     Optional[Any]=5   ,						UpperCamelCase_:     str=2_048   ,						UpperCamelCase_:     Dict=4   ,						UpperCamelCase_:     Any=6.67   ,						UpperCamelCase_:     Dict=True   ,						UpperCamelCase_:     List[str]=True   ,						UpperCamelCase_:     Dict=True   ,						UpperCamelCase_:     Any=True   ,						UpperCamelCase_:     Tuple=True   ,						UpperCamelCase_:     Optional[Any]=True   ,						UpperCamelCase_:     Any=True   ,						**UpperCamelCase_:     Union[str, Any]   ,						)      ->       Union[str, Any]:





									"""simple docstring"""







									lowercase__						=				vocab_size
									lowercase__						=				hidden_size
									lowercase__						=				num_attention_heads
									lowercase__						=				hidden_act
									lowercase__						=				intermediate_size
									lowercase__						=				hidden_dropout_prob
									lowercase__						=				attention_probs_dropout_prob
									lowercase__						=				max_position_embeddings
									lowercase__						=				type_vocab_size
									lowercase__						=				initializer_range
									lowercase__						=				layer_norm_eps
									lowercase__						=				num_qa_labels
									lowercase__						=				num_object_labels
									lowercase__						=				num_attr_labels
									lowercase__						=				l_layers
									lowercase__						=				x_layers
									lowercase__						=				r_layers
									lowercase__						=				visual_feat_dim
									lowercase__						=				visual_pos_dim
									lowercase__						=				visual_loss_normalizer
									lowercase__						=				task_matched
									lowercase__						=				task_mask_lm
									lowercase__						=				task_obj_predict
									lowercase__						=				task_qa
									lowercase__						=				visual_obj_loss
									lowercase__						=				visual_attr_loss
									lowercase__						=				visual_feat_loss
									lowercase__						=				{'''vision''': r_layers, '''cross_encoder''': x_layers, '''language''': l_layers}
									super().__init__(**UpperCamelCase_							)


