





"""simple docstring"""
import inspect
import unittest

from transformers import ConvNextConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import ConvNextBackbone, ConvNextForImageClassification, ConvNextModel
  from transformers.models.convnext.modeling_convnext import CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST


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__=13		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=4		,SCREAMING_SNAKE_CASE__=[10, 20, 30, 40]		,SCREAMING_SNAKE_CASE__=[2, 2, 3, 2]		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=37		,SCREAMING_SNAKE_CASE__="gelu"		,SCREAMING_SNAKE_CASE__=10		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=["stage2", "stage3", "stage4"]		,SCREAMING_SNAKE_CASE__=[2, 3, 4]		,SCREAMING_SNAKE_CASE__=None		,)      ->				List[str]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Tuple		    =  parent
             __SCREAMING_SNAKE_CASE       :List[str]		    =  batch_size
             __SCREAMING_SNAKE_CASE       :Any		    =  image_size
             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  num_channels
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  num_stages
             __SCREAMING_SNAKE_CASE       :str		    =  hidden_sizes
             __SCREAMING_SNAKE_CASE       :Dict		    =  depths
             __SCREAMING_SNAKE_CASE       :Tuple		    =  is_training
             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  use_labels
             __SCREAMING_SNAKE_CASE       :int		    =  intermediate_size
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  hidden_act
             __SCREAMING_SNAKE_CASE       :Tuple		    =  num_labels
             __SCREAMING_SNAKE_CASE       :Any		    =  initializer_range
             __SCREAMING_SNAKE_CASE       :Any		    =  out_features
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  out_indices
             __SCREAMING_SNAKE_CASE       :List[str]		    =  scope




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

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

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




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





             """simple docstring"""






             return ConvNextConfig(
                 num_channels=self.num_channels		,hidden_sizes=self.hidden_sizes		,depths=self.depths		,num_stages=self.num_stages		,hidden_act=self.hidden_act		,is_decoder=SCREAMING_SNAKE_CASE__		,initializer_range=self.initializer_range		,out_features=self.out_features		,out_indices=self.out_indices		,num_labels=self.num_labels		,)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  ConvNextModel(config=SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             model.eval()
             __SCREAMING_SNAKE_CASE       :Dict		    =  model(SCREAMING_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__							)      ->				Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  ConvNextForImageClassification(SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             model.eval()
             __SCREAMING_SNAKE_CASE       :Dict		    =  model(SCREAMING_SNAKE_CASE__		,labels=SCREAMING_SNAKE_CASE__							)
             self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_labels)							)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  ConvNextBackbone(config=SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             model.eval()
             __SCREAMING_SNAKE_CASE       :Tuple		    =  model(SCREAMING_SNAKE_CASE__							)

             # verify hidden states
             self.parent.assertEqual(len(result.feature_maps							)		,len(config.out_features							)							)
             self.parent.assertListEqual(list(result.feature_maps[0].shape							)		,[self.batch_size, self.hidden_sizes[1], 4, 4]							)

             # verify channels
             self.parent.assertEqual(len(model.channels							)		,len(config.out_features							)							)
             self.parent.assertListEqual(model.channels		,config.hidden_sizes[1:]							)

             # verify backbone works with out_features=None
             __SCREAMING_SNAKE_CASE       :str		    =  None
             __SCREAMING_SNAKE_CASE       :Any		    =  ConvNextBackbone(config=SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             model.eval()
             __SCREAMING_SNAKE_CASE       :Tuple		    =  model(SCREAMING_SNAKE_CASE__							)

             # verify feature maps
             self.parent.assertEqual(len(result.feature_maps							)		,1							)
             self.parent.assertListEqual(list(result.feature_maps[0].shape							)		,[self.batch_size, self.hidden_sizes[-1], 1, 1]							)

             # verify channels
             self.parent.assertEqual(len(model.channels							)		,1							)
             self.parent.assertListEqual(model.channels		,[config.hidden_sizes[-1]]							)




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





             """simple docstring"""






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






@require_torch
class  _SCREAMING_SNAKE_CASE(       A   ,     A   ,     unittest.TestCase  ):
       SCREAMING_SNAKE_CASE_       :				int     						=  (
           (
               ConvNextModel,
               ConvNextForImageClassification,
               ConvNextBackbone,
           )
           if is_torch_available()
           else ()
       )
       SCREAMING_SNAKE_CASE_       :				Optional[int]     						=  (
           {'''feature-extraction''': ConvNextModel, '''image-classification''': ConvNextForImageClassification}
           if is_torch_available()
           else {}
       )

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




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Tuple		    =  ConvNextModelTester(self							)
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  ConfigTester(self		,config_class=SCREAMING_SNAKE_CASE__		,has_text_modality=SCREAMING_SNAKE_CASE__		,hidden_size=37							)




       def    _UpperCamelCase					(						self							)      ->				Any:





             """simple docstring"""






             self.create_and_test_config_common_properties()
             self.config_tester.create_and_test_config_to_json_string()
             self.config_tester.create_and_test_config_to_json_file()
             self.config_tester.create_and_test_config_from_and_save_pretrained()
             self.config_tester.create_and_test_config_with_num_labels()
             self.config_tester.check_config_can_be_init_without_params()
             self.config_tester.check_config_arguments_init()




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





             """simple docstring"""






             return




       @unittest.skip(reason='''ConvNext does not use inputs_embeds'''							)
       def    _UpperCamelCase					(						self							)      ->				Optional[Any]:





             """simple docstring"""






             pass




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





             """simple docstring"""






             pass




       @unittest.skip(reason='''ConvNext does not use feedforward chunking'''							)
       def    _UpperCamelCase					(						self							)      ->				List[str]:





             """simple docstring"""






             pass




       def    _UpperCamelCase					(						self							)      ->				Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE       :Dict		    =  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE       :str		    =  model_class(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE       :List[Any]		    =  inspect.signature(model.forward							)
                   # 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]		,SCREAMING_SNAKE_CASE__							)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :str		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__							)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_backbone(*SCREAMING_SNAKE_CASE__							)




       def    _UpperCamelCase					(						self							)      ->				Tuple:





             """simple docstring"""






             def check_hidden_states_output(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							):
                   __SCREAMING_SNAKE_CASE       :Dict		    =  model_class(SCREAMING_SNAKE_CASE__							)
                   model.to(SCREAMING_SNAKE_CASE__							)
                   model.eval()

                   with torch.no_grad():
                         __SCREAMING_SNAKE_CASE       :Optional[int]		    =  model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)							)

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

                   __SCREAMING_SNAKE_CASE       :List[str]		    =  self.model_tester.num_stages
                   self.assertEqual(len(SCREAMING_SNAKE_CASE__							)		,expected_num_stages + 1							)

                   # ConvNext'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 // 4, self.model_tester.image_size // 4]		,)

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

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE       :List[Any]		    =  True
                   check_hidden_states_output(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_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(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE__							)




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





             """simple docstring"""






             for model_name in CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  ConvNextModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)




def 					__lowerCamelCase       (							)      ->				str:
      __SCREAMING_SNAKE_CASE       :Tuple		    =  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
      return image






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




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





             """simple docstring"""






             return AutoImageProcessor.from_pretrained('''facebook/convnext-tiny-224'''							) if is_vision_available() else None




       @slow
       def    _UpperCamelCase					(						self							)      ->				Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  ConvNextForImageClassification.from_pretrained('''facebook/convnext-tiny-224'''							).to(SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE       :Any		    =  self.default_image_processor
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  prepare_img()
             __SCREAMING_SNAKE_CASE       :Tuple		    =  image_processor(images=SCREAMING_SNAKE_CASE__		,return_tensors='''pt'''							).to(SCREAMING_SNAKE_CASE__							)

             # forward pass
             with torch.no_grad():
                   __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  model(**SCREAMING_SNAKE_CASE__							)

             # verify the logits
             __SCREAMING_SNAKE_CASE       :str		    =  torch.Size((1, 10_00)							)
             self.assertEqual(outputs.logits.shape		,SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE       :List[Any]		    =  torch.tensor([-0.0_2_6_0, -0.4_7_3_9, 0.1_9_1_1]							).to(SCREAMING_SNAKE_CASE__							)

             self.assertTrue(torch.allclose(outputs.logits[0, :3]		,SCREAMING_SNAKE_CASE__		,atol=1E-4							)							)






@require_torch
class  _SCREAMING_SNAKE_CASE(       unittest.TestCase   ,     A  ):
       SCREAMING_SNAKE_CASE_       :				List[str]     						=  (ConvNextBackbone,) if is_torch_available() else ()
       SCREAMING_SNAKE_CASE_       :				List[str]     						=  ConvNextConfig

       SCREAMING_SNAKE_CASE_       :				Tuple     						=  False




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  ConvNextModelTester(self							)






"""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__							)