





from __future__ import annotations

import unittest

from transformers import DebertaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import tensorflow as tf

     from transformers import (
         TFDebertaForMaskedLM,
         TFDebertaForQuestionAnswering,
         TFDebertaForSequenceClassification,
         TFDebertaForTokenClassification,
         TFDebertaModel,
     )




class 			_lowerCamelCase	:



      """simple docstring"""






      def __init__(	self			,  UpperCAmelCase			,  UpperCAmelCase=13			,  UpperCAmelCase=7			,  UpperCAmelCase=True			,  UpperCAmelCase=True			,  UpperCAmelCase=True			,  UpperCAmelCase=True			,  UpperCAmelCase=99			,  UpperCAmelCase=32			,  UpperCAmelCase=2			,  UpperCAmelCase=4			,  UpperCAmelCase=37			,  UpperCAmelCase="gelu"			,  UpperCAmelCase=0.1			,  UpperCAmelCase=0.1			,  UpperCAmelCase=512			,  UpperCAmelCase=16			,  UpperCAmelCase=2			,  UpperCAmelCase=0.02			,  UpperCAmelCase=3			,  UpperCAmelCase=4			,  UpperCAmelCase=None			,  )    ->				Any:






        '''simple docstring'''






        __snake_case				:			Optional[int]            =    parent
        __snake_case				:			Tuple            =    13
        __snake_case				:			List[str]            =    7
        __snake_case				:			Optional[int]            =    True
        __snake_case				:			List[Any]            =    True
        __snake_case				:			int            =    True
        __snake_case				:			List[Any]            =    True
        __snake_case				:			Tuple            =    99
        __snake_case				:			List[str]            =    32
        __snake_case				:			str            =    2
        __snake_case				:			Union[str, Any]            =    4
        __snake_case				:			Dict            =    37
        __snake_case				:			Any            =    "gelu"
        __snake_case				:			Dict            =    0.1
        __snake_case				:			Optional[Any]            =    0.1
        __snake_case				:			Union[str, Any]            =    512
        __snake_case				:			Optional[Any]            =    16
        __snake_case				:			List[Any]            =    False
        __snake_case				:			Tuple            =    -1
        __snake_case				:			str            =    True
        __snake_case				:			Optional[Any]            =    2
        __snake_case				:			List[str]            =    0.02
        __snake_case				:			int            =    3
        __snake_case				:			Any            =    4
        __snake_case				:			Dict            =    None







      def   UpperCAmelCase						(	self				)    ->				Tuple:






        '''simple docstring'''






        __snake_case				:			Dict            =    ids_tensor([self.batch_size, self.seq_length]			,  self.vocab_size				)

        __snake_case				:			str            =    None
        if self.use_input_mask:
          __snake_case				:			Tuple            =    random_attention_mask([self.batch_size, self.seq_length]				)

        __snake_case				:			Any            =    None
        if self.use_token_type_ids:
          __snake_case				:			Optional[int]            =    ids_tensor([self.batch_size, self.seq_length]			,  self.type_vocab_size				)

        __snake_case				:			Optional[int]            =    None
        __snake_case				:			int            =    None
        __snake_case				:			Dict            =    None
        if self.use_labels:
          __snake_case				:			Optional[Any]            =    ids_tensor([self.batch_size]			,  self.type_sequence_label_size				)
          __snake_case				:			Any            =    ids_tensor([self.batch_size, self.seq_length]			,  self.num_labels				)

        __snake_case				:			Optional[int]            =    DebertaConfig(
            vocab_size=self.vocab_size			,  hidden_size=self.hidden_size			,  num_hidden_layers=self.num_hidden_layers			,  num_attention_heads=self.num_attention_heads			,  intermediate_size=self.intermediate_size			,  hidden_act=self.hidden_act			,  hidden_dropout_prob=self.hidden_dropout_prob			,  attention_probs_dropout_prob=self.attention_probs_dropout_prob			,  max_position_embeddings=self.max_position_embeddings			,  type_vocab_size=self.type_vocab_size			,  relative_attention=self.relative_attention			,  max_relative_positions=self.max_relative_positions			,  position_biased_input=self.position_biased_input			,  initializer_range=self.initializer_range			,  return_dict=SCREAMING_SNAKE_CASE__			,  )

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







      def   UpperCAmelCase						(	self			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				Optional[Any]:






        '''simple docstring'''






        __snake_case				:			str            =    TFDebertaModel(config=SCREAMING_SNAKE_CASE__				)
        __snake_case				:			Any            =    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

        __snake_case				:			List[str]            =    [input_ids, input_mask]
        __snake_case				:			Union[str, Any]            =    model(SCREAMING_SNAKE_CASE__				)

        __snake_case				:			Tuple            =    model(SCREAMING_SNAKE_CASE__				)

        self.parent.assertEqual(result.last_hidden_state.shape			,  (self.batch_size, self.seq_length, self.hidden_size)				)







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






        '''simple docstring'''






        __snake_case				:			int            =    TFDebertaForMaskedLM(config=SCREAMING_SNAKE_CASE__				)
        __snake_case				:			Optional[Any]            =    {
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }
        __snake_case				:			Optional[Any]            =    model(SCREAMING_SNAKE_CASE__				)
        self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.vocab_size)				)







      def   UpperCAmelCase						(	self			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				Dict:






        '''simple docstring'''






        __snake_case				:			Optional[int]            =    self.num_labels
        __snake_case				:			str            =    TFDebertaForSequenceClassification(config=SCREAMING_SNAKE_CASE__				)
        __snake_case				:			Tuple            =    {
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }

        __snake_case				:			Optional[Any]            =    model(SCREAMING_SNAKE_CASE__				)
        self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.num_labels)				)







      def   UpperCAmelCase						(	self			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				List[Any]:






        '''simple docstring'''






        __snake_case				:			Any            =    self.num_labels
        __snake_case				:			Dict            =    TFDebertaForTokenClassification(config=SCREAMING_SNAKE_CASE__				)
        __snake_case				:			str            =    {
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }
        __snake_case				:			Optional[int]            =    model(SCREAMING_SNAKE_CASE__				)
        self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.num_labels)				)







      def   UpperCAmelCase						(	self			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				int:






        '''simple docstring'''






        __snake_case				:			List[str]            =    TFDebertaForQuestionAnswering(config=SCREAMING_SNAKE_CASE__				)
        __snake_case				:			Optional[Any]            =    {
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }

        __snake_case				:			str            =    model(SCREAMING_SNAKE_CASE__				)
        self.parent.assertEqual(result.start_logits.shape			,  (self.batch_size, self.seq_length)				)
        self.parent.assertEqual(result.end_logits.shape			,  (self.batch_size, self.seq_length)				)







      def   UpperCAmelCase						(	self				)    ->				Tuple:






        '''simple docstring'''






        __snake_case				:			int            =    self.prepare_config_and_inputs()
        (
            __snake_case      
        )				:			List[Any]            =    config_and_inputs
        __snake_case				:			List[Any]            =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
        return config, inputs_dict




@require_tf
class 			_lowerCamelCase	(      _a	,				_a	,				unittest.TestCase      ):



      """simple docstring"""






      UpperCAmelCase_  : Any				      =(
          (
              TFDebertaModel,
              TFDebertaForMaskedLM,
              TFDebertaForQuestionAnswering,
              TFDebertaForSequenceClassification,
              TFDebertaForTokenClassification,
          )
          if is_tf_available()
          else ()
      )
      UpperCAmelCase_  : List[str]				      =(
          {
              '''feature-extraction''': TFDebertaModel,
              '''fill-mask''': TFDebertaForMaskedLM,
              '''question-answering''': TFDebertaForQuestionAnswering,
              '''text-classification''': TFDebertaForSequenceClassification,
              '''token-classification''': TFDebertaForTokenClassification,
              '''zero-shot''': TFDebertaForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )

      UpperCAmelCase_  : Any				      =False
      UpperCAmelCase_  : List[Any]				      =False







      def   UpperCAmelCase						(	self				)    ->				List[Any]:






        '''simple docstring'''






        __snake_case				:			Tuple            =    TFDebertaModelTester(self				)
        __snake_case				:			Tuple            =    ConfigTester(self			,  config_class=SCREAMING_SNAKE_CASE__			,  hidden_size=37				)







      def   UpperCAmelCase						(	self				)    ->				Optional[int]:






        '''simple docstring'''






        self.config_tester.run_common_tests()







      def   UpperCAmelCase						(	self				)    ->				Tuple:






        '''simple docstring'''






        __snake_case				:			Tuple            =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__				)







      def   UpperCAmelCase						(	self				)    ->				Tuple:






        '''simple docstring'''






        __snake_case				:			Optional[Any]            =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE__				)







      def   UpperCAmelCase						(	self				)    ->				int:






        '''simple docstring'''






        __snake_case				:			List[Any]            =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE__				)







      def   UpperCAmelCase						(	self				)    ->				str:






        '''simple docstring'''






        __snake_case				:			str            =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE__				)







      def   UpperCAmelCase						(	self				)    ->				List[Any]:






        '''simple docstring'''






        __snake_case				:			Optional[int]            =    self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE__				)







      @slow
      def   UpperCAmelCase						(	self				)    ->				str:






        '''simple docstring'''






        __snake_case				:			Optional[Any]            =    TFDebertaModel.from_pretrained("kamalkraj/deberta-base"				)
        self.assertIsNotNone(SCREAMING_SNAKE_CASE__				)




@require_tf
class 			_lowerCamelCase	(      unittest.TestCase      ):



      """simple docstring"""






      @unittest.skip(reason="Model not available yet"				)
      def   UpperCAmelCase						(	self				)    ->				Any:






        '''simple docstring'''






        pass







      @slow
      def   UpperCAmelCase						(	self				)    ->				List[Any]:






        '''simple docstring'''






        __snake_case				:			Dict            =    TFDebertaModel.from_pretrained("kamalkraj/deberta-base"				)
        __snake_case				:			int            =    tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]				)
        __snake_case				:			Dict            =    tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
        __snake_case				:			Optional[int]            =    model(SCREAMING_SNAKE_CASE__			,  attention_mask=SCREAMING_SNAKE_CASE__				)[0]

        __snake_case				:			Optional[int]            =    tf.constant(
            [
                [
                    [-0.59_855_896, -0.80_552_566, -0.8_462_135],
                    [1.4_484_025, -0.93_483_794, -0.80_593_085],
                    [0.3_122_741, 0.00_316_059, -1.4_131_377],
                ]
            ]				)
        tf.debugging.assert_near(output[:, 1:4, 1:4]			,  SCREAMING_SNAKE_CASE__			,  atol=1E-4				)








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


_UpperCamelCase    =	logging.get_logger(__name__)

_UpperCamelCase    =	{
    '''facebook/blenderbot-3B''': '''https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json''',
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}




class 			_lowerCamelCase	(      a      ):



      """simple docstring"""






      UpperCAmelCase_  : Tuple				      ="blenderbot"
      UpperCAmelCase_  : Any				      =["past_key_values"]
      UpperCAmelCase_  : Optional[int]				      ={"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}







      def __init__(	self			,  UpperCAmelCase=8008			,  UpperCAmelCase=128			,  UpperCAmelCase=2			,  UpperCAmelCase=10240			,  UpperCAmelCase=32			,  UpperCAmelCase=24			,  UpperCAmelCase=10240			,  UpperCAmelCase=32			,  UpperCAmelCase=0.0			,  UpperCAmelCase=0.0			,  UpperCAmelCase=True			,  UpperCAmelCase=True			,  UpperCAmelCase="gelu"			,  UpperCAmelCase=2560			,  UpperCAmelCase=0.1			,  UpperCAmelCase=0.0			,  UpperCAmelCase=0.0			,  UpperCAmelCase=0.02			,  UpperCAmelCase=1			,  UpperCAmelCase=False			,  UpperCAmelCase=0			,  UpperCAmelCase=1			,  UpperCAmelCase=2			,  UpperCAmelCase=3			,  UpperCAmelCase=2			,  **UpperCAmelCase			,  )    ->				List[Any]:






        '''simple docstring'''






        __snake_case				:			List[Any]            =    vocab_size
        __snake_case				:			List[str]            =    max_position_embeddings
        __snake_case				:			str            =    d_model
        __snake_case				:			int            =    encoder_ffn_dim
        __snake_case				:			Dict            =    encoder_layers
        __snake_case				:			Any            =    encoder_attention_heads
        __snake_case				:			Optional[int]            =    decoder_ffn_dim
        __snake_case				:			int            =    decoder_layers
        __snake_case				:			Dict            =    decoder_attention_heads
        __snake_case				:			Optional[int]            =    dropout
        __snake_case				:			Optional[Any]            =    attention_dropout
        __snake_case				:			Dict            =    activation_dropout
        __snake_case				:			Any            =    activation_function
        __snake_case				:			List[Any]            =    init_std
        __snake_case				:			Any            =    encoder_layerdrop
        __snake_case				:			List[Any]            =    decoder_layerdrop
        __snake_case				:			Any            =    use_cache
        __snake_case				:			Optional[int]            =    encoder_layers
        __snake_case				:			Optional[int]            =    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			,  encoder_no_repeat_ngram_size=UpperCAmelCase			,  forced_eos_token_id=UpperCAmelCase			,  **UpperCAmelCase			,  )




class 			_lowerCamelCase	(      a      ):



      """simple docstring"""






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






        '''simple docstring'''






        if self.task in ["default", "seq2seq-lm"]:
          __snake_case				:			Any            =    OrderedDict(
              [
                  ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                  ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
              ]				)
          if self.use_past:
            __snake_case				:			List[str]            =    {0: "batch"}
            __snake_case				:			Optional[Any]            =    {0: "batch", 1: "past_decoder_sequence + sequence"}
          else:
            __snake_case				:			int            =    {0: "batch", 1: "decoder_sequence"}
            __snake_case				:			Optional[int]            =    {0: "batch", 1: "decoder_sequence"}
          if self.use_past:
            self.fill_with_past_key_values_(UpperCAmelCase			,  direction="inputs"				)
        elif self.task == "causal-lm":
          __snake_case				:			List[str]            =    OrderedDict(
              [
                  ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                  ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
              ]				)
          if self.use_past:
            __snake_case      ,				__snake_case				:			List[Any]            =    self.num_layers
            for i in range(UpperCAmelCase				):
              __snake_case				:			int            =    {0: "batch", 2: "past_sequence + sequence"}
              __snake_case				:			Tuple            =    {0: "batch", 2: "past_sequence + sequence"}
        else:
          __snake_case				:			Dict            =    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
      # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
      def   UpperCAmelCase						(	self				)    ->				Mapping[str, Mapping[int, str]]:






        '''simple docstring'''






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







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






        '''simple docstring'''






        __snake_case				:			int            =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)
        # Generate decoder inputs
        __snake_case				:			List[Any]            =    seq_length if not self.use_past else 1
        __snake_case				:			Tuple            =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)
        __snake_case				:			Tuple            =    {F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
        __snake_case				:			Dict            =    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
          __snake_case      ,				__snake_case				:			int            =    common_inputs["input_ids"].shape
          __snake_case				:			Union[str, Any]            =    common_inputs["decoder_input_ids"].shape[1]
          __snake_case      ,				__snake_case				:			Optional[Any]            =    self.num_attention_heads
          __snake_case				:			Tuple            =    (
              batch,
              num_encoder_attention_heads,
              encoder_seq_length,
              self._config.hidden_size // num_encoder_attention_heads,
          )
          __snake_case				:			Any            =    decoder_seq_length
          __snake_case				:			List[Any]            =    (
              batch,
              num_decoder_attention_heads,
              decoder_past_length,
              self._config.hidden_size // num_decoder_attention_heads,
          )
          __snake_case				:			Any            =    torch.cat(
              [common_inputs["decoder_attention_mask"], torch.ones(UpperCAmelCase			,  UpperCAmelCase				)]			,  dim=1				)
          __snake_case				:			Any            =    []
          __snake_case      ,				__snake_case				:			Tuple            =    self.num_layers

          for _ in range(UpperCAmelCase				):
            common_inputs["past_key_values"].append(
                (
                    torch.zeros(UpperCAmelCase				),
                    torch.zeros(UpperCAmelCase				),
                    torch.zeros(UpperCAmelCase				),
                    torch.zeros(UpperCAmelCase				),
                )				)
        return common_inputs







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






        '''simple docstring'''






        __snake_case				:			List[Any]            =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  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
          __snake_case      ,				__snake_case				:			List[Any]            =    common_inputs["input_ids"].shape
          __snake_case				:			Any            =    seqlen
          __snake_case      ,				__snake_case				:			Dict            =    self.num_layers
          __snake_case      ,				__snake_case				:			int            =    self.num_attention_heads
          __snake_case				:			str            =    (
              batch,
              num_encoder_attention_heads,
              past_key_values_length,
              self._config.hidden_size // num_encoder_attention_heads,
          )
          __snake_case				:			Dict            =    common_inputs["attention_mask"].dtype
          __snake_case				:			Optional[Any]            =    torch.cat(
              [common_inputs["attention_mask"], torch.ones(UpperCAmelCase			,  UpperCAmelCase			,  dtype=UpperCAmelCase				)]			,  dim=1				)
          __snake_case				:			str            =    [
              (torch.zeros(UpperCAmelCase				), torch.zeros(UpperCAmelCase				)) for _ in range(UpperCAmelCase				)
          ]
        return common_inputs







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






        '''simple docstring'''






        __snake_case				:			Tuple            =    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
        __snake_case				:			str            =    tokenizer.num_special_tokens_to_add(UpperCAmelCase				)
        __snake_case				:			Any            =    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
        __snake_case				:			Tuple            =    [" ".join([tokenizer.unk_token]				) * seq_length] * batch_size
        __snake_case				:			str            =    dict(tokenizer(UpperCAmelCase			,  return_tensors=UpperCAmelCase				)				)
        return common_inputs







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






        '''simple docstring'''






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

        elif self.task == "causal-lm":
          __snake_case				:			Union[str, Any]            =    self._generate_dummy_inputs_for_causal_lm(
              UpperCAmelCase			,  batch_size=UpperCAmelCase			,  seq_length=UpperCAmelCase			,  is_pair=UpperCAmelCase			,  framework=UpperCAmelCase				)
        else:
          __snake_case				:			Dict            =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
              UpperCAmelCase			,  batch_size=UpperCAmelCase			,  seq_length=UpperCAmelCase			,  is_pair=UpperCAmelCase			,  framework=UpperCAmelCase				)

        return common_inputs







      def   UpperCAmelCase						(	self			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				int:






        '''simple docstring'''






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







      def   UpperCAmelCase						(	self			,  UpperCAmelCase			,  UpperCAmelCase				)    ->				Any:






        '''simple docstring'''






        if direction not in ["inputs", "outputs"]:
          raise ValueError(F"""direction must either be \"inputs\" or \"outputs\", but {direction} was given"""				)

        __snake_case				:			Tuple            =    "past_key_values" if direction == "inputs" else "present"
        __snake_case      ,				__snake_case				:			Any            =    self.num_layers

        __snake_case				:			int            =    "past_encoder_sequence"
        __snake_case				:			int            =    "past_decoder_sequence" if direction == "inputs" else "past_decoder_sequence + sequence"

        for i in range(UpperCAmelCase				):
          __snake_case				:			Any            =    {0: "batch", 2: decoder_sequence}
          __snake_case				:			List[Any]            =    {0: "batch", 2: decoder_sequence}
          __snake_case				:			Tuple            =    {0: "batch", 2: encoder_sequence}
          __snake_case				:			int            =    {0: "batch", 2: encoder_sequence}

