





"""simple docstring"""
from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import RegNetConfig
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 TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST, TFRegNetForImageClassification, TFRegNetModel


if is_vision_available():
  from PIL import Image

  from transformers import AutoImageProcessor






class  _SCREAMING_SNAKE_CASE:




       def __init__(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=10		,SCREAMING_SNAKE_CASE__=[10, 20, 30, 40]		,SCREAMING_SNAKE_CASE__=[1, 1, 2, 1]		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__="relu"		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=None		,)      ->				List[str]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[Any]		    =  parent
             __SCREAMING_SNAKE_CASE       :List[str]		    =  batch_size
             __SCREAMING_SNAKE_CASE       :List[str]		    =  image_size
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  num_channels
             __SCREAMING_SNAKE_CASE       :int		    =  embeddings_size
             __SCREAMING_SNAKE_CASE       :Any		    =  hidden_sizes
             __SCREAMING_SNAKE_CASE       :str		    =  depths
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  is_training
             __SCREAMING_SNAKE_CASE       :Any		    =  use_labels
             __SCREAMING_SNAKE_CASE       :Tuple		    =  hidden_act
             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  num_labels
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  scope
             __SCREAMING_SNAKE_CASE       :Dict		    =  len(__snake_case							)




       def    _UpperCamelCase					(						self							)      ->				Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  None
             if self.use_labels:
                   __SCREAMING_SNAKE_CASE       :Tuple		    =  ids_tensor([self.batch_size]		,self.num_labels							)

             __SCREAMING_SNAKE_CASE       :Dict		    =  self.get_config()
             return config, pixel_values, labels




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





             """simple docstring"""






             return RegNetConfig(
                 num_channels=self.num_channels		,embeddings_size=self.embeddings_size		,hidden_sizes=self.hidden_sizes		,depths=self.depths		,hidden_act=self.hidden_act		,num_labels=self.num_labels		,)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  TFRegNetModel(config=__snake_case							)
             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  model(__snake_case		,training=__snake_case							)
             # expected last hidden states: B, C, H // 32, W // 32
             self.parent.assertEqual(
                 result.last_hidden_state.shape		,(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)		,)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  self.num_labels
             __SCREAMING_SNAKE_CASE       :List[Any]		    =  TFRegNetForImageClassification(__snake_case							)
             __SCREAMING_SNAKE_CASE       :int		    =  model(__snake_case		,labels=__snake_case		,training=__snake_case							)
             self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_labels)							)




       def    _UpperCamelCase					(						self							)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  self.prepare_config_and_inputs()
             __SCREAMING_SNAKE_CASE       :List[str]		    =  config_and_inputs
             __SCREAMING_SNAKE_CASE       :Tuple		    =  {'pixel_values': pixel_values}
             return config, inputs_dict






@require_tf
class  _SCREAMING_SNAKE_CASE(       lowerCamelCase__   ,     lowerCamelCase__   ,     unittest.TestCase  ):
       SCREAMING_SNAKE_CASE_       :				Dict     						=  (TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else ()
       SCREAMING_SNAKE_CASE_       :				Union[str, Any]     						=  (
           {'''feature-extraction''': TFRegNetModel, '''image-classification''': TFRegNetForImageClassification}
           if is_tf_available()
           else {}
       )

       SCREAMING_SNAKE_CASE_       :				List[str]     						=  False
       SCREAMING_SNAKE_CASE_       :				str     						=  False
       SCREAMING_SNAKE_CASE_       :				Optional[int]     						=  False
       SCREAMING_SNAKE_CASE_       :				Optional[int]     						=  False
       SCREAMING_SNAKE_CASE_       :				Dict     						=  False




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  TFRegNetModelTester(self							)
             __SCREAMING_SNAKE_CASE       :List[Any]		    =  ConfigTester(self		,config_class=__snake_case		,has_text_modality=__snake_case							)




       def    _UpperCamelCase					(						self							)      ->				Optional[Any]:





             """simple docstring"""






             return




       @unittest.skip(reason='''RegNet does not use inputs_embeds'''							)
       def    _UpperCamelCase					(						self							)      ->				Dict:





             """simple docstring"""






             pass




       @unittest.skipIf(
           not is_tf_available() or len(tf.config.list_physical_devices('''GPU'''							)							) == 0		,reason='''TF does not support backprop for grouped convolutions on CPU.'''		,)
       @slow
       def    _UpperCamelCase					(						self							)      ->				Any:





             """simple docstring"""






             super().test_keras_fit()




       @unittest.skip(reason='''RegNet does not support input and output embeddings'''							)
       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             pass




       def    _UpperCamelCase					(						self							)      ->				Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE       :Tuple		    =  model_class(__snake_case							)
                   __SCREAMING_SNAKE_CASE       :Dict		    =  inspect.signature(model.call							)
                   # signature.parameters is an OrderedDict => so arg_names order is deterministic
                   __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  [*signature.parameters.keys()]

                   __SCREAMING_SNAKE_CASE       :List[Any]		    =  ['pixel_values']
                   self.assertListEqual(arg_names[:1]		,__snake_case							)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__snake_case							)




       def    _UpperCamelCase					(						self							)      ->				Dict:





             """simple docstring"""






             def check_hidden_states_output(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							):
                   __SCREAMING_SNAKE_CASE       :Any		    =  model_class(__snake_case							)
                   __SCREAMING_SNAKE_CASE       :Any		    =  model(**self._prepare_for_class(__snake_case		,__snake_case							)		,training=__snake_case							)

                   __SCREAMING_SNAKE_CASE       :Dict		    =  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

                   __SCREAMING_SNAKE_CASE       :Any		    =  self.model_tester.num_stages
                   self.assertEqual(len(__snake_case							)		,expected_num_stages + 1							)

                   # RegNet's feature maps are of shape (batch_size, num_channels, height, width)
                   self.assertListEqual(
                       list(hidden_states[0].shape[-2:]							)		,[self.model_tester.image_size // 2, self.model_tester.image_size // 2]		,)

             __SCREAMING_SNAKE_CASE       :List[Any]		    =  self.model_tester.prepare_config_and_inputs_for_common()
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  ['basic', 'bottleneck']
             for model_class in self.all_model_classes:
                   for layer_type in layers_type:
                         __SCREAMING_SNAKE_CASE       :Dict		    =  layer_type
                         __SCREAMING_SNAKE_CASE       :Any		    =  True
                         check_hidden_states_output(__snake_case		,__snake_case		,__snake_case							)

                         # check that output_hidden_states also work using config
                         del inputs_dict["output_hidden_states"]
                         __SCREAMING_SNAKE_CASE       :Any		    =  True

                         check_hidden_states_output(__snake_case		,__snake_case		,__snake_case							)




       def    _UpperCamelCase					(						self							)      ->				Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Any		    =  self.model_tester.prepare_config_and_inputs_for_common()

             def check_equivalence(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__={}							):
                   __SCREAMING_SNAKE_CASE       :Optional[int]		    =  model(__snake_case		,return_dict=__snake_case		,**__snake_case							)
                   __SCREAMING_SNAKE_CASE       :List[Any]		    =  model(__snake_case		,return_dict=__snake_case		,**__snake_case							).to_tuple()

                   def recursive_check(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							):
                         if isinstance(__snake_case		,(List, Tuple)							):
                               for tuple_iterable_value, dict_iterable_value in zip(__snake_case		,__snake_case							):
                                     recursive_check(__snake_case		,__snake_case							)
                         elif tuple_object is None:
                               return
                         else:
                               self.assertTrue(
                                   all(tf.equal(__snake_case		,__snake_case							)							)		,msg=(
                                       '''Tuple and dict output are not equal. Difference:'''
                                       f''' {tf.math.reduce_max(tf.abs(tuple_object - dict_object							)							)}'''
                                   )		,)

                         recursive_check(__snake_case		,__snake_case							)

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE       :str		    =  model_class(__snake_case							)

                   __SCREAMING_SNAKE_CASE       :Any		    =  self._prepare_for_class(__snake_case		,__snake_case							)
                   __SCREAMING_SNAKE_CASE       :int		    =  self._prepare_for_class(__snake_case		,__snake_case							)
                   check_equivalence(__snake_case		,__snake_case		,__snake_case							)

                   __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  self._prepare_for_class(__snake_case		,__snake_case		,return_labels=__snake_case							)
                   __SCREAMING_SNAKE_CASE       :Optional[int]		    =  self._prepare_for_class(__snake_case		,__snake_case		,return_labels=__snake_case							)
                   check_equivalence(__snake_case		,__snake_case		,__snake_case							)

                   __SCREAMING_SNAKE_CASE       :Dict		    =  self._prepare_for_class(__snake_case		,__snake_case							)
                   __SCREAMING_SNAKE_CASE       :int		    =  self._prepare_for_class(__snake_case		,__snake_case							)
                   check_equivalence(__snake_case		,__snake_case		,__snake_case		,{'''output_hidden_states''': True}							)

                   __SCREAMING_SNAKE_CASE       :List[Any]		    =  self._prepare_for_class(__snake_case		,__snake_case		,return_labels=__snake_case							)
                   __SCREAMING_SNAKE_CASE       :List[Any]		    =  self._prepare_for_class(__snake_case		,__snake_case		,return_labels=__snake_case							)
                   check_equivalence(__snake_case		,__snake_case		,__snake_case		,{'''output_hidden_states''': True}							)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*__snake_case							)




       @slow
       def    _UpperCamelCase					(						self							)      ->				Dict:





             """simple docstring"""






             for model_name in TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE       :Any		    =  TFRegNetModel.from_pretrained(__snake_case							)
                   self.assertIsNotNone(__snake_case							)




def 					__lowerCamelCase       (							)      ->				Optional[int]:
      __SCREAMING_SNAKE_CASE       :List[Any]		    =  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
      return image







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




       @cached_property
       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             return (
                 AutoImageProcessor.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]							)
                 if is_vision_available()
                 else None
             )




       @slow
       def    _UpperCamelCase					(						self							)      ->				Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  TFRegNetForImageClassification.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]							)

             __SCREAMING_SNAKE_CASE       :Dict		    =  self.default_image_processor
             __SCREAMING_SNAKE_CASE       :Tuple		    =  prepare_img()
             __SCREAMING_SNAKE_CASE       :Any		    =  image_processor(images=__snake_case		,return_tensors='''tf'''							)

             # forward pass
             __SCREAMING_SNAKE_CASE       :Tuple		    =  model(**__snake_case		,training=__snake_case							)

             # verify the logits
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  tf.TensorShape((1, 10_00)							)
             self.assertEqual(outputs.logits.shape		,__snake_case							)

             __SCREAMING_SNAKE_CASE       :List[str]		    =  tf.constant([-0.4_1_8_0, -1.5_0_5_1, -3.4_8_3_6]							)

             tf.debugging.assert_near(outputs.logits[0, :3]		,__snake_case		,atol=1E-4							)






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

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


lowerCamelCase_       =		logging.get_logger(__name__)

lowerCamelCase_       =		{
    "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/config.json",
    # See all BART models at https://huggingface.co/models?filter=bart
}






class  _SCREAMING_SNAKE_CASE(       A  ):
       SCREAMING_SNAKE_CASE_       :				str     						=  '''bart'''
       SCREAMING_SNAKE_CASE_       :				str     						=  ['''past_key_values''']
       SCREAMING_SNAKE_CASE_       :				str     						=  {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}




       def __init__(						self		,SCREAMING_SNAKE_CASE__=5_02_65		,SCREAMING_SNAKE_CASE__=10_24		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=40_96		,SCREAMING_SNAKE_CASE__=16		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=40_96		,SCREAMING_SNAKE_CASE__=16		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__="gelu"		,SCREAMING_SNAKE_CASE__=10_24		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=1		,SCREAMING_SNAKE_CASE__=0		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=2		,**SCREAMING_SNAKE_CASE__		,)      ->				int:





             """simple docstring"""






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

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

             # ensure backward compatibility for BART CNN models
             if self.forced_bos_token_id is None and kwargs.get('''force_bos_token_to_be_generated'''		,SCREAMING_SNAKE_CASE__							):
                   __SCREAMING_SNAKE_CASE       :str		    =  self.bos_token_id
                   warnings.warn(
                       f'''Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. '''
                       '''The config can simply be saved and uploaded again to be fixed.'''							)






class  _SCREAMING_SNAKE_CASE(       A  ):




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





             """simple docstring"""






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

                   if self.use_past:
                         __SCREAMING_SNAKE_CASE       :int		    =  {0: '''batch'''}
                         __SCREAMING_SNAKE_CASE       :int		    =  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
                   else:
                         __SCREAMING_SNAKE_CASE       :Tuple		    =  {0: '''batch''', 1: '''decoder_sequence'''}
                         __SCREAMING_SNAKE_CASE       :Any		    =  {0: '''batch''', 1: '''decoder_sequence'''}

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





             """simple docstring"""






             if self.task in ["default", "seq2seq-lm"]:
                   __SCREAMING_SNAKE_CASE       :str		    =  super().outputs
             else:
                   __SCREAMING_SNAKE_CASE       :List[str]		    =  super(SCREAMING_SNAKE_CASE__		,self							).outputs
                   if self.use_past:
                         __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Dict		    =  self.num_layers
                         for i in range(SCREAMING_SNAKE_CASE__							):
                               __SCREAMING_SNAKE_CASE       :str		    =  {0: '''batch''', 2: '''past_sequence + sequence'''}
                               __SCREAMING_SNAKE_CASE       :Any		    =  {0: '''batch''', 2: '''past_sequence + sequence'''}
             return common_outputs




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

             # Generate decoder inputs
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  seq_length if not self.use_past else 1
             __SCREAMING_SNAKE_CASE       :Dict		    =  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE       :List[str]		    =  {f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
             __SCREAMING_SNAKE_CASE       :Any		    =  dict(**SCREAMING_SNAKE_CASE__		,**SCREAMING_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
                   __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Dict		    =  common_inputs['''input_ids'''].shape
                   __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  common_inputs['''decoder_input_ids'''].shape[1]
                   __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  self.num_attention_heads
                   __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  (
                       batch,
                       num_encoder_attention_heads,
                       encoder_seq_length,
                       self._config.hidden_size // num_encoder_attention_heads,
                   )
                   __SCREAMING_SNAKE_CASE       :Optional[int]		    =  decoder_seq_length + 3
                   __SCREAMING_SNAKE_CASE       :Tuple		    =  (
                       batch,
                       num_decoder_attention_heads,
                       decoder_past_length,
                       self._config.hidden_size // num_decoder_attention_heads,
                   )

                   __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  torch.cat(
                       [common_inputs['''decoder_attention_mask'''], torch.ones(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)]		,dim=1							)

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

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




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_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
                   __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :str		    =  common_inputs['''input_ids'''].shape
                   # Not using the same length for past_key_values
                   __SCREAMING_SNAKE_CASE       :List[str]		    =  seqlen + 2
                   __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  self.num_layers
                   __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :int		    =  self.num_attention_heads
                   __SCREAMING_SNAKE_CASE       :Tuple		    =  (
                       batch,
                       num_encoder_attention_heads,
                       past_key_values_length,
                       self._config.hidden_size // num_encoder_attention_heads,
                   )

                   __SCREAMING_SNAKE_CASE       :Tuple		    =  common_inputs['''attention_mask'''].dtype
                   __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  torch.cat(
                       [common_inputs['''attention_mask'''], torch.ones(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,dtype=SCREAMING_SNAKE_CASE__							)]		,dim=1							)
                   __SCREAMING_SNAKE_CASE       :str		    =  [
                       (torch.zeros(SCREAMING_SNAKE_CASE__							), torch.zeros(SCREAMING_SNAKE_CASE__							)) for _ in range(SCREAMING_SNAKE_CASE__							)
                   ]
             return common_inputs




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[Any]		    =  compute_effective_axis_dimension(
                 SCREAMING_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
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  tokenizer.num_special_tokens_to_add(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE       :List[Any]		    =  compute_effective_axis_dimension(
                 SCREAMING_SNAKE_CASE__		,fixed_dimension=OnnxConfig.default_fixed_sequence		,num_token_to_add=SCREAMING_SNAKE_CASE__							)

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




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





             """simple docstring"""






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

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

             return common_inputs




       def    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)      ->				str:





             """simple docstring"""






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