


'''simple docstring'''





from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import DeiTConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

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


if is_tf_available():
    import tensorflow as tf

    from transformers import (
        TFDeiTForImageClassification,
        TFDeiTForImageClassificationWithTeacher,
        TFDeiTForMaskedImageModeling,
        TFDeiTModel,
    )
    from transformers.models.deit.modeling_tf_deit import TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
    from PIL import Image

    from transformers import DeiTImageProcessor







class     _lowercase				:


       """simple docstring"""




       def __init__(     self							:    Optional[int]      ,   __lowerCamelCase							:    Tuple      ,   __lowerCamelCase							:    int=13      ,   __lowerCamelCase							:    Union[str, Any]=30      ,   __lowerCamelCase							:    List[str]=2      ,   __lowerCamelCase							:    Optional[Any]=3      ,   __lowerCamelCase							:    Optional[int]=True      ,   __lowerCamelCase							:    Optional[Any]=True      ,   __lowerCamelCase							:    Any=32      ,   __lowerCamelCase							:    Dict=2      ,   __lowerCamelCase							:    str=4      ,   __lowerCamelCase							:    Tuple=37      ,   __lowerCamelCase							:    Union[str, Any]="gelu"      ,   __lowerCamelCase							:    List[Any]=0.1      ,   __lowerCamelCase							:    Any=0.1      ,   __lowerCamelCase							:    Union[str, Any]=10      ,   __lowerCamelCase							:    Tuple=0.0_2      ,   __lowerCamelCase							:    Any=3      ,   __lowerCamelCase							:    str=None      ,   __lowerCamelCase							:    Optional[Any]=2      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       List[Any]					=						parent
             lowerCamelCase__	:       int					=						batch_size
             lowerCamelCase__	:       Any					=						image_size
             lowerCamelCase__	:       List[str]					=						patch_size
             lowerCamelCase__	:       Tuple					=						num_channels
             lowerCamelCase__	:       Optional[Any]					=						is_training
             lowerCamelCase__	:       List[Any]					=						use_labels
             lowerCamelCase__	:       Optional[int]					=						hidden_size
             lowerCamelCase__	:       Optional[int]					=						num_hidden_layers
             lowerCamelCase__	:       Any					=						num_attention_heads
             lowerCamelCase__	:       Optional[int]					=						intermediate_size
             lowerCamelCase__	:       str					=						hidden_act
             lowerCamelCase__	:       Union[str, Any]					=						hidden_dropout_prob
             lowerCamelCase__	:       Optional[Any]					=						attention_probs_dropout_prob
             lowerCamelCase__	:       Dict					=						type_sequence_label_size
             lowerCamelCase__	:       List[str]					=						initializer_range
             lowerCamelCase__	:       int					=						scope
             lowerCamelCase__	:       List[str]					=						encoder_stride

             # in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
             lowerCamelCase__	:       List[Any]					=						(image_size // patch_size) ** 2
             lowerCamelCase__	:       Tuple					=						num_patches + 2





       def 		lowerCAmelCase  (     self							:    Dict ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

             lowerCamelCase__	:       Any					=						None
             if self.use_labels:
                   lowerCamelCase__	:       Optional[int]					=						ids_tensor([self.batch_size]      ,   self.type_sequence_label_size )

             lowerCamelCase__	:       Optional[Any]					=						self.get_config()

             return config, pixel_values, labels





       def 		lowerCAmelCase  (     self							:    Any ):


             '''simple docstring'''



             return DeiTConfig(
                 image_size=self.image_size      ,   patch_size=self.patch_size      ,   num_channels=self.num_channels      ,   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      ,   is_decoder=__lowerCamelCase      ,   initializer_range=self.initializer_range      ,   encoder_stride=self.encoder_stride      ,   )





       def 		lowerCAmelCase  (     self							:    Tuple      ,   __lowerCamelCase							:    Any      ,   __lowerCamelCase							:    List[str]      ,   __lowerCamelCase							:    Dict ):


             '''simple docstring'''



             lowerCamelCase__	:       List[Any]					=						TFDeiTModel(config=__lowerCamelCase )
             lowerCamelCase__	:       List[Any]					=						model(__lowerCamelCase )
             self.parent.assertEqual(result.last_hidden_state.shape      ,   (self.batch_size, self.seq_length, self.hidden_size) )





       def 		lowerCAmelCase  (     self							:    List[str]      ,   __lowerCamelCase							:    str      ,   __lowerCamelCase							:    int      ,   __lowerCamelCase							:    str ):


             '''simple docstring'''



             lowerCamelCase__	:       List[Any]					=						TFDeiTForMaskedImageModeling(config=__lowerCamelCase )
             lowerCamelCase__	:       List[str]					=						model(__lowerCamelCase )
             self.parent.assertEqual(
                 result.reconstruction.shape      ,   (self.batch_size, self.num_channels, self.image_size, self.image_size) )

             # test greyscale images
             lowerCamelCase__	:       Optional[Any]					=						1
             lowerCamelCase__	:       Union[str, Any]					=						TFDeiTForMaskedImageModeling(__lowerCamelCase )

             lowerCamelCase__	:       Dict					=						floats_tensor([self.batch_size, 1, self.image_size, self.image_size] )
             lowerCamelCase__	:       Any					=						model(__lowerCamelCase )
             self.parent.assertEqual(result.reconstruction.shape      ,   (self.batch_size, 1, self.image_size, self.image_size) )





       def 		lowerCAmelCase  (     self							:    Tuple      ,   __lowerCamelCase							:    Optional[int]      ,   __lowerCamelCase							:    List[str]      ,   __lowerCamelCase							:    Tuple ):


             '''simple docstring'''



             lowerCamelCase__	:       Tuple					=						self.type_sequence_label_size
             lowerCamelCase__	:       int					=						TFDeiTForImageClassification(__lowerCamelCase )
             lowerCamelCase__	:       int					=						model(__lowerCamelCase      ,   labels=__lowerCamelCase )
             self.parent.assertEqual(result.logits.shape      ,   (self.batch_size, self.type_sequence_label_size) )

             # test greyscale images
             lowerCamelCase__	:       Optional[Any]					=						1
             lowerCamelCase__	:       Tuple					=						TFDeiTForImageClassification(__lowerCamelCase )

             lowerCamelCase__	:       List[Any]					=						floats_tensor([self.batch_size, 1, self.image_size, self.image_size] )
             lowerCamelCase__	:       str					=						model(__lowerCamelCase      ,   labels=__lowerCamelCase )
             self.parent.assertEqual(result.logits.shape      ,   (self.batch_size, self.type_sequence_label_size) )





       def 		lowerCAmelCase  (     self							:    str ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						self.prepare_config_and_inputs()
             lowerCamelCase__					,     lowerCamelCase__					,     lowerCamelCase__	:       List[str]					=						config_and_inputs
             lowerCamelCase__	:       List[Any]					=						{"pixel_values": pixel_values}
             return config, inputs_dict







@require_tf
class     _lowercase				(							lowercase__							,						lowercase__							,						unittest.TestCase):


       """simple docstring"""




       A__      		=    (
           (
               TFDeiTModel,
               TFDeiTForImageClassification,
               TFDeiTForImageClassificationWithTeacher,
               TFDeiTForMaskedImageModeling,
           )
           if is_tf_available()
           else ()
       )
       A__      		=    (
           {
               """feature-extraction""": TFDeiTModel,
               """image-classification""": (TFDeiTForImageClassification, TFDeiTForImageClassificationWithTeacher),
           }
           if is_tf_available()
           else {}
       )

       A__      		=    False
       A__      		=    False
       A__      		=    False
       A__      		=    False





       def 		lowerCAmelCase  (     self							:    List[Any] ):


             '''simple docstring'''



             lowerCamelCase__	:       int					=						TFDeiTModelTester(self )
             lowerCamelCase__	:       str					=						ConfigTester(self      ,   config_class=__lowerCamelCase      ,   has_text_modality=__lowerCamelCase      ,   hidden_size=37 )





       def 		lowerCAmelCase  (     self							:    Optional[int] ):


             '''simple docstring'''



             self.config_tester.run_common_tests()





       @unittest.skip(reason="DeiT does not use inputs_embeds" )
       def 		lowerCAmelCase  (     self							:    Tuple ):


             '''simple docstring'''



             pass





       def 		lowerCAmelCase  (     self							:    Optional[Any] ):


             '''simple docstring'''



             lowerCamelCase__					,     lowerCamelCase__	:       Any					=						self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   lowerCamelCase__	:       Tuple					=						model_class(__lowerCamelCase )
                   self.assertIsInstance(model.get_input_embeddings()      ,   (tf.keras.layers.Layer) )
                   lowerCamelCase__	:       Optional[Any]					=						model.get_output_embeddings()
                   self.assertTrue(x is None or isinstance(__lowerCamelCase      ,   tf.keras.layers.Dense ) )





       def 		lowerCAmelCase  (     self							:    Optional[Any] ):


             '''simple docstring'''



             lowerCamelCase__					,     lowerCamelCase__	:       Tuple					=						self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   lowerCamelCase__	:       Optional[int]					=						model_class(__lowerCamelCase )
                   lowerCamelCase__	:       List[str]					=						inspect.signature(model.call )
                   # signature.parameters is an OrderedDict => so arg_names order is deterministic
                   lowerCamelCase__	:       int					=						[*signature.parameters.keys()]

                   lowerCamelCase__	:       Dict					=						["pixel_values"]
                   self.assertListEqual(arg_names[:1]      ,   __lowerCamelCase )





       def 		lowerCAmelCase  (     self							:    Tuple ):


             '''simple docstring'''



             lowerCamelCase__	:       List[str]					=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__lowerCamelCase )





       def 		lowerCAmelCase  (     self							:    List[str] ):


             '''simple docstring'''



             lowerCamelCase__	:       int					=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_image_modeling(*__lowerCamelCase )





       def 		lowerCAmelCase  (     self							:    List[Any] ):


             '''simple docstring'''



             lowerCamelCase__	:       List[str]					=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase )





       def 		lowerCAmelCase  (     self							:    str      ,   __lowerCamelCase							:    Any      ,   __lowerCamelCase							:    Dict      ,   __lowerCamelCase							:    List[Any]=False ):


             '''simple docstring'''



             lowerCamelCase__	:       Optional[Any]					=						super()._prepare_for_class(__lowerCamelCase      ,   __lowerCamelCase      ,   return_labels=__lowerCamelCase )

             if return_labels:
                   if "labels" in inputs_dict and "labels" not in inspect.signature(model_class.call ).parameters:
                         del inputs_dict["labels"]

             return inputs_dict





       @slow
       def 		lowerCAmelCase  (     self							:    Optional[Any] ):


             '''simple docstring'''



             for model_name in TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   lowerCamelCase__	:       int					=						TFDeiTModel.from_pretrained(__lowerCamelCase )
                   self.assertIsNotNone(__lowerCamelCase )



def    lowercase_	(	):

      """simple docstring"""




      lowerCamelCase__	:       str					=						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
      return image







@require_tf
@require_vision
class     _lowercase				(							unittest.TestCase):


       """simple docstring"""




       @cached_property
       def 		lowerCAmelCase  (     self							:    List[Any] ):


             '''simple docstring'''



             return (
                 DeiTImageProcessor.from_pretrained("facebook/deit-base-distilled-patch16-224" )
                 if is_vision_available()
                 else None
             )





       @slow
       def 		lowerCAmelCase  (     self							:    Optional[Any] ):


             '''simple docstring'''



             lowerCamelCase__	:       List[Any]					=						TFDeiTForImageClassificationWithTeacher.from_pretrained("facebook/deit-base-distilled-patch16-224" )

             lowerCamelCase__	:       Optional[int]					=						self.default_image_processor
             lowerCamelCase__	:       int					=						prepare_img()
             lowerCamelCase__	:       str					=						image_processor(images=__lowerCamelCase      ,   return_tensors="tf" )

             # forward pass
             lowerCamelCase__	:       List[str]					=						model(**__lowerCamelCase )

             # verify the logits
             lowerCamelCase__	:       List[str]					=						tf.TensorShape((1, 1000) )
             self.assertEqual(outputs.logits.shape      ,   __lowerCamelCase )

             lowerCamelCase__	:       Union[str, Any]					=						tf.constant([-1.0_2_6_6, 0.1_9_1_2, -1.2_8_6_1] )

             self.assertTrue(np.allclose(outputs.logits[0, :3]      ,   __lowerCamelCase      ,   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


A   :					List[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     _lowercase				(							lowercase__):


       """simple docstring"""




       A__      		=    "blenderbot-small"
       A__      		=    ["past_key_values"]
       A__      		=    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}





       def __init__(     self							:    Dict      ,   __lowerCamelCase							:    List[str]=50265      ,   __lowerCamelCase							:    str=512      ,   __lowerCamelCase							:    Tuple=8      ,   __lowerCamelCase							:    str=2048      ,   __lowerCamelCase							:    str=16      ,   __lowerCamelCase							:    List[Any]=8      ,   __lowerCamelCase							:    Any=2048      ,   __lowerCamelCase							:    List[str]=16      ,   __lowerCamelCase							:    Dict=0.0      ,   __lowerCamelCase							:    List[Any]=0.0      ,   __lowerCamelCase							:    Optional[int]=True      ,   __lowerCamelCase							:    Union[str, Any]=True      ,   __lowerCamelCase							:    Tuple="gelu"      ,   __lowerCamelCase							:    Tuple=512      ,   __lowerCamelCase							:    Dict=0.1      ,   __lowerCamelCase							:    int=0.0      ,   __lowerCamelCase							:    Union[str, Any]=0.0      ,   __lowerCamelCase							:    Any=0.0_2      ,   __lowerCamelCase							:    str=1      ,   __lowerCamelCase							:    Dict=False      ,   __lowerCamelCase							:    int=0      ,   __lowerCamelCase							:    Optional[Any]=1      ,   __lowerCamelCase							:    str=2      ,   __lowerCamelCase							:    Any=2      ,   **__lowerCamelCase							:    int      ,   ):


             '''simple docstring'''



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

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







class     _lowercase				(							lowercase__):


       """simple docstring"""




       @property
       def 		lowerCAmelCase  (     self							:    List[str] ):


             '''simple docstring'''



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

                   if self.use_past:
                         lowerCamelCase__	:       Union[str, Any]					=						{0: "batch"}
                         lowerCamelCase__	:       int					=						{0: "batch", 1: "past_decoder_sequence + sequence"}
                   else:
                         lowerCamelCase__	:       Tuple					=						{0: "batch", 1: "decoder_sequence"}
                         lowerCamelCase__	:       str					=						{0: "batch", 1: "decoder_sequence"}

                   if self.use_past:
                         self.fill_with_past_key_values_(__lowerCamelCase      ,   direction="inputs" )
             elif self.task == "causal-lm":
                   # TODO: figure this case out.
                   lowerCamelCase__	:       Tuple					=						OrderedDict(
                       [
                           ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                           ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
                       ] )
                   if self.use_past:
                         lowerCamelCase__					,     lowerCamelCase__	:       Tuple					=						self.num_layers
                         for i in range(__lowerCamelCase ):
                               lowerCamelCase__	:       Union[str, Any]					=						{0: "batch", 2: "past_sequence + sequence"}
                               lowerCamelCase__	:       Optional[int]					=						{0: "batch", 2: "past_sequence + sequence"}
             else:
                   lowerCamelCase__	:       Any					=						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							:    Optional[int] ):


             '''simple docstring'''



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





       def 		lowerCAmelCase  (     self							:    int      ,   __lowerCamelCase							:    PreTrainedTokenizer      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    bool = False      ,   __lowerCamelCase							:    Optional[TensorType] = None      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       Union[str, Any]					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )

             # Generate decoder inputs
             lowerCamelCase__	:       List[str]					=						seq_length if not self.use_past else 1
             lowerCamelCase__	:       List[Any]					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )
             lowerCamelCase__	:       Optional[Any]					=						{f"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
             lowerCamelCase__	:       Optional[Any]					=						dict(**__lowerCamelCase      ,   **__lowerCamelCase )

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

                   lowerCamelCase__	:       List[Any]					=						torch.cat(
                       [common_inputs["decoder_attention_mask"], torch.ones(__lowerCamelCase      ,   __lowerCamelCase )]      ,   dim=1 )

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

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





       def 		lowerCAmelCase  (     self							:    Tuple      ,   __lowerCamelCase							:    PreTrainedTokenizer      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    bool = False      ,   __lowerCamelCase							:    Optional[TensorType] = None      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )

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

                   lowerCamelCase__	:       Union[str, Any]					=						common_inputs["attention_mask"].dtype
                   lowerCamelCase__	:       List[str]					=						torch.cat(
                       [common_inputs["attention_mask"], torch.ones(__lowerCamelCase      ,   __lowerCamelCase      ,   dtype=__lowerCamelCase )]      ,   dim=1 )
                   lowerCamelCase__	:       Tuple					=						[
                       (torch.zeros(__lowerCamelCase ), torch.zeros(__lowerCamelCase )) for _ in range(__lowerCamelCase )
                   ]
             return common_inputs





       def 		lowerCAmelCase  (     self							:    Union[str, Any]      ,   __lowerCamelCase							:    PreTrainedTokenizer      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    int = -1      ,   __lowerCamelCase							:    bool = False      ,   __lowerCamelCase							:    Optional[TensorType] = None      ,   ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						compute_effective_axis_dimension(
                 __lowerCamelCase      ,   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
             lowerCamelCase__	:       List[str]					=						tokenizer.num_special_tokens_to_add(__lowerCamelCase )
             lowerCamelCase__	:       Dict					=						compute_effective_axis_dimension(
                 __lowerCamelCase      ,   fixed_dimension=OnnxConfig.default_fixed_sequence      ,   num_token_to_add=__lowerCamelCase )

             # Generate dummy inputs according to compute batch and sequence
             lowerCamelCase__	:       Optional[int]					=						[" ".join([tokenizer.unk_token] ) * seq_length] * batch_size
             lowerCamelCase__	:       Optional[Any]					=						dict(tokenizer(__lowerCamelCase      ,   return_tensors=__lowerCamelCase ) )
             return common_inputs





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


             '''simple docstring'''



             if self.task in ["default", "seq2seq-lm"]:
                   lowerCamelCase__	:       Optional[int]					=						self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                       __lowerCamelCase      ,   batch_size=__lowerCamelCase      ,   seq_length=__lowerCamelCase      ,   is_pair=__lowerCamelCase      ,   framework=__lowerCamelCase )

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

             return common_inputs





       def 		lowerCAmelCase  (     self							:    Any      ,   __lowerCamelCase							:    Union[str, Any]      ,   __lowerCamelCase							:    int      ,   __lowerCamelCase							:    Optional[Any]      ,   __lowerCamelCase							:    str ):


             '''simple docstring'''



             if self.task in ["default", "seq2seq-lm"]:
                   lowerCamelCase__	:       Dict					=						super()._flatten_past_key_values_(__lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )
             else:
                   lowerCamelCase__	:       int					=						super(__lowerCamelCase      ,   self )._flatten_past_key_values_(
                       __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase      ,   __lowerCamelCase )


