





"""simple docstring"""
from collections import OrderedDict
from typing import Any, Mapping, Optional

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


lowerCAmelCase:	Union[str, Any]							      =logging.get_logger(__name__)

lowerCAmelCase:	Any							      ={
    "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/config.json",
    # See all M2M100 models at https://huggingface.co/models?filter=m2m_100
}
class lowerCamelCase__  (    __SCREAMING_SNAKE_CASE				):
   __UpperCAmelCase        =					"""m2m_100"""
   __UpperCAmelCase        =					["""past_key_values"""]
   __UpperCAmelCase        =					{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}



   def __init__(       self      ,   snake_case=1_2_8_1_1_2      ,   snake_case=1_0_2_4      ,   snake_case=1_2      ,   snake_case=4_0_9_6      ,   snake_case=1_6      ,   snake_case=1_2      ,   snake_case=4_0_9_6      ,   snake_case=1_6      ,   snake_case=0.05      ,   snake_case=0.05      ,   snake_case=True      ,   snake_case=True      ,   snake_case="relu"      ,   snake_case=1_0_2_4      ,   snake_case=0.1      ,   snake_case=0.1      ,   snake_case=0.0      ,   snake_case=0.02      ,   snake_case=2      ,   snake_case=True      ,   snake_case=1      ,   snake_case=0      ,   snake_case=2      ,   **snake_case      ,   ) ->    Any:







      """simple docstring"""
      lowercase    :			Dict  =       vocab_size
      lowercase    :			List[str]  =       max_position_embeddings
      lowercase    :			List[Any]  =       d_model
      lowercase    :			List[Any]  =       encoder_ffn_dim
      lowercase    :			Optional[Any]  =       encoder_layers
      lowercase    :			List[str]  =       encoder_attention_heads
      lowercase    :			str  =       decoder_ffn_dim
      lowercase    :			List[Any]  =       decoder_layers
      lowercase    :			Any  =       decoder_attention_heads
      lowercase    :			Dict  =       dropout
      lowercase    :			Union[str, Any]  =       attention_dropout
      lowercase    :			Tuple  =       activation_dropout
      lowercase    :			Tuple  =       activation_function
      lowercase    :			List[str]  =       init_std
      lowercase    :			Optional[int]  =       encoder_layerdrop
      lowercase    :			List[Any]  =       decoder_layerdrop
      lowercase    :			Optional[Any]  =       use_cache
      lowercase    :			Any  =       encoder_layers
      lowercase    :			List[Any]  =       scale_embedding  # scale factor will be sqrt(d_model) if True

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




class lowerCamelCase__  (    __SCREAMING_SNAKE_CASE				):



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







      """simple docstring"""
      lowercase    :			Dict  =       OrderedDict(
          [
              ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
              ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
          ]	)

      if self.use_past:
         lowercase    :			Union[str, Any]  =       {0: '''batch'''}
         lowercase    :			str  =       {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
      else:
         lowercase    :			Tuple  =       {0: '''batch''', 1: '''decoder_sequence'''}
         lowercase    :			Optional[Any]  =       {0: '''batch''', 1: '''decoder_sequence'''}

      if self.use_past:
         self.fill_with_past_key_values_(UpperCamelCase__      ,   direction="""inputs"""	)
      return common_inputs



   def    _UpperCAmelCase	(       self      ,   snake_case      ,   snake_case = -1      ,   snake_case = -1      ,   snake_case = False      ,   snake_case = None      ,   ) ->    Mapping[str, Any]:







      """simple docstring"""
      lowercase    :			str  =       compute_effective_axis_dimension(
          UpperCamelCase__      ,   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
      lowercase    :			Union[str, Any]  =       tokenizer.num_special_tokens_to_add(UpperCamelCase__	)
      lowercase    :			Optional[int]  =       compute_effective_axis_dimension(
          UpperCamelCase__      ,   fixed_dimension=OnnxConfig.default_fixed_sequence      ,   num_token_to_add=UpperCamelCase__	)

      # Generate dummy inputs according to compute batch and sequence
      lowercase    :			Any  =       [''' '''.join([tokenizer.unk_token]	) * seq_length] * batch_size
      lowercase    :			Union[str, Any]  =       dict(tokenizer(UpperCamelCase__      ,   return_tensors=UpperCamelCase__	)	)
      return common_inputs



   def    _UpperCAmelCase	(       self      ,   snake_case      ,   snake_case = -1      ,   snake_case = -1      ,   snake_case = False      ,   snake_case = None      ,   ) ->    Mapping[str, Any]:







      """simple docstring"""
      lowercase    :			Dict  =       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          UpperCamelCase__      ,   UpperCamelCase__      ,   UpperCamelCase__      ,   UpperCamelCase__      ,   UpperCamelCase__	)

      # Generate decoder inputs
      lowercase    :			int  =       seq_length if not self.use_past else 1
      lowercase    :			Any  =       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          UpperCamelCase__      ,   UpperCamelCase__      ,   UpperCamelCase__      ,   UpperCamelCase__      ,   UpperCamelCase__	)
      lowercase    :			List[str]  =       {f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
      lowercase    :			Union[str, Any]  =       dict(**UpperCamelCase__      ,   **UpperCamelCase__	)

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

         lowercase    :			str  =       torch.cat(
             [common_inputs["""decoder_attention_mask"""], torch.ones(UpperCamelCase__      ,   UpperCamelCase__	)]      ,   dim=1	)

         lowercase    :			Union[str, Any]  =       []
         # If the number of encoder and decoder layers are present in the model configuration, both are considered
         lowercase    :			Dict  =       self.num_layers
         lowercase    :			Dict  =       min(UpperCamelCase__      ,   UpperCamelCase__	)
         lowercase    :			int  =       max(UpperCamelCase__      ,   UpperCamelCase__	) - min_num_layers
         lowercase    :			Optional[int]  =       '''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

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





   __UpperCAmelCase        =					_generate_dummy_inputs_for_default_and_seqaseq_lm







"""simple docstring"""
from typing import TYPE_CHECKING

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


lowerCAmelCase:	Union[str, Any]							      ={
    "configuration_deberta_v2": ["DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP", "DebertaV2Config", "DebertaV2OnnxConfig"],
    "tokenization_deberta_v2": ["DebertaV2Tokenizer"],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCAmelCase:	Dict							      =["DebertaV2TokenizerFast"]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCAmelCase:	Optional[Any]							      =[
       "TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
       "TFDebertaV2ForMaskedLM",
       "TFDebertaV2ForQuestionAnswering",
       "TFDebertaV2ForSequenceClassification",
       "TFDebertaV2ForTokenClassification",
       "TFDebertaV2Model",
       "TFDebertaV2PreTrainedModel",
   ]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCAmelCase:	str							      =[
       "DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
       "DebertaV2ForMaskedLM",
       "DebertaV2ForMultipleChoice",
       "DebertaV2ForQuestionAnswering",
       "DebertaV2ForSequenceClassification",
       "DebertaV2ForTokenClassification",
       "DebertaV2Model",
       "DebertaV2PreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_deberta_va import (
       DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP,
       DebertaVaConfig,
       DebertaVaOnnxConfig,
   )
   from .tokenization_deberta_va import DebertaVaTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_deberta_va_fast import DebertaVaTokenizerFast

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_deberta_va import (
          TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFDebertaVaForMaskedLM,
          TFDebertaVaForQuestionAnswering,
          TFDebertaVaForSequenceClassification,
          TFDebertaVaForTokenClassification,
          TFDebertaVaModel,
          TFDebertaVaPreTrainedModel,
      )

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_deberta_va import (
          DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
          DebertaVaForMaskedLM,
          DebertaVaForMultipleChoice,
          DebertaVaForQuestionAnswering,
          DebertaVaForSequenceClassification,
          DebertaVaForTokenClassification,
          DebertaVaModel,
          DebertaVaPreTrainedModel,
      )

else:
   import sys

   lowerCAmelCase:	Optional[Any]							      =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


