






from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...file_utils import TensorType, is_torch_available
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import logging


__a:     Any   					=					logging.get_logger(__name__)

__a:     Any   					=					{
    "facebook/blenderbot_small-90M": "https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/config.json",
    # See all BlenderbotSmall models at https://huggingface.co/models?filter=blenderbot_small
}
class 		SCREAMING_SNAKE_CASE__	(  UpperCamelCase__     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''blenderbot-small'''
  _lowerCamelCase    =  ['''past_key_values''']
  _lowerCamelCase    =  {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}


  def __init__(      self		:			Any       ,				lowerCamelCase		:			Optional[int]=5_0265       ,				lowerCamelCase		:			Any=512       ,				lowerCamelCase		:			Tuple=8       ,				lowerCamelCase		:			Optional[Any]=2048       ,				lowerCamelCase		:			List[Any]=16       ,				lowerCamelCase		:			Any=8       ,				lowerCamelCase		:			Union[str, Any]=2048       ,				lowerCamelCase		:			Any=16       ,				lowerCamelCase		:			List[str]=0.0       ,				lowerCamelCase		:			Dict=0.0       ,				lowerCamelCase		:			str=True       ,				lowerCamelCase		:			Optional[int]=True       ,				lowerCamelCase		:			Optional[int]="gelu"       ,				lowerCamelCase		:			Dict=512       ,				lowerCamelCase		:			Optional[Any]=0.1       ,				lowerCamelCase		:			Tuple=0.0       ,				lowerCamelCase		:			Optional[Any]=0.0       ,				lowerCamelCase		:			Optional[int]=0.02       ,				lowerCamelCase		:			Optional[int]=1       ,				lowerCamelCase		:			str=False       ,				lowerCamelCase		:			List[Any]=0       ,				lowerCamelCase		:			int=1       ,				lowerCamelCase		:			List[Any]=2       ,				lowerCamelCase		:			Optional[Any]=2       ,				**lowerCamelCase		:			str       ,				)						->	Dict:


         """simple docstring"""
         _UpperCAmelCase							=    vocab_size
         _UpperCAmelCase							=    max_position_embeddings
         _UpperCAmelCase							=    d_model
         _UpperCAmelCase							=    encoder_ffn_dim
         _UpperCAmelCase							=    encoder_layers
         _UpperCAmelCase							=    encoder_attention_heads
         _UpperCAmelCase							=    decoder_ffn_dim
         _UpperCAmelCase							=    decoder_layers
         _UpperCAmelCase							=    decoder_attention_heads
         _UpperCAmelCase							=    dropout
         _UpperCAmelCase							=    attention_dropout
         _UpperCAmelCase							=    activation_dropout
         _UpperCAmelCase							=    activation_function
         _UpperCAmelCase							=    init_std
         _UpperCAmelCase							=    encoder_layerdrop
         _UpperCAmelCase							=    decoder_layerdrop
         _UpperCAmelCase							=    use_cache
         _UpperCAmelCase							=    encoder_layers
         _UpperCAmelCase							=    scale_embedding  # scale factor will be sqrt(d_model) if True

         super().__init__(
             pad_token_id=__snake_case       ,				bos_token_id=__snake_case       ,				eos_token_id=__snake_case       ,				is_encoder_decoder=__snake_case       ,				decoder_start_token_id=__snake_case       ,				forced_eos_token_id=__snake_case       ,				**__snake_case       ,				)



class 		SCREAMING_SNAKE_CASE__	(  UpperCamelCase__     ):

  '''simple docstring'''







  @property
  def  lowerCamelCase       (      self		:			Any							)						->	str:


         """simple docstring"""

         if self.task in ["default", "seq2seq-lm"]:
                _UpperCAmelCase							=    OrderedDict(
                    [
                        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                    ]							)

                if self.use_past:
                       _UpperCAmelCase							=    {0: """batch"""}
                       _UpperCAmelCase							=    {0: """batch""", 1: """past_decoder_sequence + sequence"""}
                else:
                       _UpperCAmelCase							=    {0: """batch""", 1: """decoder_sequence"""}
                       _UpperCAmelCase							=    {0: """batch""", 1: """decoder_sequence"""}

                if self.use_past:
                       self.fill_with_past_key_values_(__snake_case       ,				direction="""inputs"""							)
         elif self.task == "causal-lm":
                # TODO: figure this case out.
                _UpperCAmelCase							=    OrderedDict(
                    [
                        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                    ]							)
                if self.use_past:
                       _UpperCAmelCase							=    self.num_layers
                       for i in range(__snake_case							):
                              _UpperCAmelCase							=    {0: """batch""", 2: """past_sequence + sequence"""}
                              _UpperCAmelCase							=    {0: """batch""", 2: """past_sequence + sequence"""}
         else:
                _UpperCAmelCase							=    OrderedDict(
                    [
                        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                        ("""decoder_input_ids""", {0: """batch""", 1: """decoder_sequence"""}),
                        ("""decoder_attention_mask""", {0: """batch""", 1: """decoder_sequence"""}),
                    ]							)

         return common_inputs


  @property
  def  lowerCamelCase       (      self		:			Any							)						->	str:


         """simple docstring"""

         if self.task in ["default", "seq2seq-lm"]:
                _UpperCAmelCase							=    super().outputs
         else:
                _UpperCAmelCase							=    super(__snake_case       ,				self							).outputs
                if self.use_past:
                       _UpperCAmelCase							=    self.num_layers
                       for i in range(__snake_case							):
                              _UpperCAmelCase							=    {0: """batch""", 2: """past_sequence + sequence"""}
                              _UpperCAmelCase							=    {0: """batch""", 2: """past_sequence + sequence"""}
         return common_outputs


  def  lowerCamelCase       (      self		:			List[Any]       ,				lowerCamelCase		:			PreTrainedTokenizer       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			bool = False       ,				lowerCamelCase		:			Optional[TensorType] = None       ,				)						->	int:


         """simple docstring"""
         _UpperCAmelCase							=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             __snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case							)

         # Generate decoder inputs
         _UpperCAmelCase							=    seq_length if not self.use_past else 1
         _UpperCAmelCase							=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             __snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case							)
         _UpperCAmelCase							=    {f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
         _UpperCAmelCase							=    dict(**__snake_case       ,				**__snake_case							)

         if self.use_past:
                if not is_torch_available():
                       raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""							)
                else:
                       import torch
                _UpperCAmelCase							=    common_inputs["""input_ids"""].shape
                _UpperCAmelCase							=    common_inputs["""decoder_input_ids"""].shape[1]
                _UpperCAmelCase							=    self.num_attention_heads
                _UpperCAmelCase							=    (
                    batch,
                    num_encoder_attention_heads,
                    encoder_seq_length,
                    self._config.hidden_size // num_encoder_attention_heads,
                )
                _UpperCAmelCase							=    decoder_seq_length + 3
                _UpperCAmelCase							=    (
                    batch,
                    num_decoder_attention_heads,
                    decoder_past_length,
                    self._config.hidden_size // num_decoder_attention_heads,
                )

                _UpperCAmelCase							=    torch.cat(
                    [common_inputs["""decoder_attention_mask"""], torch.ones(__snake_case       ,				__snake_case							)]       ,				dim=1							)

                _UpperCAmelCase							=    []
                # If the number of encoder and decoder layers are present in the model configuration, both are considered
                _UpperCAmelCase							=    self.num_layers
                _UpperCAmelCase							=    min(__snake_case       ,				__snake_case							)
                _UpperCAmelCase							=    max(__snake_case       ,				__snake_case							) - min_num_layers
                _UpperCAmelCase							=    """encoder""" if num_encoder_layers > num_decoder_layers else """decoder"""

                for _ in range(__snake_case							):
                       common_inputs["past_key_values"].append(
                           (
                               torch.zeros(__snake_case							),
                               torch.zeros(__snake_case							),
                               torch.zeros(__snake_case							),
                               torch.zeros(__snake_case							),
                           )							)
                # TODO: test this.
                _UpperCAmelCase							=    encoder_shape if remaining_side_name == """encoder""" else decoder_shape
                for _ in range(__snake_case       ,				__snake_case							):
                       common_inputs["past_key_values"].append((torch.zeros(__snake_case							), torch.zeros(__snake_case							))							)
         return common_inputs


  def  lowerCamelCase       (      self		:			List[str]       ,				lowerCamelCase		:			PreTrainedTokenizer       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			bool = False       ,				lowerCamelCase		:			Optional[TensorType] = None       ,				)						->	Optional[int]:


         """simple docstring"""
         _UpperCAmelCase							=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             __snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case							)

         if self.use_past:
                if not is_torch_available():
                       raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""							)
                else:
                       import torch
                _UpperCAmelCase							=    common_inputs["""input_ids"""].shape
                # Not using the same length for past_key_values
                _UpperCAmelCase							=    seqlen + 2
                _UpperCAmelCase							=    self.num_layers
                _UpperCAmelCase							=    self.num_attention_heads
                _UpperCAmelCase							=    (
                    batch,
                    num_encoder_attention_heads,
                    past_key_values_length,
                    self._config.hidden_size // num_encoder_attention_heads,
                )

                _UpperCAmelCase							=    common_inputs["""attention_mask"""].dtype
                _UpperCAmelCase							=    torch.cat(
                    [common_inputs["""attention_mask"""], torch.ones(__snake_case       ,				__snake_case       ,				dtype=__snake_case							)]       ,				dim=1							)
                _UpperCAmelCase							=    [
                    (torch.zeros(__snake_case							), torch.zeros(__snake_case							)) for _ in range(__snake_case							)
                ]
         return common_inputs


  def  lowerCamelCase       (      self		:			Any       ,				lowerCamelCase		:			PreTrainedTokenizer       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			bool = False       ,				lowerCamelCase		:			Optional[TensorType] = None       ,				)						->	int:


         """simple docstring"""
         _UpperCAmelCase							=    compute_effective_axis_dimension(
             __snake_case       ,				fixed_dimension=OnnxConfig.default_fixed_batch       ,				num_token_to_add=0							)

         # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
         _UpperCAmelCase							=    tokenizer.num_special_tokens_to_add(__snake_case							)
         _UpperCAmelCase							=    compute_effective_axis_dimension(
             __snake_case       ,				fixed_dimension=OnnxConfig.default_fixed_sequence       ,				num_token_to_add=__snake_case							)

         # Generate dummy inputs according to compute batch and sequence
         _UpperCAmelCase							=    [""" """.join([tokenizer.unk_token]							) * seq_length] * batch_size
         _UpperCAmelCase							=    dict(tokenizer(__snake_case       ,				return_tensors=__snake_case							)							)
         return common_inputs


  def  lowerCamelCase       (      self		:			Optional[Any]       ,				lowerCamelCase		:			PreTrainedTokenizer       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			int = -1       ,				lowerCamelCase		:			bool = False       ,				lowerCamelCase		:			Optional[TensorType] = None       ,				)						->	int:


         """simple docstring"""

         if self.task in ["default", "seq2seq-lm"]:
                _UpperCAmelCase							=    self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                    __snake_case       ,				batch_size=__snake_case       ,				seq_length=__snake_case       ,				is_pair=__snake_case       ,				framework=__snake_case							)

         elif self.task == "causal-lm":
                _UpperCAmelCase							=    self._generate_dummy_inputs_for_causal_lm(
                    __snake_case       ,				batch_size=__snake_case       ,				seq_length=__snake_case       ,				is_pair=__snake_case       ,				framework=__snake_case							)
         else:
                _UpperCAmelCase							=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                    __snake_case       ,				batch_size=__snake_case       ,				seq_length=__snake_case       ,				is_pair=__snake_case       ,				framework=__snake_case							)

         return common_inputs





  def  lowerCamelCase       (      self		:			List[str]       ,				lowerCamelCase		:			Any       ,				lowerCamelCase		:			Dict       ,				lowerCamelCase		:			Any       ,				lowerCamelCase		:			Any							)						->	str:


         """simple docstring"""

         if self.task in ["default", "seq2seq-lm"]:
                _UpperCAmelCase							=    super()._flatten_past_key_values_(__snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case							)
         else:
                _UpperCAmelCase							=    super(__snake_case       ,				self							)._flatten_past_key_values_(
                    __snake_case       ,				__snake_case       ,				__snake_case       ,				__snake_case							)





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase_		:					Tuple          =  logging.get_logger(__name__)

UpperCAmelCase_		:					List[str]          =  {
    "facebook/xlm-roberta-xl": "https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json",
    "facebook/xlm-roberta-xxl": "https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json",
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}




class 		__A   (      UpperCamelCase__      ):
						UpperCamelCase      =       """xlm-roberta-xl"""

						def __init__(		self :Dict     ,			__snake_case :Optional[Any]=25_08_80     ,			__snake_case :List[Any]=25_60     ,			__snake_case :Optional[Any]=36     ,			__snake_case :Any=32     ,			__snake_case :int=1_02_40     ,			__snake_case :List[Any]="gelu"     ,			__snake_case :Union[str, Any]=0.1     ,			__snake_case :Optional[Any]=0.1     ,			__snake_case :str=5_14     ,			__snake_case :Union[str, Any]=1     ,			__snake_case :Optional[int]=0.02     ,			__snake_case :str=1E-05     ,			__snake_case :str=1     ,			__snake_case :int=0     ,			__snake_case :Tuple=2     ,			__snake_case :Optional[int]="absolute"     ,			__snake_case :str=True     ,			__snake_case :Any=None     ,			**__snake_case :Dict     ,			):
										'''simple docstring'''

										super().__init__(pad_token_id=__snake_case     ,			bos_token_id=__snake_case     ,			eos_token_id=__snake_case     ,			**__snake_case			)
										__magic_name__						:						List[str]										=vocab_size
										__magic_name__						:						List[str]										=hidden_size
										__magic_name__						:						Union[str, Any]										=num_hidden_layers
										__magic_name__						:						Any										=num_attention_heads
										__magic_name__						:						Any										=hidden_act
										__magic_name__						:						List[str]										=intermediate_size
										__magic_name__						:						Any										=hidden_dropout_prob
										__magic_name__						:						Union[str, Any]										=attention_probs_dropout_prob
										__magic_name__						:						Any										=max_position_embeddings
										__magic_name__						:						Any										=type_vocab_size
										__magic_name__						:						List[str]										=initializer_range
										__magic_name__						:						Optional[int]										=layer_norm_eps
										__magic_name__						:						Dict										=position_embedding_type
										__magic_name__						:						Any										=use_cache
										__magic_name__						:						Dict										=classifier_dropout




class 		__A   (      UpperCamelCase__      ):

						@property
						def      A__    (		self :Dict			):
										'''simple docstring'''

										if self.task == "multiple-choice":
														__magic_name__						:						str										={0: """batch""", 1: """choice""", 2: """sequence"""}
										else:
														__magic_name__						:						Optional[Any]										={0: """batch""", 1: """sequence"""}
										return OrderedDict(
										    [
										        ("""input_ids""", dynamic_axis),
										        ("""attention_mask""", dynamic_axis),
										    ]			)




