



from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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


if is_tf_available():
       import tensorflow as tf

       from transformers import (
           TFFunnelBaseModel,
           TFFunnelForMaskedLM,
           TFFunnelForMultipleChoice,
           TFFunnelForPreTraining,
           TFFunnelForQuestionAnswering,
           TFFunnelForSequenceClassification,
           TFFunnelForTokenClassification,
           TFFunnelModel,
       )



class    UpperCAmelCase__:

   '''simple docstring'''




   def __init__(    self	:      str      ,					lowerCAmelCase	:      List[Any]      ,					lowerCAmelCase	:      Tuple=13      ,					lowerCAmelCase	:      Any=7      ,					lowerCAmelCase	:      str=True      ,					lowerCAmelCase	:      List[str]=True      ,					lowerCAmelCase	:      Tuple=True      ,					lowerCAmelCase	:      List[Any]=True      ,					lowerCAmelCase	:      str=99      ,					lowerCAmelCase	:      Optional[int]=[1, 1, 2]      ,					lowerCAmelCase	:      int=1      ,					lowerCAmelCase	:      Tuple=32      ,					lowerCAmelCase	:      int=4      ,					lowerCAmelCase	:      Optional[int]=8      ,					lowerCAmelCase	:      Optional[int]=37      ,					lowerCAmelCase	:      Tuple="gelu_new"      ,					lowerCAmelCase	:      List[Any]=0.1      ,					lowerCAmelCase	:      Optional[Any]=0.1      ,					lowerCAmelCase	:      Tuple=0.0      ,					lowerCAmelCase	:      int=5_12      ,					lowerCAmelCase	:      Optional[int]=3      ,					lowerCAmelCase	:      str=0.02      ,					lowerCAmelCase	:      int=3      ,					lowerCAmelCase	:      Any=4      ,					lowerCAmelCase	:      Any=None      ,					lowerCAmelCase	:      Optional[int]=False      ,					)						->					Optional[int]:




         """simple docstring"""

         lowercase__  =	parent
         lowercase__  =	batch_size
         lowercase__  =	seq_length
         lowercase__  =	is_training
         lowercase__  =	use_input_mask
         lowercase__  =	use_token_type_ids
         lowercase__  =	use_labels
         lowercase__  =	vocab_size
         lowercase__  =	block_sizes
         lowercase__  =	num_decoder_layers
         lowercase__  =	d_model
         lowercase__  =	n_head
         lowercase__  =	d_head
         lowercase__  =	d_inner
         lowercase__  =	hidden_act
         lowercase__  =	hidden_dropout
         lowercase__  =	attention_dropout
         lowercase__  =	activation_dropout
         lowercase__  =	max_position_embeddings
         lowercase__  =	type_vocab_size
         lowercase__  =	2
         lowercase__  =	num_labels
         lowercase__  =	num_choices
         lowercase__  =	scope
         lowercase__  =	initializer_std

         # Used in the tests to check the size of the first attention layer
         lowercase__  =	n_head
         # Used in the tests to check the size of the first hidden state
         lowercase__  =	self.d_model
         # Used in the tests to check the number of output hidden states/attentions
         lowercase__  =	sum(self.block_sizes) + (0 if base else self.num_decoder_layers)
         # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
         # the last hidden state of the first block (which is the first hidden state of the decoder).
         if not base:
               lowercase__  =	self.num_hidden_layers + 2


   def       UpperCAmelCase		(    self	:      Tuple)						->					int:




         """simple docstring"""

         lowercase__  =	ids_tensor([self.batch_size, self.seq_length]      ,					self.vocab_size)

         lowercase__  =	None
         if self.use_input_mask:
               lowercase__  =	random_attention_mask([self.batch_size, self.seq_length])

         lowercase__  =	None
         if self.use_token_type_ids:
               lowercase__  =	ids_tensor([self.batch_size, self.seq_length]      ,					self.type_vocab_size)

         lowercase__  =	None
         lowercase__  =	None
         lowercase__  =	None
         if self.use_labels:
               lowercase__  =	ids_tensor([self.batch_size]      ,					self.type_sequence_label_size)
               lowercase__  =	ids_tensor([self.batch_size, self.seq_length]      ,					self.num_labels)
               lowercase__  =	ids_tensor([self.batch_size]      ,					self.num_choices)

         lowercase__  =	FunnelConfig(
             vocab_size=self.vocab_size      ,					block_sizes=self.block_sizes      ,					num_decoder_layers=self.num_decoder_layers      ,					d_model=self.d_model      ,					n_head=self.n_head      ,					d_head=self.d_head      ,					d_inner=self.d_inner      ,					hidden_act=self.hidden_act      ,					hidden_dropout=self.hidden_dropout      ,					attention_dropout=self.attention_dropout      ,					activation_dropout=self.activation_dropout      ,					max_position_embeddings=self.max_position_embeddings      ,					type_vocab_size=self.type_vocab_size      ,					initializer_std=self.initializer_std      ,					)

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


   def       UpperCAmelCase		(    self	:      str      ,					lowerCAmelCase	:      Optional[Any]      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      str      ,					lowerCAmelCase	:      List[Any]      ,					lowerCAmelCase	:      List[Any]      ,					lowerCAmelCase	:      Tuple      ,					lowerCAmelCase	:      str      ,					)						->					Any:




         """simple docstring"""

         lowercase__  =	TFFunnelModel(config=lowerCAmelCase)
         lowercase__  =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         lowercase__  =	model(lowerCAmelCase)

         lowercase__  =	[input_ids, input_mask]
         lowercase__  =	model(lowerCAmelCase)

         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.last_hidden_state.shape      ,					(self.batch_size, self.seq_length, self.d_model))

         lowercase__  =	False
         lowercase__  =	TFFunnelModel(config=lowerCAmelCase)
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.last_hidden_state.shape      ,					(self.batch_size, self.seq_length, self.d_model))

         lowercase__  =	False
         lowercase__  =	TFFunnelModel(config=lowerCAmelCase)
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.last_hidden_state.shape      ,					(self.batch_size, self.seq_length, self.d_model))


   def       UpperCAmelCase		(    self	:      int      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      List[Any]      ,					lowerCAmelCase	:      Tuple      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Tuple      ,					)						->					Union[str, Any]:




         """simple docstring"""

         lowercase__  =	TFFunnelBaseModel(config=lowerCAmelCase)
         lowercase__  =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         lowercase__  =	model(lowerCAmelCase)

         lowercase__  =	[input_ids, input_mask]
         lowercase__  =	model(lowerCAmelCase)

         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.last_hidden_state.shape      ,					(self.batch_size, 2, self.d_model))

         lowercase__  =	False
         lowercase__  =	TFFunnelBaseModel(config=lowerCAmelCase)
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.last_hidden_state.shape      ,					(self.batch_size, 3, self.d_model))

         lowercase__  =	False
         lowercase__  =	TFFunnelBaseModel(config=lowerCAmelCase)
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.last_hidden_state.shape      ,					(self.batch_size, 2, self.d_model))


   def       UpperCAmelCase		(    self	:      Any      ,					lowerCAmelCase	:      List[str]      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      str      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      List[Any]      ,					lowerCAmelCase	:      str      ,					lowerCAmelCase	:      Optional[Any]      ,					)						->					Union[str, Any]:




         """simple docstring"""

         lowercase__  =	TFFunnelForPreTraining(config=lowerCAmelCase)
         lowercase__  =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length))


   def       UpperCAmelCase		(    self	:      Tuple      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Dict      ,					lowerCAmelCase	:      Any      ,					lowerCAmelCase	:      List[str]      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      List[str]      ,					)						->					List[Any]:




         """simple docstring"""

         lowercase__  =	TFFunnelForMaskedLM(config=lowerCAmelCase)
         lowercase__  =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.vocab_size))


   def       UpperCAmelCase		(    self	:      List[Any]      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Dict      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Optional[Any]      ,					lowerCAmelCase	:      str      ,					lowerCAmelCase	:      Union[str, Any]      ,					lowerCAmelCase	:      Optional[int]      ,					)						->					str:




         """simple docstring"""

         lowercase__  =	self.num_labels
         lowercase__  =	TFFunnelForSequenceClassification(config=lowerCAmelCase)
         lowercase__  =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.num_labels))


   def       UpperCAmelCase		(    self	:      Optional[Any]      ,					lowerCAmelCase	:      Optional[Any]      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Any      ,					lowerCAmelCase	:      List[str]      ,					lowerCAmelCase	:      int      ,					lowerCAmelCase	:      Tuple      ,					lowerCAmelCase	:      Any      ,					)						->					Optional[Any]:




         """simple docstring"""

         lowercase__  =	self.num_choices
         lowercase__  =	TFFunnelForMultipleChoice(config=lowerCAmelCase)
         lowercase__  =	tf.tile(tf.expand_dims(lowerCAmelCase      ,					1)      ,					(1, self.num_choices, 1))
         lowercase__  =	tf.tile(tf.expand_dims(lowerCAmelCase      ,					1)      ,					(1, self.num_choices, 1))
         lowercase__  =	tf.tile(tf.expand_dims(lowerCAmelCase      ,					1)      ,					(1, self.num_choices, 1))
         lowercase__  =	{
             'input_ids': multiple_choice_inputs_ids,
             'attention_mask': multiple_choice_input_mask,
             'token_type_ids': multiple_choice_token_type_ids,
         }
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.num_choices))


   def       UpperCAmelCase		(    self	:      Optional[Any]      ,					lowerCAmelCase	:      Union[str, Any]      ,					lowerCAmelCase	:      Union[str, Any]      ,					lowerCAmelCase	:      Any      ,					lowerCAmelCase	:      Dict      ,					lowerCAmelCase	:      Optional[Any]      ,					lowerCAmelCase	:      Any      ,					lowerCAmelCase	:      str      ,					)						->					Tuple:




         """simple docstring"""

         lowercase__  =	self.num_labels
         lowercase__  =	TFFunnelForTokenClassification(config=lowerCAmelCase)
         lowercase__  =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.num_labels))


   def       UpperCAmelCase		(    self	:      List[Any]      ,					lowerCAmelCase	:      Dict      ,					lowerCAmelCase	:      Dict      ,					lowerCAmelCase	:      Union[str, Any]      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Dict      ,					lowerCAmelCase	:      Union[str, Any]      ,					lowerCAmelCase	:      Tuple      ,					)						->					Tuple:




         """simple docstring"""

         lowercase__  =	TFFunnelForQuestionAnswering(config=lowerCAmelCase)
         lowercase__  =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         lowercase__  =	model(lowerCAmelCase)
         self.parent.assertEqual(result.start_logits.shape      ,					(self.batch_size, self.seq_length))
         self.parent.assertEqual(result.end_logits.shape      ,					(self.batch_size, self.seq_length))



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




         """simple docstring"""

         lowercase__  =	self.prepare_config_and_inputs()
         (
             (
             lowercase__
         ),						(
             lowercase__
         ),						(
             lowercase__
         ),						(
             lowercase__
         ),						(
             lowercase__
         ),						(
             lowercase__
         ),						(
             lowercase__
         ),						
         )  =	config_and_inputs
         lowercase__  =	{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
         return config, inputs_dict



@require_tf
class    UpperCAmelCase__(				lowerCamelCase  ,				lowerCamelCase  ,				unittest.TestCase						):

   '''simple docstring'''




   A     :	Tuple												=     (
       (
           TFFunnelModel,
           TFFunnelForMaskedLM,
           TFFunnelForPreTraining,
           TFFunnelForQuestionAnswering,
           TFFunnelForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   A     :	str												=     (
       {
           "feature-extraction": (TFFunnelBaseModel, TFFunnelModel),
           "fill-mask": TFFunnelForMaskedLM,
           "question-answering": TFFunnelForQuestionAnswering,
           "text-classification": TFFunnelForSequenceClassification,
           "token-classification": TFFunnelForTokenClassification,
           "zero-shot": TFFunnelForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   A     :	Tuple												=     False
   A     :	Union[str, Any]												=     False


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




         """simple docstring"""

         lowercase__  =	TFFunnelModelTester(self)
         lowercase__  =	ConfigTester(self      ,					config_class=lowerCAmelCase)


   def       UpperCAmelCase		(    self	:      int)						->					Dict:




         """simple docstring"""

         self.config_tester.run_common_tests()


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




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*lowerCAmelCase)


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




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_pretraining(*lowerCAmelCase)


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




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase)


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




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase)



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




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase)



@require_tf
class    UpperCAmelCase__(				lowerCamelCase  ,				unittest.TestCase						):

   '''simple docstring'''




   A     :	Any												=     (
       (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
   )
   A     :	Tuple												=     False
   A     :	Tuple												=     False


   def       UpperCAmelCase		(    self	:      Any)						->					Any:




         """simple docstring"""

         lowercase__  =	TFFunnelModelTester(self      ,					base=lowerCAmelCase)
         lowercase__  =	ConfigTester(self      ,					config_class=lowerCAmelCase)


   def       UpperCAmelCase		(    self	:      int)						->					str:




         """simple docstring"""

         self.config_tester.run_common_tests()


   def       UpperCAmelCase		(    self	:      Dict)						->					Any:




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_base_model(*lowerCAmelCase)


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




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase)



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




         """simple docstring"""

         lowercase__  =	self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase)





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


a__   :					int 						=      logging.get_logger(__name__)

a__   :					int 						=      {
    "Helsinki-NLP/opus-mt-en-de": "https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json",
    # See all Marian models at https://huggingface.co/models?filter=marian
}



class    UpperCAmelCase__(				lowerCamelCase						):

   '''simple docstring'''




   A     :	Union[str, Any]												=     "marian"
   A     :	Dict												=     ["past_key_values"]
   A     :	List[Any]												=     {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}


   def __init__(    self	:      Any      ,					lowerCAmelCase	:      List[Any]=5_81_01      ,					lowerCAmelCase	:      Optional[int]=None      ,					lowerCAmelCase	:      List[str]=10_24      ,					lowerCAmelCase	:      int=12      ,					lowerCAmelCase	:      Union[str, Any]=40_96      ,					lowerCAmelCase	:      int=16      ,					lowerCAmelCase	:      Dict=12      ,					lowerCAmelCase	:      Optional[int]=40_96      ,					lowerCAmelCase	:      str=16      ,					lowerCAmelCase	:      List[Any]=0.0      ,					lowerCAmelCase	:      Optional[Any]=0.0      ,					lowerCAmelCase	:      List[str]=True      ,					lowerCAmelCase	:      Union[str, Any]=True      ,					lowerCAmelCase	:      List[Any]="gelu"      ,					lowerCAmelCase	:      int=10_24      ,					lowerCAmelCase	:      Optional[int]=0.1      ,					lowerCAmelCase	:      Optional[int]=0.0      ,					lowerCAmelCase	:      Tuple=0.0      ,					lowerCAmelCase	:      List[Any]=0.02      ,					lowerCAmelCase	:      Union[str, Any]=5_81_00      ,					lowerCAmelCase	:      str=False      ,					lowerCAmelCase	:      Optional[Any]=5_81_00      ,					lowerCAmelCase	:      Union[str, Any]=0      ,					lowerCAmelCase	:      Optional[Any]=0      ,					lowerCAmelCase	:      int=True      ,					**lowerCAmelCase	:      List[str]      ,					)						->					Dict:




         """simple docstring"""

         lowercase__  =	vocab_size
         lowercase__  =	decoder_vocab_size or vocab_size
         lowercase__  =	max_position_embeddings
         lowercase__  =	d_model
         lowercase__  =	encoder_ffn_dim
         lowercase__  =	encoder_layers
         lowercase__  =	encoder_attention_heads
         lowercase__  =	decoder_ffn_dim
         lowercase__  =	decoder_layers
         lowercase__  =	decoder_attention_heads
         lowercase__  =	dropout
         lowercase__  =	attention_dropout
         lowercase__  =	activation_dropout
         lowercase__  =	activation_function
         lowercase__  =	init_std
         lowercase__  =	encoder_layerdrop
         lowercase__  =	decoder_layerdrop
         lowercase__  =	use_cache
         lowercase__  =	encoder_layers
         lowercase__  =	scale_embedding  # scale factor will be sqrt(d_model) if True
         lowercase__  =	share_encoder_decoder_embeddings
         super().__init__(
             pad_token_id=lowerCAmelCase      ,					eos_token_id=lowerCAmelCase      ,					is_encoder_decoder=lowerCAmelCase      ,					decoder_start_token_id=lowerCAmelCase      ,					forced_eos_token_id=lowerCAmelCase      ,					**lowerCAmelCase      ,					)



class    UpperCAmelCase__(				lowerCamelCase						):

   '''simple docstring'''




   @property
   # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
   def       UpperCAmelCase		(    self	:      List[Any])						->					Mapping[str, Mapping[int, str]]:




         """simple docstring"""

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

               if self.use_past:
                     lowercase__  =	{0: 'batch'}
                     lowercase__  =	{0: 'batch', 1: 'past_decoder_sequence + sequence'}
               else:
                     lowercase__  =	{0: 'batch', 1: 'decoder_sequence'}
                     lowercase__  =	{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.
               lowercase__  =	OrderedDict(
                   [
                       ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                       ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
                   ])
               if self.use_past:
                     lowercase__,						lowercase__  =	self.num_layers
                     for i in range(lowerCAmelCase):
                           lowercase__  =	{0: 'batch', 2: 'past_sequence + sequence'}
                           lowercase__  =	{0: 'batch', 2: 'past_sequence + sequence'}
         else:
               lowercase__  =	OrderedDict(
                   [
                       ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                       ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
                       ('decoder_input_ids', {0: 'batch', 1: 'decoder_sequence'}),
                       ('decoder_attention_mask', {0: 'batch', 1: 'decoder_sequence'}),
                   ])

         return common_inputs


   @property
   # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
   def       UpperCAmelCase		(    self	:      Any)						->					Mapping[str, Mapping[int, str]]:




         """simple docstring"""

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


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




         """simple docstring"""

         lowercase__  =	self._generate_dummy_inputs_for_encoder_and_decoder(
             lowerCAmelCase      ,					lowerCAmelCase      ,					lowerCAmelCase      ,					lowerCAmelCase      ,					lowerCAmelCase)

         # Generate decoder inputs
         lowercase__  =	seq_length if not self.use_past else 1
         lowercase__  =	self._generate_dummy_inputs_for_encoder_and_decoder(
             lowerCAmelCase      ,					lowerCAmelCase      ,					lowerCAmelCase      ,					lowerCAmelCase      ,					lowerCAmelCase)
         lowercase__  =	{f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
         lowercase__  =	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
               lowercase__,						lowercase__  =	common_inputs['input_ids'].shape
               lowercase__  =	common_inputs['decoder_input_ids'].shape[1]
               lowercase__,						lowercase__  =	self.num_attention_heads
               lowercase__  =	(
                   batch,
                   num_encoder_attention_heads,
                   encoder_seq_length,
                   self._config.hidden_size // num_encoder_attention_heads,
               )
               lowercase__  =	decoder_seq_length + 3
               lowercase__  =	(
                   batch,
                   num_decoder_attention_heads,
                   decoder_past_length,
                   self._config.hidden_size // num_decoder_attention_heads,
               )

               lowercase__  =	torch.cat(
                   [common_inputs['decoder_attention_mask'], torch.ones(lowerCAmelCase      ,					lowerCAmelCase)]      ,					dim=1)

               lowercase__  =	[]
               # If the number of encoder and decoder layers are present in the model configuration, both are considered
               lowercase__,						lowercase__  =	self.num_layers
               lowercase__  =	min(lowerCAmelCase      ,					lowerCAmelCase)
               lowercase__  =	max(lowerCAmelCase      ,					lowerCAmelCase) - min_num_layers
               lowercase__  =	'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.
               lowercase__  =	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       UpperCAmelCase		(    self	:      str      ,					lowerCAmelCase	:      PreTrainedTokenizer      ,					lowerCAmelCase	:      int = -1      ,					lowerCAmelCase	:      int = -1      ,					lowerCAmelCase	:      bool = False      ,					lowerCAmelCase	:      Optional[TensorType] = None      ,					)						->					Mapping[str, Any]:




         """simple docstring"""

         lowercase__  =	self._generate_dummy_inputs_for_encoder_and_decoder(
             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
               lowercase__,						lowercase__  =	common_inputs['input_ids'].shape
               # Not using the same length for past_key_values
               lowercase__  =	seqlen + 2
               lowercase__,						lowercase__  =	self.num_layers
               lowercase__,						lowercase__  =	self.num_attention_heads
               lowercase__  =	(
                   batch,
                   num_encoder_attention_heads,
                   past_key_values_length,
                   self._config.hidden_size // num_encoder_attention_heads,
               )

               lowercase__  =	common_inputs['attention_mask'].dtype
               lowercase__  =	torch.cat(
                   [common_inputs['attention_mask'], torch.ones(lowerCAmelCase      ,					lowerCAmelCase      ,					dtype=lowerCAmelCase)]      ,					dim=1)
               lowercase__  =	[
                   (torch.zeros(lowerCAmelCase), torch.zeros(lowerCAmelCase)) for _ in range(lowerCAmelCase)
               ]
         return common_inputs


   def       UpperCAmelCase		(    self	:      Dict      ,					lowerCAmelCase	:      PreTrainedTokenizer      ,					lowerCAmelCase	:      int = -1      ,					lowerCAmelCase	:      int = -1      ,					lowerCAmelCase	:      bool = False      ,					lowerCAmelCase	:      Optional[TensorType] = None      ,					)						->					Mapping[str, Any]:




         """simple docstring"""

         lowercase__  =	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
         lowercase__  =	tokenizer.num_special_tokens_to_add(lowerCAmelCase)
         lowercase__  =	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
         lowercase__  =	[' '.join([tokenizer.unk_token]) * seq_length] * batch_size
         lowercase__  =	dict(tokenizer(lowerCAmelCase      ,					return_tensors=lowerCAmelCase))
         return common_inputs


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




         """simple docstring"""

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

         else:
               lowercase__  =	self._generate_dummy_inputs_for_causal_lm(
                   lowerCAmelCase      ,					batch_size=lowerCAmelCase      ,					seq_length=lowerCAmelCase      ,					is_pair=lowerCAmelCase      ,					framework=lowerCAmelCase)

         return common_inputs


   def       UpperCAmelCase		(    self	:      List[Any]      ,					lowerCAmelCase	:      Optional[int]      ,					lowerCAmelCase	:      Optional[Any]      ,					lowerCAmelCase	:      str      ,					lowerCAmelCase	:      str)						->					Optional[int]:




         """simple docstring"""

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



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




         """simple docstring"""

         return 1E-4
